Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(legend): expose legend extra configuration #2043

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5b89d40
test:add example for last bucket error
markov00 May 17, 2023
9a5c199
Merge branch 'main' into 2023_05_17-fix_last_bucket
markov00 May 17, 2023
a502693
test(vrt): update screenshots [skip ci]
elastic-datavis[bot] May 17, 2023
fbeb404
feat(legend): improve legend extra configuration
markov00 May 18, 2023
22e7275
revert: interval changes
markov00 May 18, 2023
0490f93
fix min, max
markov00 May 22, 2023
eb44744
fix min max
markov00 May 22, 2023
275fbb9
fix extra visibility when not configured
markov00 May 22, 2023
1808cec
small refactor
markov00 May 22, 2023
e5ca643
add back the ordinal last value
markov00 May 22, 2023
9ad8b02
WIP
markov00 May 23, 2023
bf57cb1
fix(legend): extra not shown with categorical charts
markov00 May 24, 2023
ab72f96
add decision comment to legend extra
markov00 May 24, 2023
e1bc598
add issue to comment
markov00 May 24, 2023
1b8acf8
fix tests
markov00 May 24, 2023
bc74b47
Merge branch 'main' into 2023_05_17-fix_last_bucket
markov00 May 24, 2023
5a9494d
test(vrt): update screenshots [skip ci]
elastic-datavis[bot] May 24, 2023
4f66648
revert screenshots to main
markov00 May 24, 2023
b2ee8f1
chore: update vrt screenshots [update-vrt]
markov00 May 24, 2023
dc1b541
test(vrt): update screenshots [skip ci]
elastic-datavis[bot] May 24, 2023
ef65677
remove screenshots
markov00 May 25, 2023
bbe7c3f
add back screenshot from main
markov00 May 25, 2023
59f9ccb
Merge branch 'main' into 2023_05_17-fix_last_bucket
markov00 May 25, 2023
d95ed06
test(vrt): update screenshots [skip ci]
elastic-datavis[bot] May 29, 2023
340ba86
Merge branch 'main' into 2023_05_17-fix_last_bucket
markov00 Jun 5, 2023
e0711b8
refactor: rename extras with values
markov00 Jun 6, 2023
68d5746
refactor: fix lint and tests
markov00 Jun 6, 2023
7a21197
Merge branch 'main' into 2023_05_17-fix_last_bucket
markov00 Jun 6, 2023
b25d208
refactor: fix last missing rename
markov00 Jun 6, 2023
a3036a1
fix screenshots and wrong merge in story
markov00 Jun 6, 2023
64481f9
test(vrt): update screenshots [skip ci]
elastic-datavis[bot] Jun 6, 2023
7fc0526
refactor: replace strings with enum
markov00 Jun 7, 2023
fe167d1
Merge branch 'main' into 2023_05_17-fix_last_bucket
markov00 Jun 8, 2023
0817ed0
move legend types in its own file
markov00 Jun 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
2 changes: 1 addition & 1 deletion e2e/tests/interactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ test.describe('Interactions', () => {
);
});

