From 6562a3e9a22ddf2fae126f4c441bc01de7a414bb Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Wed, 4 Dec 2024 13:26:56 +0100 Subject: [PATCH] feat: Add Created with Visualize link to screenshot footnotes --- app/components/chart-footnotes.tsx | 11 +++++++--- app/components/chart-published.tsx | 2 +- app/components/chart-shared.tsx | 33 ++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/app/components/chart-footnotes.tsx b/app/components/chart-footnotes.tsx index d2df08c74..536492604 100644 --- a/app/components/chart-footnotes.tsx +++ b/app/components/chart-footnotes.tsx @@ -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"; @@ -41,6 +41,8 @@ export const useFootnotesStyles = makeStyles( }) ); +export const CHART_FOOTNOTES_CLASS_NAME = "chart-footnotes"; + export const ChartFootnotes = ({ dataSource, chartConfig, @@ -73,7 +75,10 @@ export const ChartFootnotes = ({ const formatLocale = useTimeFormatLocale(); return ( - :not(:last-child)": { mb: 3 } }}> + :not(:last-child)": { mb: 3 } }} + > {data?.dataCubesMetadata.map((metadata) => (
{ + const footnotes = node.querySelector(CHART_FOOTNOTES_CLASS_NAME); + + if (footnotes) { + const container = footnotes.appendChild(document.createElement("div")); + ReactDOM.render( + , + 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);