Skip to content

Commit

Permalink
feat: Add Created with Visualize link to screenshot footnotes
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Dec 4, 2024
1 parent af03396 commit 6562a3e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
11 changes: 8 additions & 3 deletions app/components/chart-footnotes.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Trans } from "@lingui/macro";
import { t, Trans } from "@lingui/macro";
import { Box, Link, Theme, Typography } from "@mui/material";
import { makeStyles } from "@mui/styles";
import uniqBy from "lodash/uniqBy";
import { useMemo } from "react";
import { ReactNode, useMemo } from "react";

import { extractChartConfigUsedCubes } from "@/charts/shared/chart-helpers";
import { LegendItem } from "@/charts/shared/legend-color";
Expand Down Expand Up @@ -41,6 +41,8 @@ export const useFootnotesStyles = makeStyles<Theme, { useMarginTop: boolean }>(
})
);

export const CHART_FOOTNOTES_CLASS_NAME = "chart-footnotes";

export const ChartFootnotes = ({
dataSource,
chartConfig,
Expand Down Expand Up @@ -73,7 +75,10 @@ export const ChartFootnotes = ({
const formatLocale = useTimeFormatLocale();

return (
<Box sx={{ mt: 1, "& > :not(:last-child)": { mb: 3 } }}>
<Box
className={CHART_FOOTNOTES_CLASS_NAME}
sx={{ mt: 1, "& > :not(:last-child)": { mb: 3 } }}
>
{data?.dataCubesMetadata.map((metadata) => (
<div key={metadata.iri}>
<ChartFootnotesLegend
Expand Down
2 changes: 1 addition & 1 deletion app/components/chart-published.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Trans } from "@lingui/macro";
import { t, Trans } from "@lingui/macro";
import { Box, Theme } from "@mui/material";
import { makeStyles } from "@mui/styles";
import clsx from "clsx";
Expand Down
33 changes: 24 additions & 9 deletions app/components/chart-shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ import {
} from "@mui/material";
import { makeStyles } from "@mui/styles";
import { select } from "d3-selection";
import {
ComponentProps,
useCallback,
useEffect,
useMemo,
useState,
} from "react";
import { ComponentProps, useCallback, useEffect, useState } from "react";
import ReactDOM from "react-dom";

import {
ChartDataFiltersList,
ChartDataFiltersToggle,
useChartDataFiltersState,
} from "@/charts/shared/chart-data-filters";
import { ArrowMenuTopBottom } from "@/components/arrow-menu";
import {
CHART_FOOTNOTES_CLASS_NAME,
VisualizeLink,
} from "@/components/chart-footnotes";
import { chartPanelLayoutGridClasses } from "@/components/chart-panel-layout-grid";
import { useChartTablePreview } from "@/components/chart-table-preview";
import { MenuActionItem } from "@/components/menu-action-item";
Expand Down Expand Up @@ -157,10 +156,26 @@ export const ChartMoreButton = ({

const modifyNode = useCallback(
(node: HTMLElement) => {
const footnotes = node.querySelector(CHART_FOOTNOTES_CLASS_NAME);

if (footnotes) {
const container = footnotes.appendChild(document.createElement("div"));
ReactDOM.render(
<VisualizeLink
createdWith={t({ id: "metadata.link.created.with" })}
/>,
container
);
}

// Every text element should be dark-grey (currently we use primary.main to
// indicate interactive elements, which doesn't make sense for screenshots).
// indicate interactive elements, which doesn't make sense for screenshots)
// and not have underlines.
const color = theme.palette.grey[700];
select(node).selectAll("*").style("color", color);
select(node)
.selectAll("*")
.style("color", color)
.style("text-decoration", "none");
// SVG elements have fill instead of color. Here we only target text elements,
// to avoid changing the color of other SVG elements (charts).
select(node).selectAll("text").style("fill", color);
Expand Down

0 comments on commit 6562a3e

Please sign in to comment.