test('show synced extra values in legend', async ({ page }) => {
test('show synced values in legend', async ({ page }) => {
await common.expectChartWithMouseAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/interactions--cursor-update-action&knob-Series type_Top Chart=line&knob-enable external tooltip_Top Chart=true&knob-Series type_Bottom Chart=line&knob-enable external tooltip_Bottom Chart=false&knob-pointer update debounce=0',
{ right: 200, top: 80 },
Expand Down
14 changes: 7 additions & 7 deletions e2e/tests/legend_stories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ test.describe('Legend stories', () => {

test('should correctly render multiline nested legend labels', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--piechart&globals=background:white;theme:light&knob-Hide color picker=true&knob-Hide color picker_Legend=true&knob-Legend position=right&knob-Legend position_Legend=right&knob-max legend label lines=0&knob-Number of series=5&knob-Popover position=leftCenter&knob-Popover position_Legend=leftCenter&knob-Series with long name=3&knob-direction_Legend=vertical&knob-floating columns_Legend=2&knob-hAlign_Legend=right&knob-legend buffer value=80&knob-legend margins=20&knob-long label text_Legend=Non do aliqua veniam dolore ipsum eu aliquip. Culpa in duis amet non velit qui non ullamco sit adipisicing. Ut sunt Lorem mollit exercitation deserunt officia sunt ipsum eu amet.&knob-multiline Legend labels=true&knob-vAlign_Legend=bottom&knob-Partition Layout=sunburst&knob-flatLegend=&knob-showLegendExtra=&knob-legendMaxDepth=2&knob-legendStrategy=key',
'http://localhost:9001/?path=/story/legend--piechart&globals=background:white;theme:light&knob-Hide color picker=true&knob-Hide color picker_Legend=true&knob-Legend position=right&knob-Legend position_Legend=right&knob-max legend label lines=0&knob-Number of series=5&knob-Popover position=leftCenter&knob-Popover position_Legend=leftCenter&knob-Series with long name=3&knob-direction_Legend=vertical&knob-floating columns_Legend=2&knob-hAlign_Legend=right&knob-legend buffer value=80&knob-legend margins=20&knob-long label text_Legend=Non do aliqua veniam dolore ipsum eu aliquip. Culpa in duis amet non velit qui non ullamco sit adipisicing. Ut sunt Lorem mollit exercitation deserunt officia sunt ipsum eu amet.&knob-multiline Legend labels=true&knob-vAlign_Legend=bottom&knob-Partition Layout=sunburst&knob-flatLegend=&knob-legendValue=none&knob-legendMaxDepth=2&knob-legendStrategy=key',
);
});

test('should correctly render very long multiline legend labels', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--legend-spacing-buffer&knob-Hide color picker=true&knob-Hide color picker_Legend=true&knob-Legend position=right&knob-Legend position_Legend=right&knob-Number of series=5&knob-Partition Layout=sunburst&knob-Popover position=leftCenter&knob-Popover position_Legend=leftCenter&knob-Series with long name=3&knob-direction_Legend=vertical&knob-flatLegend=true&knob-floating columns_Legend=2&knob-hAlign_Legend=right&knob-legend buffer value=80&knob-legend margins=20&knob-legendMaxDepth=3&knob-legendStrategy=key&knob-long label text_Legend=Non do aliqua veniam dolore ipsum eu aliquip. Culpa in duis amet non velit qui non ullamco sit adipisicing. Ut sunt Lorem mollit exercitation deserunt officia sunt ipsum eu amet.&knob-max legend label lines=0&knob-showLegendExtra=true&knob-use long labels=true&knob-vAlign_Legend=bottom',
'http://localhost:9001/?path=/story/legend--legend-spacing-buffer&knob-Hide color picker=true&knob-Hide color picker_Legend=true&knob-Legend position=right&knob-Legend position_Legend=right&knob-Number of series=5&knob-Partition Layout=sunburst&knob-Popover position=leftCenter&knob-Popover position_Legend=leftCenter&knob-Series with long name=3&knob-direction_Legend=vertical&knob-flatLegend=true&knob-floating columns_Legend=2&knob-hAlign_Legend=right&knob-legend buffer value=80&knob-legend margins=20&knob-legendMaxDepth=3&knob-legendStrategy=key&knob-long label text_Legend=Non do aliqua veniam dolore ipsum eu aliquip. Culpa in duis amet non velit qui non ullamco sit adipisicing. Ut sunt Lorem mollit exercitation deserunt officia sunt ipsum eu amet.&knob-max legend label lines=0&knob-legendValue=lastBucket&knob-use long labels=true&knob-vAlign_Legend=bottom',
);
});

Expand Down Expand Up @@ -184,21 +184,21 @@ test.describe('Legend stories', () => {
});
});

