Skip to content

Commit

Permalink
fix(partition): consider legendMaxDepth on legend size
Browse files Browse the repository at this point in the history
On partition chart we should compute the legend size only for the elements actually rendered, so
everything below the legendMaxDepth if used

fix elastic#639
  • Loading branch information
markov00 committed Apr 28, 2020
1 parent f411771 commit 500c5a3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion integration/tests/all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jest.mock('../../.storybook/theme_service.ts', () => ({
switchTheme: () => undefined,
}));

const storyGroups = getStorybookInfo();
const storyGroups = getStorybookInfo().filter(({ group }) => group === 'Sunburst');

describe('Baseline Visual tests for all stories', () => {
storyGroups.forEach(({ group, encodedGroup, stories }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ import { getSettingsSpecSelector } from '../../../../state/selectors/get_setting
export const getLegendItemsLabels = createCachedSelector(
[getPieSpecOrNull, getSettingsSpecSelector, getTree],
(pieSpec, { legendMaxDepth }, tree): LegendItemLabel[] => {
if (!pieSpec || (typeof legendMaxDepth === 'number' && legendMaxDepth <= 0)) {
if (!pieSpec) {
return [];
}
return flatSlicesNames(pieSpec.layers, 0, tree);
if (typeof legendMaxDepth === 'number' && (Number.isNaN(legendMaxDepth) || legendMaxDepth <= 0)) {
return [];
}
const labels = flatSlicesNames(pieSpec.layers, 0, tree).filter(({ depth }) => {
if (typeof legendMaxDepth !== 'number') {
return true;
}
return depth <= legendMaxDepth;
});

return labels;
},
)(getChartIdSelector);

Expand All @@ -45,6 +55,7 @@ function flatSlicesNames(
if (tree.length === 0) {
return [];
}

for (let i = 0; i < tree.length; i++) {
const branch = tree[i];
const arrayNode = branch[1];
Expand Down
3 changes: 2 additions & 1 deletion stories/sunburst/8_sunburst_two_layers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
* specific language governing permissions and limitations
* under the License. */

import { Chart, Datum, Partition, PartitionLayout } from '../../src';
import { Chart, Datum, Partition, PartitionLayout, Settings } from '../../src';
import { mocks } from '../../src/mocks/hierarchical/index';
import { config } from '../../src/chart_types/partition_chart/layout/config/config';
import React from 'react';
import { countryLookup, indexInterpolatedFillColor, interpolatorCET2s, regionLookup } from '../utils/utils';

export const example = () => (
<Chart className="story-chart">
<Settings showLegend legendMaxDepth={1} />
<Partition
id="spec_1"
data={mocks.sunburst}
Expand Down

0 comments on commit 500c5a3

Please sign in to comment.