Skip to content

Commit bc0b3a5

Browse files
authored
Merge pull request #913 from visualize-admin/feat/metadata-panel
feat: Metadata panel v2
2 parents 85b0611 + e76efef commit bc0b3a5

27 files changed

Lines changed: 709 additions & 382 deletions

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ You can also check the [release page](https://github.com/visualize-admin/visuali
99

1010
## Unreleased
1111

12-
Nothing yet.
12+
- Metadata is now shown in a dedicated panel that can be reached both from editor & published mode
1313

1414
## [3.15.0] - 2022-11-29
1515

app/charts/area/areas-state.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
formatNumberWithUnit,
4848
useTimeFormatUnit,
4949
} from "@/formatters";
50+
import { DimensionMetadataFragment } from "@/graphql/query-hooks";
5051
import { getPalette } from "@/palettes";
5152
import { sortByIndex } from "@/utils/array";
5253
import { estimateTextWidth } from "@/utils/estimate-text-width";
@@ -70,7 +71,7 @@ export interface AreasState extends CommonChartState {
7071
segments: string[];
7172
colors: ScaleOrdinal<string, string>;
7273
yAxisLabel: string;
73-
yAxisDescription: string | undefined;
74+
yAxisDimension: DimensionMetadataFragment;
7475
chartWideData: ArrayLike<Observation>;
7576
allDataWide: ArrayLike<Observation>;
7677
series: $FixMe[];
@@ -202,7 +203,6 @@ const useAreasState = (
202203
}
203204

204205
const yAxisLabel = getLabelWithUnit(yMeasure);
205-
const yAxisDescription = yMeasure.description || undefined;
206206

207207
/** Ordered segments */
208208
const segmentSorting = fields.segment?.sorting;
@@ -404,7 +404,7 @@ const useAreasState = (
404404
yScale,
405405
getSegment,
406406
yAxisLabel,
407-
yAxisDescription,
407+
yAxisDimension: yMeasure,
408408
segments,
409409
colors,
410410
chartWideData,

app/charts/column/columns-grouped-state.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
} from "@/configurator/components/ui-helpers";
5252
import { isTemporalDimension, Observation } from "@/domain/data";
5353
import { useFormatNumber, formatNumberWithUnit } from "@/formatters";
54+
import { DimensionMetadataFragment } from "@/graphql/query-hooks";
5455
import { getPalette } from "@/palettes";
5556
import { sortByIndex } from "@/utils/array";
5657
import {
@@ -77,7 +78,7 @@ export interface GroupedColumnsState extends CommonChartState {
7778
segments: string[];
7879
colors: ScaleOrdinal<string, string>;
7980
yAxisLabel: string;
80-
yAxisDescription: string | undefined;
81+
yAxisDimension: DimensionMetadataFragment;
8182
grouped: [string, Observation[]][];
8283
getAnnotationInfo: (d: Observation) => TooltipInfo;
8384
showStandardError: boolean;
@@ -312,7 +313,6 @@ const useGroupedColumnsState = (
312313
}
313314

314315
const yAxisLabel = getLabelWithUnit(yMeasure);
315-
const yAxisDescription = yMeasure.description || undefined;
316316

317317
// Group
318318
const grouped = useMemo(() => {
@@ -452,7 +452,7 @@ const useGroupedColumnsState = (
452452
getSegment,
453453
getSegmentLabel,
454454
yAxisLabel,
455-
yAxisDescription,
455+
yAxisDimension: yMeasure,
456456
segments,
457457
colors,
458458
grouped,

app/charts/column/columns-stacked-state.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { Observer, useWidth } from "@/charts/shared/use-width";
5151
import { ColumnFields, SortingOrder, SortingType } from "@/configurator";
5252
import { isTemporalDimension, Observation } from "@/domain/data";
5353
import { formatNumberWithUnit, useFormatNumber } from "@/formatters";
54+
import { DimensionMetadataFragment } from "@/graphql/query-hooks";
5455
import { getPalette } from "@/palettes";
5556
import { sortByIndex } from "@/utils/array";
5657
import {
@@ -75,7 +76,7 @@ export interface StackedColumnsState extends CommonChartState {
7576
segments: string[];
7677
colors: ScaleOrdinal<string, string>;
7778
yAxisLabel: string;
78-
yAxisDescription: string | undefined;
79+
yAxisDimension: DimensionMetadataFragment;
7980
chartWideData: ArrayLike<Observation>;
8081
allDataWide: ArrayLike<Observation>;
8182
grouped: [string, Observation[]][];
@@ -325,7 +326,6 @@ const useColumnsStackedState = (
325326
}
326327

327328
const yAxisLabel = getLabelWithUnit(yMeasure);
328-
const yAxisDescription = yMeasure.description || undefined;
329329

330330
const yScale = scaleLinear().domain(yStackDomain).nice();
331331

@@ -507,7 +507,7 @@ const useColumnsStackedState = (
507507
getSegment,
508508
getSegmentLabel,
509509
yAxisLabel,
510-
yAxisDescription,
510+
yAxisDimension: yMeasure,
511511
segments,
512512
colors,
513513
chartWideData,

app/charts/column/columns-state.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ import {
5353
formatNumberWithUnit,
5454
useTimeFormatUnit,
5555
} from "@/formatters";
56-
import { TemporalDimension, TimeUnit } from "@/graphql/query-hooks";
56+
import {
57+
DimensionMetadataFragment,
58+
TemporalDimension,
59+
TimeUnit,
60+
} from "@/graphql/query-hooks";
5761
import { getPalette } from "@/palettes";
5862
import {
5963
getSortingOrders,
@@ -79,7 +83,7 @@ export interface ColumnsState extends CommonChartState {
7983
segments: string[];
8084
colors: ScaleOrdinal<string, string>;
8185
yAxisLabel: string;
82-
yAxisDescription: string | undefined;
86+
yAxisDimension: DimensionMetadataFragment;
8387
getAnnotationInfo: (d: Observation) => TooltipInfo;
8488
showStandardError: boolean;
8589
}
@@ -229,7 +233,6 @@ const useColumnsState = (
229233
}
230234

231235
const yAxisLabel = getLabelWithUnit(yMeasure);
232-
const yAxisDescription = yMeasure.description || undefined;
233236

234237
const { left, bottom } = useChartPadding(
235238
yScale,
@@ -358,7 +361,7 @@ const useColumnsState = (
358361
getSegment,
359362
getSegmentLabel,
360363
yAxisLabel,
361-
yAxisDescription,
364+
yAxisDimension: yMeasure,
362365
segments,
363366
colors,
364367
getAnnotationInfo,

app/charts/line/lines-state.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
formatNumberWithUnit,
4141
useTimeFormatUnit,
4242
} from "@/formatters";
43+
import { DimensionMetadataFragment } from "@/graphql/query-hooks";
4344
import { getPalette } from "@/palettes";
4445
import { sortByIndex } from "@/utils/array";
4546
import { estimateTextWidth } from "@/utils/estimate-text-width";
@@ -62,7 +63,7 @@ export interface LinesState extends CommonChartState {
6263
colors: ScaleOrdinal<string, string>;
6364
xAxisLabel: string;
6465
yAxisLabel: string;
65-
yAxisDescription: string | undefined;
66+
yAxisDimension: DimensionMetadataFragment;
6667
grouped: Map<string, Observation[]>;
6768
chartWideData: ArrayLike<Observation>;
6869
allDataWide: ArrayLike<Observation>;
@@ -184,7 +185,6 @@ const useLinesState = (
184185
}
185186

186187
const yAxisLabel = getLabelWithUnit(yMeasure);
187-
const yAxisDescription = yMeasure.description || undefined;
188188

189189
const segmentDimension = useMemo(() => {
190190
return (
@@ -345,7 +345,7 @@ const useLinesState = (
345345
getSegmentLabel,
346346
xAxisLabel,
347347
yAxisLabel,
348-
yAxisDescription,
348+
yAxisDimension: yMeasure,
349349
segments,
350350
colors,
351351
grouped: preparedDataGroupedBySegment,

app/charts/scatterplot/scatterplot-state.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { ScatterPlotFields } from "@/configurator";
2828
import { mkNumber } from "@/configurator/components/ui-helpers";
2929
import { DimensionValue, Observation } from "@/domain/data";
3030
import { useFormatNumber } from "@/formatters";
31+
import { DimensionMetadataFragment } from "@/graphql/query-hooks";
3132
import { getPalette } from "@/palettes";
3233
import { estimateTextWidth } from "@/utils/estimate-text-width";
3334

@@ -43,9 +44,9 @@ export interface ScatterplotState extends CommonChartState {
4344
getSegment: (d: Observation) => string;
4445
colors: ScaleOrdinal<string, string>;
4546
xAxisLabel: string;
46-
xAxisDescription: string | undefined;
47+
xAxisDimension: DimensionMetadataFragment;
4748
yAxisLabel: string;
48-
yAxisDescription: string | undefined;
49+
yAxisDimension: DimensionMetadataFragment;
4950
getSegmentLabel: (s: string) => string;
5051
getAnnotationInfo: (d: Observation, values: Observation[]) => TooltipInfo;
5152
}
@@ -93,7 +94,6 @@ const useScatterplotState = ({
9394
}
9495

9596
const xAxisLabel = getLabelWithUnit(xMeasure);
96-
const xAxisDescription = xMeasure.description || undefined;
9797

9898
const xMinValue = Math.min(mkNumber(min(preparedData, (d) => getX(d))), 0);
9999
const xMaxValue = max(preparedData, (d) => getX(d)) as number;
@@ -107,7 +107,6 @@ const useScatterplotState = ({
107107
}
108108

109109
const yAxisLabel = getLabelWithUnit(yMeasure);
110-
const yAxisDescription = yMeasure.description || undefined;
111110

112111
const yMinValue = Math.min(mkNumber(min(preparedData, (d) => getY(d))), 0);
113112
const yMaxValue = max(preparedData, getY) as number;
@@ -243,9 +242,9 @@ const useScatterplotState = ({
243242
getSegment,
244243
colors,
245244
xAxisLabel,
246-
xAxisDescription,
245+
xAxisDimension: xMeasure,
247246
yAxisLabel,
248-
yAxisDescription,
247+
yAxisDimension: yMeasure,
249248
getAnnotationInfo,
250249
getSegmentLabel,
251250
};

app/charts/shared/axis-height-linear.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { LinesState } from "@/charts/line/lines-state";
1010
import { ScatterplotState } from "@/charts/scatterplot/scatterplot-state";
1111
import { useChartState } from "@/charts/shared/use-chart-state";
1212
import { useChartTheme } from "@/charts/shared/use-chart-theme";
13+
import { OpenMetadataPanelWrapper } from "@/components/metadata-panel";
1314
import { useFormatNumber } from "@/formatters";
14-
import { MaybeTooltip } from "@/utils/maybe-tooltip";
1515

1616
export const TICK_MIN_HEIGHT = 50;
1717

@@ -23,7 +23,7 @@ export const AxisHeightLinear = () => {
2323
const ref = useRef<SVGGElement>(null);
2424
const formatNumber = useFormatNumber({ decimals: "auto" });
2525

26-
const { yScale, yAxisLabel, yAxisDescription, bounds } = useChartState() as
26+
const { yScale, yAxisLabel, yAxisDimension, bounds } = useChartState() as
2727
| AreasState
2828
| ColumnsState
2929
| GroupedColumnsState
@@ -61,19 +61,11 @@ export const AxisHeightLinear = () => {
6161

6262
return (
6363
<>
64-
<g>
65-
<MaybeTooltip text={yAxisDescription}>
66-
<text
67-
x={0}
68-
y={0}
69-
dy={labelFontSize}
70-
fontSize={labelFontSize}
71-
textDecoration={yAxisDescription ? "underline" : undefined}
72-
>
73-
{yAxisLabel}
74-
</text>
75-
</MaybeTooltip>
76-
</g>
64+
<OpenMetadataPanelWrapper dim={yAxisDimension} svg={true}>
65+
<text x={0} y={0} dy={labelFontSize} fontSize={labelFontSize}>
66+
{yAxisLabel}
67+
</text>
68+
</OpenMetadataPanelWrapper>
7769
<g
7870
ref={ref}
7971
transform={`translate(${bounds.margins.left}, ${bounds.margins.top})`}

app/charts/shared/axis-width-linear.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { useEffect, useRef } from "react";
55
import { ScatterplotState } from "@/charts/scatterplot/scatterplot-state";
66
import { useChartState } from "@/charts/shared/use-chart-state";
77
import { useChartTheme } from "@/charts/shared/use-chart-theme";
8+
import { OpenMetadataPanelWrapper } from "@/components/metadata-panel";
89
import { useFormatNumber } from "@/formatters";
910
import { estimateTextWidth } from "@/utils/estimate-text-width";
10-
import { MaybeTooltip } from "@/utils/maybe-tooltip";
1111

1212
export const AxisWidthLinear = () => {
1313
const formatNumber = useFormatNumber();
14-
const { xScale, bounds, xAxisLabel, xAxisDescription } =
14+
const { xScale, bounds, xAxisLabel, xAxisDimension } =
1515
useChartState() as ScatterplotState;
1616
const { chartWidth, chartHeight, margins } = bounds;
1717
const { labelColor, labelFontSize, gridColor, fontFamily } = useChartTheme();
@@ -51,18 +51,17 @@ export const AxisWidthLinear = () => {
5151
return (
5252
<>
5353
<g transform={`translate(${margins.left}, ${margins.top})`}>
54-
<MaybeTooltip text={xAxisDescription}>
54+
<OpenMetadataPanelWrapper dim={xAxisDimension} svg={true}>
5555
<text
5656
x={chartWidth}
5757
y={chartHeight + margins.bottom}
5858
dy={-labelFontSize}
5959
fontSize={labelFontSize}
6060
textAnchor="end"
61-
textDecoration={xAxisDescription ? "underline" : undefined}
6261
>
6362
{xAxisLabel}
6463
</text>
65-
</MaybeTooltip>
64+
</OpenMetadataPanelWrapper>
6665
</g>
6766
<g
6867
ref={xAxisRef}

0 commit comments

Comments
 (0)