forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(partition): elimination of zero values (opensearch-project#658)
Ignore not only negative values but also zero values. fix opensearch-project#642
- Loading branch information
Showing
6 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
Binary file modified
BIN
+90 Bytes
(100%)
...or-all-stories-sunburst-some-zero-value-slice-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.
Binary file added
BIN
+99.6 KB
...ual-tests-for-all-stories-treemap-zero-values-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.
46 changes: 46 additions & 0 deletions
46
...s/osd-charts/src/chart_types/partition_chart/layout/viewmodel/hierarchy_of_arrays.test.ts
This file contains 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,46 @@ | ||
/* | ||
* 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 { getHierarchyOfArrays } from './hierarchy_of_arrays'; | ||
|
||
const rawFacts = [ | ||
{ sitc1: '7', exportVal: 0 }, | ||
{ sitc1: '3', exportVal: 3 }, | ||
{ sitc1: 'G', exportVal: 1 }, | ||
{ sitc1: '5', exportVal: -8 }, | ||
]; | ||
|
||
const valueAccessor = (d: any) => d.exportVal; | ||
|
||
const groupByRollupAccessors = [() => null, (d: any) => d.sitc1]; | ||
|
||
describe('Test', () => { | ||
test('getHierarchyOfArrays should omit zero and negative values', () => { | ||
const outerResult = getHierarchyOfArrays(rawFacts, valueAccessor, groupByRollupAccessors); | ||
expect(outerResult.length).toBe(1); | ||
|
||
const results = outerResult[0]; | ||
expect(results.length).toBe(2); | ||
expect(results[0]).toBeNull(); | ||
|
||
const result = results[1]; | ||
const expectedLength = rawFacts.filter((d: any) => valueAccessor(d) > 0).length; | ||
expect(expectedLength).toBe(2); | ||
expect(result.children.length).toBe(expectedLength); | ||
}); | ||
}); |
This file contains 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 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,59 @@ | ||
/* | ||
* 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 { Chart, Datum, Partition, PartitionLayout } from '../../src'; | ||
import { mocks } from '../../src/mocks/hierarchical/index'; | ||
import { config } from '../../src/chart_types/partition_chart/layout/config/config'; | ||
import { arrayToLookup, hueInterpolator } from '../../src/chart_types/partition_chart/layout/utils/calcs'; | ||
import { productDimension } from '../../src/mocks/hierarchical/dimension_codes'; | ||
import { palettes } from '../../src/mocks/hierarchical/palettes'; | ||
import React from 'react'; | ||
|
||
const productLookup = arrayToLookup((d: Datum) => d.sitc1, productDimension); | ||
|
||
// style calcs | ||
const interpolatorCET2s = hueInterpolator(palettes.CET2s.map(([r, g, b]) => [r, g, b, 0.7])); | ||
|
||
const defaultFillColor = (colorMaker: any) => (d: any, i: number, a: any[]) => colorMaker(i / (a.length + 1)); | ||
|
||
export const example = () => ( | ||
<Chart className="story-chart"> | ||
<Partition | ||
id="spec_1" | ||
data={mocks.pie.map((d: any, i: number) => (i ? d : { ...d, exportVal: 0 }))} | ||
valueAccessor={(d: Datum) => d.exportVal as number} | ||
valueFormatter={(d: number) => `$${config.fillLabel.valueFormatter(Math.round(d / 1000000000))}\xa0Bn`} | ||
layers={[ | ||
{ | ||
groupByRollup: (d: Datum) => d.sitc1, | ||
nodeLabel: (d: Datum) => productLookup[d].name, | ||
fillLabel: { | ||
textInvertible: true, | ||
valueFormatter: (d: number) => `${config.fillLabel.valueFormatter(Math.round(d / 1000000000))}\xa0Bn`, | ||
}, | ||
shape: { | ||
fillColor: defaultFillColor(interpolatorCET2s), | ||
}, | ||
}, | ||
]} | ||
config={{ | ||
partitionLayout: PartitionLayout.treemap, | ||
}} | ||
/> | ||
</Chart> | ||
); |
This file contains 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