-
Notifications
You must be signed in to change notification settings - Fork 129
fix(partition): consider legendMaxDepth on legend size #654
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
Merged
markov00
merged 7 commits into
elastic:master
from
markov00:2020_28_04-fix-partition-legend
May 26, 2020
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
500c5a3
fix(partition): consider legendMaxDepth on legend size
markov00 21160cd
Merge branch 'master' into 2020_28_04-fix-partition-legend
markov00 c9c2869
Merge branch 'master' into 2020_28_04-fix-partition-legend
markov00 aa07012
test: add legendMaxDepth tests
markov00 ebd22ee
fix: prevent null/undefined and empty values
markov00 f578467
Merge branch 'master' into 2020_28_04-fix-partition-legend
markov00 cee4b63
refactor: cleanup isInvalidLegendMaxDepth params type
markov00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
+6.5 KB
(110%)
...all-stories-sunburst-sunburst-with-two-layers-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
197 changes: 197 additions & 0 deletions
197
src/chart_types/partition_chart/state/selectors/get_legend_items_labels.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. */ | ||
|
|
||
| import { MockStore } from '../../../../mocks/store'; | ||
| import { MockSeriesSpec, MockGlobalSpec } from '../../../../mocks/specs'; | ||
| import { getLegendItemsLabels } from './get_legend_items_labels'; | ||
| import { PrimitiveValue } from '../../layout/utils/group_by_rollup'; | ||
| import { Store } from 'redux'; | ||
| import { GlobalChartState } from '../../../../state/chart_state'; | ||
|
|
||
| describe('Partition - Legend items labels', () => { | ||
| type TestDatum = [string, string, string, number]; | ||
| const spec = MockSeriesSpec.sunburst({ | ||
| data: [ | ||
| ['aaa', 'aa', '1', 1], | ||
| ['aaa', 'aa', '1', 2], // this should be filtered out | ||
| ['aaa', 'aa', '3', 1], | ||
| ['aaa', 'bb', '4', 1], | ||
| ['aaa', 'bb', '5', 1], | ||
| ['aaa', 'bb', '6', 1], | ||
| ['bbb', 'aa', '7', 1], | ||
| ['bbb', 'aa', '8', 1], | ||
| ['bbb', 'bb', '9', 1], | ||
| ['bbb', 'bb', '10', 1], | ||
| ['bbb', 'cc', '11', 1], | ||
| ['bbb', 'cc', '12', 1], | ||
| ], | ||
| valueAccessor: (d: TestDatum) => d[3], | ||
| layers: [ | ||
| { | ||
| groupByRollup: (datum: TestDatum) => datum[0], | ||
| nodeLabel: (d: PrimitiveValue) => String(d), | ||
| }, | ||
| { | ||
| groupByRollup: (datum: TestDatum) => datum[1], | ||
| nodeLabel: (d: PrimitiveValue) => String(d), | ||
| }, | ||
| { | ||
| groupByRollup: (datum: TestDatum) => datum[2], | ||
| nodeLabel: (d: PrimitiveValue) => String(d), | ||
| }, | ||
| ], | ||
| }); | ||
| let store: Store<GlobalChartState>; | ||
|
|
||
| beforeEach(() => { | ||
| store = MockStore.default(); | ||
| }); | ||
|
|
||
| it('no filter for no legendMaxDepth + filter duplicates', () => { | ||
| MockStore.addSpecs([spec], store); | ||
|
|
||
| const labels = getLegendItemsLabels(store.getState()); | ||
| expect(labels).toEqual([ | ||
| { | ||
| depth: 1, | ||
| label: 'aaa', | ||
| }, | ||
| { | ||
| depth: 2, | ||
| label: 'aa', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '1', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '3', | ||
| }, | ||
| { | ||
| depth: 2, | ||
| label: 'bb', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '4', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '5', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '6', | ||
| }, | ||
| { | ||
| depth: 1, | ||
| label: 'bbb', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '7', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '8', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '9', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '10', | ||
| }, | ||
| { | ||
| depth: 2, | ||
| label: 'cc', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '11', | ||
| }, | ||
| { | ||
| depth: 3, | ||
| label: '12', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('filters labels at the first layer', () => { | ||
| const settings = MockGlobalSpec.settings({ legendMaxDepth: 1 }); | ||
| MockStore.addSpecs([settings, spec], store); | ||
|
|
||
| const labels = getLegendItemsLabels(store.getState()); | ||
| expect(labels).toEqual([ | ||
| { | ||
| depth: 1, | ||
| label: 'aaa', | ||
| }, | ||
| { | ||
| depth: 1, | ||
| label: 'bbb', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('filters labels at the second layer', () => { | ||
| const settings = MockGlobalSpec.settings({ legendMaxDepth: 2 }); | ||
| MockStore.addSpecs([settings, spec], store); | ||
|
|
||
| const labels = getLegendItemsLabels(store.getState()); | ||
| expect(labels).toEqual([ | ||
| { | ||
| depth: 1, | ||
| label: 'aaa', | ||
| }, | ||
| { | ||
| depth: 2, | ||
| label: 'aa', | ||
| }, | ||
| { | ||
| depth: 2, | ||
| label: 'bb', | ||
| }, | ||
| { | ||
| depth: 1, | ||
| label: 'bbb', | ||
| }, | ||
| { | ||
| depth: 2, | ||
| label: 'cc', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('filters all labels is depth is 0', () => { | ||
| const settings = MockGlobalSpec.settings({ legendMaxDepth: 0 }); | ||
| MockStore.addSpecs([settings, spec], store); | ||
|
|
||
| const labels = getLegendItemsLabels(store.getState()); | ||
| expect(labels).toEqual([]); | ||
| }); | ||
| it('filters all labels is depth is NaN', () => { | ||
| const settings = MockGlobalSpec.settings({ legendMaxDepth: NaN }); | ||
| MockStore.addSpecs([settings, spec], store); | ||
|
|
||
| const labels = getLegendItemsLabels(store.getState()); | ||
| expect(labels).toEqual([]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.