test.describe('Extra values', () => {
test.describe('Legend values', () => {
pwEach.test([PartitionLayout.sunburst, PartitionLayout.treemap])(
(l) => `should display flat legend extra values on ${l}`,
(l) => `should display flat legend values on ${l}`,
async (page, layout) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
`http://localhost:9001/?path=/story/legend--piechart&knob-Partition Layout=${layout}&knob-flatLegend=true&knob-showLegendExtra=true&knob-legendMaxDepth=2`,
`http://localhost:9001/?path=/story/legend--piechart&knob-Partition Layout=${layout}&knob-flatLegend=true&knob-legendValue=lastBucket&knob-legendMaxDepth=2`,
);
},
);

pwEach.test([PartitionLayout.sunburst, PartitionLayout.treemap])(
(l) => `should display nested legend extra values on ${l}`,
(l) => `should display nested legend values on ${l}`,
async (page, layout) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
`http://localhost:9001/?path=/story/legend--piechart&knob-Partition Layout=${layout}&knob-flatLegend=false&knob-showLegendExtra=true&knob-legendMaxDepth=2`,
`http://localhost:9001/?path=/story/legend--piechart&knob-Partition Layout=${layout}&knob-flatLegend=false&knob-legendValue=lastBucket&knob-legendMaxDepth=2`,
);
},
);
Expand Down
6 changes: 3 additions & 3 deletions packages/charts/api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ export interface CustomLegendProps {
label: CategoryLabel;
seriesType?: SeriesType;
pointStyle?: PointStyle;
extraValue?: PrimitiveValue;
value?: PrimitiveValue;
isSeriesHidden?: boolean;
onItemOverActon: () => void;
onItemOutAction: () => void;
Expand Down Expand Up @@ -1623,6 +1623,7 @@ export interface LegendSpec {
legendSize: number;
legendSort?: SeriesCompareFn;
legendStrategy?: LegendStrategy;
legendValue: 'none' | 'lastBucket' | 'lastInSeries' | 'avg' | 'min' | 'max' | 'sum';
// (undocumented)
onLegendItemClick?: LegendItemListener;
// (undocumented)
Expand All @@ -1634,7 +1635,6 @@ export interface LegendSpec {
// (undocumented)
onLegendItemPlusClick?: LegendItemListener;
showLegend: boolean;
showLegendExtra: boolean;
}

// @public (undocumented)
Expand Down Expand Up @@ -2453,7 +2453,7 @@ export const Settings: (props: SFProps<SettingsSpec, keyof (typeof settingsBuild
// Warning: (ae-forgotten-export) The symbol "BuildProps" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export const settingsBuildProps: BuildProps<SettingsSpec, "id" | "chartType" | "specType", "debug" | "rotation" | "ariaLabelHeadingLevel" | "ariaUseDefaultSummary" | "legendPosition" | "flatLegend" | "legendMaxDepth" | "legendSize" | "showLegend" | "showLegendExtra" | "baseTheme" | "rendering" | "animateData" | "externalPointerEvents" | "pointBuffer" | "resizeDebounce" | "pointerUpdateTrigger" | "brushAxis" | "minBrushDelta" | "allowBrushingLastHistogramBin", "ariaLabel" | "xDomain" | "ariaDescription" | "ariaDescribedBy" | "ariaLabelledBy" | "ariaTableCaption" | "theme" | "legendAction" | "legendColorPicker" | "legendStrategy" | "onLegendItemClick" | "customLegend" | "onLegendItemMinusClick" | "onLegendItemOut" | "onLegendItemOver" | "onLegendItemPlusClick" | "orderOrdinalBinsBy" | "debugState" | "onProjectionClick" | "onElementClick" | "onElementOver" | "onElementOut" | "onBrushEnd" | "onPointerUpdate" | "onRenderChange" | "onProjectionAreaChange" | "onAnnotationClick" | "pointerUpdateDebounce" | "roundHistogramBrushValues" | "noResults" | "legendSort", never>;
export const settingsBuildProps: BuildProps<SettingsSpec, "id" | "chartType" | "specType", "debug" | "rotation" | "ariaLabelHeadingLevel" | "ariaUseDefaultSummary" | "legendPosition" | "flatLegend" | "legendMaxDepth" | "legendSize" | "showLegend" | "legendValue" | "baseTheme" | "rendering" | "animateData" | "externalPointerEvents" | "pointBuffer" | "resizeDebounce" | "pointerUpdateTrigger" | "brushAxis" | "minBrushDelta" | "allowBrushingLastHistogramBin", "ariaLabel" | "xDomain" | "ariaDescription" | "ariaDescribedBy" | "ariaLabelledBy" | "ariaTableCaption" | "theme" | "legendAction" | "legendColorPicker" | "legendStrategy" | "onLegendItemClick" | "customLegend" | "onLegendItemMinusClick" | "onLegendItemOut" | "onLegendItemOver" | "onLegendItemPlusClick" | "orderOrdinalBinsBy" | "debugState" | "onProjectionClick" | "onElementClick" | "onElementOver" | "onElementOut" | "onBrushEnd" | "onPointerUpdate" | "onRenderChange" | "onProjectionAreaChange" | "onAnnotationClick" | "pointerUpdateDebounce" | "roundHistogramBrushValues" | "noResults" | "legendSort", never>;

// @public (undocumented)
export type SettingsProps = ComponentProps<typeof Settings>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { FlameWithTooltip } from './flame_chart';
import { ChartType } from '..';
import { DEFAULT_CSS_CURSOR } from '../../common/constants';
import { LegendItemExtraValues } from '../../common/legend';
import { LegendItemValues } from '../../common/legend';
import { SeriesKey } from '../../common/series_id';
import { InternalChartState } from '../../state/chart_state';
import { InitStatus } from '../../state/selectors/get_internal_is_intialized';
Expand All @@ -28,7 +28,7 @@ export class FlameState implements InternalChartState {
isChartEmpty = () => false;
getLegendItemsLabels = () => [];
getLegendItems = () => [];
getLegendExtraValues = () => new Map<SeriesKey, LegendItemExtraValues>();
getLegendValues = () => new Map<SeriesKey, LegendItemValues>();
getPointerCursor = () => DEFAULT_CSS_CURSOR;
getTooltipAnchor = () => ({ x: 0, y: 0, width: 0, height: 0 });
isTooltipVisible = () => ({ visible: false, isExternal: false, displayOnly: false, isPinnable: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class GoalState implements InternalChartState {
return EMPTY_LEGEND_ITEM_LIST;
}

getLegendExtraValues() {
getLegendValues() {
return EMPTY_MAP;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class HeatmapState implements InternalChartState {
return getLegendItemsLabelsSelector(globalState);
}

getLegendExtraValues() {
getLegendValues() {
return EMPTY_MAP;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const computeLegendSelector = createCustomCachedSelector(
isToggleable: true,
path: [{ index: 0, value: label }],
keys: [],
value: {
raw: null,
formatted: '',
legendSizingLabel: '',
},
};
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { getSettingsSpecSelector } from '../../../../state/selectors/get_setting
/** @internal */
export const getLegendItemsLabelsSelector = createCustomCachedSelector(
[computeLegendSelector, getSettingsSpecSelector],
(legendItems, { showLegendExtra }): LegendItemLabel[] =>
legendItems.map(({ label, defaultExtra }) => ({
label: `${label}${showLegendExtra ? defaultExtra?.formatted ?? '' : ''}`,
(legendItems): LegendItemLabel[] =>
legendItems.map(({ label }) => ({
label: `${label}`,
depth: 0,
})),
);
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class MetricState implements InternalChartState {
isChartEmpty = () => false;
getLegendItems = () => EMPTY_LEGEND_LIST;
getLegendItemsLabels = () => EMPTY_LEGEND_ITEM_LIST;
getLegendExtraValues = () => EMPTY_MAP;
getLegendValues = () => EMPTY_MAP;
getPointerCursor = () => DEFAULT_CSS_CURSOR;
isTooltipVisible = () => ({
visible: false,
Expand Down
Loading