Skip to content

Commit

Permalink
fix: merge issues and code simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
nickofthyme committed Jan 19, 2021
1 parent 22fc63d commit 69c7dc8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 35 deletions.
13 changes: 0 additions & 13 deletions src/chart_types/partition_chart/partition.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
{ index: 0, value: 'A' },
],
depth: 0,
path: [0, 0],
label: 'A',
seriesIdentifier: { key: 'A', specId: 'spec1' },
},
Expand All @@ -115,7 +114,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
{ index: 0, value: 'A' },
],
depth: 1,
path: [0, 0, 0],
label: 'A',
seriesIdentifier: { key: 'A', specId: 'spec1' },
},
Expand All @@ -128,7 +126,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
{ index: 1, value: 'B' },
],
depth: 1,
path: [0, 0, 1],
label: 'B',
seriesIdentifier: { key: 'B', specId: 'spec1' },
},
Expand All @@ -140,7 +137,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
{ index: 1, value: 'B' },
],
depth: 0,
path: [0, 1],
label: 'B',
seriesIdentifier: { key: 'B', specId: 'spec1' },
},
Expand All @@ -153,7 +149,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
{ index: 0, value: 'A' },
],
depth: 1,
path: [0, 1, 0],
label: 'A',
seriesIdentifier: { key: 'A', specId: 'spec1' },
},
Expand All @@ -166,7 +161,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
{ index: 1, value: 'B' },
],
depth: 1,
path: [0, 1, 1],
label: 'B',
seriesIdentifier: { key: 'B', specId: 'spec1' },
},
Expand All @@ -178,7 +172,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
{ index: 2, value: 'C' },
],
depth: 0,
path: [0, 2],
label: 'C',
seriesIdentifier: { key: 'C', specId: 'spec1' },
},
Expand All @@ -191,7 +184,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
{ index: 0, value: 'A' },
],
depth: 1,
path: [0, 2, 0],
label: 'A',
seriesIdentifier: { key: 'A', specId: 'spec1' },
},
Expand All @@ -204,7 +196,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
{ index: 1, value: 'B' },
],
depth: 1,
path: [0, 2, 1],
label: 'B',
seriesIdentifier: { key: 'B', specId: 'spec1' },
},
Expand All @@ -228,7 +219,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
},
],
depth: 0,
path: [0, 0],
label: 'A',
seriesIdentifier: { key: 'A', specId: 'spec1' },
},
Expand All @@ -251,7 +241,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
],

depth: 1,
path: [0, 0, 0],
label: 'A',
seriesIdentifier: { key: 'A', specId: 'spec1' },
},
Expand All @@ -275,7 +264,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
},
],
depth: 0,
path: [0, 0],
label: 'C',
seriesIdentifier: { key: 'C', specId: 'spec1' },
},
Expand All @@ -297,7 +285,6 @@ describe('Retain hierarchy even with arbitrary names', () => {
},
],
depth: 1,
path: [0, 0, 0],
label: 'B',
seriesIdentifier: { key: 'B', specId: 'spec1' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import createCachedSelector from 're-reselect';

import { LegendItemExtraValues } from '../../../../commons/legend';
import { SeriesKey } from '../../../../commons/series_id';
import { LegendItemExtraValues } from '../../../../common/legend';
import { SeriesKey } from '../../../../common/series_id';
import { SettingsSpec } from '../../../../specs';
import { getChartIdSelector } from '../../../../state/selectors/get_chart_id';
import { getSettingsSpecSelector } from '../../../../state/selectors/get_settings_specs';
Expand All @@ -35,14 +35,7 @@ export const getLegendItemsExtra = createCachedSelector(
(pieSpec, { legendMaxDepth }, tree): Map<SeriesKey, LegendItemExtraValues> => {
const legendExtraValues = new Map<SeriesKey, LegendItemExtraValues>();

if (!pieSpec) {
return legendExtraValues;
}
if (isInvalidLegendMaxDepth(legendMaxDepth)) {
return legendExtraValues;
}

return getExtraValueMap(pieSpec, tree);
return pieSpec && !isInvalidLegendMaxDepth(legendMaxDepth) ? getExtraValueMap(pieSpec, tree) : legendExtraValues;
},
)(getChartIdSelector);

Expand All @@ -63,10 +56,6 @@ function getExtraValueMap(
tree: HierarchyOfArrays,
keys: Map<SeriesKey, LegendItemExtraValues> = new Map(),
): Map<SeriesKey, LegendItemExtraValues> {
if (tree.length === 0) {
return keys;
}

for (let i = 0; i < tree.length; i++) {
const branch = tree[i];
const [key, arrayNode] = branch;
Expand All @@ -77,7 +66,7 @@ function getExtraValueMap(
const formattedValue = valueFormatter ? valueFormatter(value) : value;

values.set(key, formattedValue);
keys.set(path.join('__'), values);
keys.set(path.map(({ value: v }) => v).join('__'), values);
}

getExtraValueMap({ layers, valueFormatter }, children, keys);
Expand Down
9 changes: 2 additions & 7 deletions src/components/legend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@ import { LegendItemExtraValues, LegendItem } from '../../common/legend';

/** @internal */
export function getExtra(extraValues: Map<string, LegendItemExtraValues>, item: LegendItem, totalItems: number) {
const {
seriesIdentifier: { key },
defaultExtra,
childId,
path,
} = item;
const { defaultExtra, childId, path } = item;
if (extraValues.size === 0) {
return defaultExtra?.formatted ?? '';
}
const extraValueKey = path ? path.join('__') : key;
const extraValueKey = path.map(({ value: v }) => v).join('__');
const itemExtraValues = extraValues.get(extraValueKey);
const actionExtra = (childId && itemExtraValues?.get(childId)) ?? null;
if (extraValues.size !== totalItems) {
Expand Down

0 comments on commit 69c7dc8

Please sign in to comment.