diff --git a/packages/@ourworldindata/grapher/src/barCharts/DiscreteBarChart.tsx b/packages/@ourworldindata/grapher/src/barCharts/DiscreteBarChart.tsx index d760df22e4d..3ab204b0d10 100644 --- a/packages/@ourworldindata/grapher/src/barCharts/DiscreteBarChart.tsx +++ b/packages/@ourworldindata/grapher/src/barCharts/DiscreteBarChart.tsx @@ -547,7 +547,10 @@ export class DiscreteBarChart opacity={GRAPHER_AREA_OPACITY_DEFAULT} style={{ transition: "height 200ms ease" }} /> - + { // #5 Footer // #6 [Related question] return ( -
+
{/* #1 Header */}
@@ -435,6 +444,10 @@ export class CaptionedChart extends React.Component { ) } + @computed protected get backgroundColor(): Color { + return this.manager.backgroundColor ?? GRAPHER_BACKGROUND_DEFAULT + } + @computed protected get svgProps(): React.SVGProps { return { xmlns: "http://www.w3.org/2000/svg", @@ -443,7 +456,8 @@ export class CaptionedChart extends React.Component { fontFamily: "Lato, 'Helvetica Neue', Helvetica, Arial, 'Liberation Sans', sans-serif", fontSize: this.manager.fontSize ?? BASE_FONT_SIZE, - backgroundColor: "white", + // needs to be set here or else pngs will have a black background + backgroundColor: this.backgroundColor, textRendering: "geometricPrecision", WebkitFontSmoothing: "antialiased", }, @@ -571,13 +585,15 @@ export class StaticCaptionedChart extends CaptionedChart { > {this.fonts} {this.patterns} - + {!this.manager.isExportingForSocialMedia && ( + + )} diff --git a/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx b/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx index 81473996726..6b6e2b64ce4 100644 --- a/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx +++ b/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx @@ -62,6 +62,7 @@ import { GRAPHER_AXIS_LINE_WIDTH_THICK, GRAPHER_AXIS_LINE_WIDTH_DEFAULT, BASE_FONT_SIZE, + GRAPHER_BACKGROUND_DEFAULT, } from "../core/GrapherConstants" import { ColorSchemes } from "../color/ColorSchemes" import { AxisConfig, AxisManager } from "../axis/AxisConfig" @@ -101,8 +102,6 @@ import { HorizontalNumericColorLegend, } from "../horizontalColorLegend/HorizontalColorLegends" -// background -const BACKGROUND_COLOR = "#fff" // line color const BLUR_LINE_COLOR = "#eee" const DEFAULT_LINE_COLOR = "#000" @@ -207,7 +206,9 @@ class Lines extends React.Component { "outline", series.seriesName ), - stroke: BACKGROUND_COLOR, + stroke: + this.props.backgroundColor ?? + GRAPHER_BACKGROUND_DEFAULT, strokeWidth: this.strokeWidth + this.lineOutlineWidth * 2, @@ -585,7 +586,10 @@ export class LineChart ) : series.color } - stroke="#fff" + stroke={ + this.manager.backgroundColor ?? + GRAPHER_BACKGROUND_DEFAULT + } strokeWidth={0.5} /> ) @@ -854,7 +858,9 @@ export class LineChart const lineWidth = manager.isStaticAndSmall ? GRAPHER_AXIS_LINE_WIDTH_THICK : GRAPHER_AXIS_LINE_WIDTH_DEFAULT - const dashPattern = manager.isStaticAndSmall ? "7, 7" : undefined + const dashPattern = manager.isExportingForSocialMedia + ? "7, 7" + : undefined return ( ))} {manager.showLegend && } @@ -898,6 +905,7 @@ export class LineChart focusedSeriesNames={this.focusedSeriesNames} lineStrokeWidth={this.lineStrokeWidth} lineOutlineWidth={this.lineOutlineWidth} + backgroundColor={this.manager.backgroundColor} markerRadius={this.markerRadius} isStatic={manager.isStatic} /> @@ -1067,11 +1075,14 @@ export class LineChart } numericBinSize = 6 - numericBinStroke = BACKGROUND_COLOR numericBinStrokeWidth = 1 legendTextColor = "#555" legendTickSize = 1 + @computed get numericBinStroke(): Color { + return this.manager.backgroundColor ?? GRAPHER_BACKGROUND_DEFAULT + } + @computed get numericLegend(): HorizontalNumericColorLegend | undefined { return this.hasColorScale && this.manager.showLegend ? new HorizontalNumericColorLegend({ manager: this }) diff --git a/packages/@ourworldindata/grapher/src/lineCharts/LineChartConstants.ts b/packages/@ourworldindata/grapher/src/lineCharts/LineChartConstants.ts index 0adb09fb480..b290a436a23 100644 --- a/packages/@ourworldindata/grapher/src/lineCharts/LineChartConstants.ts +++ b/packages/@ourworldindata/grapher/src/lineCharts/LineChartConstants.ts @@ -36,6 +36,7 @@ export interface LinesProps { markerRadius?: number isStatic?: boolean multiColor?: boolean + backgroundColor?: string } export interface LineChartManager extends ChartManager { diff --git a/packages/@ourworldindata/grapher/src/modal/DownloadModal.tsx b/packages/@ourworldindata/grapher/src/modal/DownloadModal.tsx index 21dd4e3822b..7327b68ec6d 100644 --- a/packages/@ourworldindata/grapher/src/modal/DownloadModal.tsx +++ b/packages/@ourworldindata/grapher/src/modal/DownloadModal.tsx @@ -39,6 +39,7 @@ export interface DownloadModalManager { isOnChartOrMapTab?: boolean framePaddingVertical?: number showAdminControls?: boolean + isSocialMediaExport?: boolean } interface DownloadModalProps { @@ -63,6 +64,10 @@ export class DownloadModal extends React.Component { return this.manager.staticFormat === GrapherStaticFormat.square } + @computed private get isSocialMediaExport(): boolean { + return this.manager.isSocialMediaExport ?? false + } + @computed private get shouldIncludeDetails(): boolean { return !!this.manager.shouldIncludeDetailsInStaticExport } @@ -204,6 +209,10 @@ export class DownloadModal extends React.Component { : GrapherStaticFormat.square } + @action.bound private toggleExportForUseInSocialMedia(): void { + this.manager.isSocialMediaExport = !this.isSocialMediaExport + } + @action.bound private toggleIncludeDetails(): void { this.manager.shouldIncludeDetailsInStaticExport = !this.manager.shouldIncludeDetailsInStaticExport @@ -295,11 +304,37 @@ export class DownloadModal extends React.Component { { + onChange={action((): void => { this.reset() this.toggleExportFormat() + + if (!this.isExportingSquare) { + this.manager.isSocialMediaExport = + false + } + this.export() - }} + })} + /> + )} + {this.manager.showAdminControls && ( + { + this.reset() + this.toggleExportForUseInSocialMedia() + + // set reasonable defaults for social media exports + if (this.isSocialMediaExport) { + this.manager.staticFormat = + GrapherStaticFormat.square + this.manager.shouldIncludeDetailsInStaticExport = + false + } + + this.export() + })} /> )}
diff --git a/packages/@ourworldindata/grapher/src/scatterCharts/ComparisonLine.tsx b/packages/@ourworldindata/grapher/src/scatterCharts/ComparisonLine.tsx index 97ece7dd9da..19fadad9d82 100644 --- a/packages/@ourworldindata/grapher/src/scatterCharts/ComparisonLine.tsx +++ b/packages/@ourworldindata/grapher/src/scatterCharts/ComparisonLine.tsx @@ -11,7 +11,7 @@ import { observer } from "mobx-react" import { DualAxis } from "../axis/Axis" import { generateComparisonLinePoints } from "./ComparisonLineGenerator" import { Halo } from "../halo/Halo" -import { ComparisonLineConfig } from "@ourworldindata/types" +import { Color, ComparisonLineConfig } from "@ourworldindata/types" import { GRAPHER_FONT_SCALE_10_5 } from "../core/GrapherConstants" @observer @@ -19,6 +19,7 @@ export class ComparisonLine extends React.Component<{ dualAxis: DualAxis comparisonLine: ComparisonLineConfig baseFontSize: number + backgroundColor?: Color }> { private renderUid = guid() @@ -122,7 +123,10 @@ export class ComparisonLine extends React.Component<{ }} clipPath={`url(#axisBounds-${renderUid})`} > - + ) } @@ -829,6 +830,7 @@ export class ScatterPlotChart dualAxis={dualAxis} comparisonLine={line} baseFontSize={this.fontSize} + backgroundColor={this.manager.backgroundColor} /> ))} {this.points} diff --git a/packages/@ourworldindata/grapher/src/scatterCharts/ScatterPlotChartConstants.ts b/packages/@ourworldindata/grapher/src/scatterCharts/ScatterPlotChartConstants.ts index 6662ab8e613..0c88c3eb8cc 100644 --- a/packages/@ourworldindata/grapher/src/scatterCharts/ScatterPlotChartConstants.ts +++ b/packages/@ourworldindata/grapher/src/scatterCharts/ScatterPlotChartConstants.ts @@ -136,6 +136,7 @@ export interface ScatterPointsWithLabelsProps { disableIntroAnimation?: boolean hideScatterLabels?: boolean quadtree: Quadtree + backgroundColor?: Color } export const SCATTER_QUADTREE_SAMPLING_DISTANCE = 10 diff --git a/packages/@ourworldindata/grapher/src/scatterCharts/ScatterPointsWithLabels.tsx b/packages/@ourworldindata/grapher/src/scatterCharts/ScatterPointsWithLabels.tsx index 01ce3169bd3..53eb8859604 100644 --- a/packages/@ourworldindata/grapher/src/scatterCharts/ScatterPointsWithLabels.tsx +++ b/packages/@ourworldindata/grapher/src/scatterCharts/ScatterPointsWithLabels.tsx @@ -425,6 +425,7 @@ export class ScatterPointsWithLabels extends React.Component fontSize?: number tooltipSeries?: ScatterSeries + backgroundColor?: Color } const LEGEND_PADDING = 3 @@ -190,6 +193,7 @@ export class ScatterSizeLegend { } labelFontSize={this.fontSizeFromRadius(radius)} labelFill={highlight ? "#bbb" : LEGEND_VALUE_COLOR} + backgroundColor={this.manager.backgroundColor} /> ) })} @@ -214,6 +218,7 @@ export class ScatterSizeLegend { labelFill={darkenColorForText(highlight.color)} labelFontWeight={700} outsideLabel={true} + backgroundColor={this.manager.backgroundColor} /> )} @@ -271,6 +276,7 @@ const LegendItem = ({ labelFontSize, labelFontWeight = 400, outsideLabel = false, + backgroundColor = GRAPHER_BACKGROUND_DEFAULT, }: { label: string cx: number @@ -284,6 +290,7 @@ const LegendItem = ({ labelFontSize: number labelFontWeight?: number outsideLabel?: boolean + backgroundColor?: Color }): React.ReactElement => { const style: React.CSSProperties = { fontSize: labelFontSize, @@ -301,7 +308,11 @@ const LegendItem = ({ strokeWidth={circleStrokeWidth} opacity={circleOpacity} /> - + ))} {this.showTotalValueLabel && ( - +