Skip to content

Commit 8e6bd45

Browse files
committed
refactor: move config string to pseudo enum object
1 parent 0300e6a commit 8e6bd45

4 files changed

Lines changed: 45 additions & 18 deletions

File tree

api/charts.api.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,17 @@ export interface LegendColorPickerProps {
10621062
export type LegendItemListener = (series: SeriesIdentifier | null) => void;
10631063

10641064
// @public (undocumented)
1065-
export type LegendStrategy = 'node' | 'path' | 'key' | 'keyInLayer' | 'nodeWithDescendants' | 'pathWithDescendants';
1065+
export const LegendStrategy: Readonly<{
1066+
Node: "node";
1067+
Path: "path";
1068+
KeyInLayer: "keyInLayer";
1069+
Key: "key";
1070+
NodeWithDescendants: "nodeWithDescendants";
1071+
PathWithDescendants: "pathWithDescendants";
1072+
}>;
1073+
1074+
// @public (undocumented)
1075+
export type LegendStrategy = $Values<typeof LegendStrategy>;
10661076

10671077
// Warning: (ae-missing-release-tag) "LegendStyle" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
10681078
//

src/chart_types/partition_chart/state/selectors/get_highlighted_shapes.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
import createCachedSelector from 're-reselect';
21+
import { $Values } from 'utility-types';
2122

2223
import { LegendPath } from '../../../../state/actions/legend';
2324
import { GlobalChartState } from '../../../../state/chart_state';
@@ -58,9 +59,36 @@ const legendStrategies = Object.freeze({
5859
});
5960

6061
/** @public */
61-
export type LegendStrategy = 'node' | 'path' | 'key' | 'keyInLayer' | 'nodeWithDescendants' | 'pathWithDescendants'; // keyof typeof legendStrategies
62+
export const LegendStrategy = Object.freeze({
63+
/**
64+
* Highlight the specific node(s) that the legend item stands for.
65+
*/
66+
Node: 'node' as const,
67+
/**
68+
* Highlight members of the exact path; ie. like `Node`, plus all its ancestors
69+
*/
70+
Path: 'path' as const,
71+
/**
72+
* Highlight all identically named (labelled) items within the tree layer (depth or ring) of the specific node(s) that the legend item stands for
73+
*/
74+
KeyInLayer: 'keyInLayer' as const,
75+
/**
76+
* Highlight all identically named (labelled) items, no matter where they are
77+
*/
78+
Key: 'key' as const,
79+
/**
80+
* Highlight the specific node(s) that the legend item stands for, plus all descendants
81+
*/
82+
NodeWithDescendants: 'nodeWithDescendants' as const,
83+
/**
84+
* Highlight the specific node(s) that the legend item stands for, plus all ancestors and descendants
85+
*/
86+
PathWithDescendants: 'pathWithDescendants' as const,
87+
});
6288

63-
const defaultStrategy: LegendStrategy = 'key';
89+
/** @public */
90+
export type LegendStrategy = $Values<typeof LegendStrategy>;
91+
const defaultStrategy: LegendStrategy = LegendStrategy.Key;
6492

6593
/** @internal */
6694
// why is it called highlighted... when it's a legend hover related thing, not a hover over the slices?

stories/icicle/02_unix_flame.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import React from 'react';
2121

22-
import { Chart, Datum, Partition, PartitionLayout, Settings } from '../../src';
22+
import { Chart, Datum, LegendStrategy, Partition, PartitionLayout, Settings } from '../../src';
2323
import { STORYBOOK_LIGHT_THEME } from '../shared';
2424
import { config, getFlatData, getLayerSpec, maxDepth } from '../utils/hierarchical_input_utils';
2525
import { plasma18 as palette } from '../utils/utils';
@@ -32,7 +32,7 @@ export const Example = () => {
3232
<Settings
3333
showLegend
3434
flatLegend
35-
legendStrategy="pathWithDescendants"
35+
legendStrategy={LegendStrategy.PathWithDescendants}
3636
legendMaxDepth={maxDepth}
3737
theme={STORYBOOK_LIGHT_THEME}
3838
/>

stories/legend/10_sunburst.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import { boolean, number, select } from '@storybook/addon-knobs';
2121
import React from 'react';
2222

23-
import { Chart, Datum, Partition, PartitionLayout, Settings } from '../../src';
23+
import { Chart, Datum, LegendStrategy, Partition, PartitionLayout, Settings } from '../../src';
2424
import { config } from '../../src/chart_types/partition_chart/layout/config/config';
2525
import { ShapeTreeNode } from '../../src/chart_types/partition_chart/layout/types/viewmodel_types';
2626
import { mocks } from '../../src/mocks/hierarchical';
@@ -40,18 +40,7 @@ export const Example = () => {
4040
max: 3,
4141
step: 1,
4242
});
43-
const legendStrategy = select(
44-
'legendStrategy',
45-
{
46-
node: 'node',
47-
path: 'path',
48-
keyInLayer: 'keyInLayer',
49-
key: 'key',
50-
nodeWithDescendants: 'nodeWithDescendants',
51-
pathWithDescendants: 'pathWithDescendants',
52-
},
53-
'key',
54-
);
43+
const legendStrategy = select('legendStrategy', LegendStrategy, LegendStrategy.Key);
5544

5645
return (
5746
<Chart className="story-chart">

0 commit comments

Comments
 (0)