-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
270 additions
and
13 deletions.
There are no files selected for viewing
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
Binary file added
BIN
+23.7 KB
...sts-for-all-stories-mosaic-alpha-other-slices-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
+50.8 KB
...ts-for-all-stories-mosaic-alpha-simple-mosaic-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.
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
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
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,111 @@ | ||
/* | ||
* 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 { boolean } from '@storybook/addon-knobs'; | ||
import React from 'react'; | ||
|
||
import { | ||
AdditiveNumber, | ||
ArrayEntry, | ||
Chart, | ||
Datum, | ||
Partition, | ||
PartitionLayout, | ||
Settings, | ||
ShapeTreeNode, | ||
} from '../../src'; | ||
import { config } from '../../src/chart_types/partition_chart/layout/config'; | ||
import { mocks } from '../../src/mocks/hierarchical'; | ||
import { keepDistinct } from '../../src/utils/common'; | ||
import { countryLookup, colorBrewerCategoricalPastel12B, regionLookup } from '../utils/utils'; | ||
|
||
const productLookup: Record<string, { label: string; position: number }> = { | ||
'3': { label: 'Firefox', position: 1 }, | ||
'5': { label: 'Edge (Chromium)', position: 4 }, | ||
'6': { label: 'Safari', position: 2 }, | ||
'7': { label: 'Chrome', position: 0 }, | ||
'8': { label: 'Brave', position: 3 }, | ||
}; | ||
|
||
const data = mocks.sunburst | ||
.map((d) => (d.dest === 'chn' ? { ...d, dest: 'zaf' } : d)) | ||
.filter( | ||
(d: any) => | ||
['eu', 'na', 'as', 'af'].includes(countryLookup[d.dest].continentCountry.slice(0, 2)) && | ||
['3', '5', '6', '7', '8'].includes(d.sitc1), | ||
); | ||
|
||
const productPalette = colorBrewerCategoricalPastel12B.slice(2); | ||
|
||
const productToColor = new Map( | ||
data | ||
.map((d) => d.sitc1) | ||
.filter(keepDistinct) | ||
.sort() | ||
.map((sitc1, i) => [sitc1, `rgba(${productPalette[i % productPalette.length].join(',')}, 0.7)`]), | ||
); | ||
|
||
export const Example = () => { | ||
return ( | ||
<Chart className="story-chart"> | ||
<Settings showLegend={boolean('Show legend', true)} showLegendExtra={boolean('Show legend values', true)} /> | ||
<Partition | ||
id="spec_1" | ||
data={data} | ||
valueAccessor={(d: Datum) => d.exportVal as AdditiveNumber} | ||
valueFormatter={(d: number) => `${config.fillLabel.valueFormatter(Math.round(d / 1000000000))}`} | ||
layers={[ | ||
{ | ||
groupByRollup: (d: Datum) => countryLookup[d.dest].continentCountry.slice(0, 2), | ||
nodeLabel: (name: any) => regionLookup[name].regionName, | ||
fillLabel: { | ||
fontWeight: 400, | ||
}, | ||
shape: { | ||
fillColor: () => 'white', | ||
}, | ||
}, | ||
{ | ||
groupByRollup: (d: Datum) => d.sitc1, | ||
nodeLabel: (d: any) => String(productLookup[d]?.label), | ||
shape: { | ||
fillColor: (d: ShapeTreeNode) => productToColor.get(d.dataName)!, | ||
}, | ||
sortPredicate: ([name1]: ArrayEntry, [name2]: ArrayEntry) => { | ||
const position1 = Number(productLookup[name1]?.position); | ||
const position2 = Number(productLookup[name2]?.position); | ||
return position2 - position1; | ||
}, | ||
fillLabel: { | ||
fontWeight: 200, | ||
minFontSize: 6, | ||
maxFontSize: 16, | ||
maximizeFontSize: true, | ||
fontFamily: 'Helvetica Neue', | ||
valueFormatter: () => '', | ||
}, | ||
}, | ||
]} | ||
config={{ | ||
partitionLayout: PartitionLayout.mosaic, | ||
}} | ||
/> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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 React from 'react'; | ||
|
||
import { | ||
AdditiveNumber, | ||
ArrayEntry, | ||
Chart, | ||
Datum, | ||
MODEL_KEY, | ||
Partition, | ||
PartitionLayout, | ||
ShapeTreeNode, | ||
} from '../../src'; | ||
import { config } from '../../src/chart_types/partition_chart/layout/config'; | ||
import { countryLookup } from '../utils/utils'; | ||
|
||
const categoricalColors = ['rgb(110,110,110)', 'rgb(123,123,123)', 'darkgrey', 'lightgrey']; | ||
|
||
const data = [ | ||
{ region: 'Americas', dest: 'usa', other: false, exportVal: 553359100104 }, | ||
{ region: 'Americas', dest: 'Other', other: true, exportVal: 753359100104 }, | ||
{ region: 'Asia', dest: 'chn', other: false, exportVal: 392617281424 }, | ||
{ region: 'Asia', dest: 'jpn', other: false, exportVal: 177490158520 }, | ||
{ region: 'Asia', dest: 'kor', other: false, exportVal: 177421375512 }, | ||
{ region: 'Asia', dest: 'Other', other: true, exportVal: 277421375512 }, | ||
{ region: 'Europe', dest: 'deu', other: false, exportVal: 253250650864 }, | ||
{ region: 'Europe', dest: 'smr', other: false, exportVal: 135443006088 }, | ||
{ region: 'Europe', dest: 'Other', other: true, exportVal: 205443006088 }, | ||
{ region: 'Africa', dest: 'Other', other: true, exportVal: 305443006088 }, | ||
]; | ||
|
||
export const Example = () => { | ||
return ( | ||
<Chart className="story-chart"> | ||
<Partition | ||
id="spec_1" | ||
data={data} | ||
valueAccessor={(d: Datum) => d.exportVal as AdditiveNumber} | ||
valueFormatter={(d: number) => `${config.fillLabel.valueFormatter(Math.round(d / 1000000000))}`} | ||
layers={[ | ||
{ | ||
groupByRollup: (d: Datum) => d.region, | ||
nodeLabel: (d) => String(d).toUpperCase(), | ||
fillLabel: { | ||
valueFormatter: () => ``, | ||
fontWeight: 600, | ||
}, | ||
shape: { | ||
fillColor: () => 'white', | ||
}, | ||
}, | ||
{ | ||
groupByRollup: (d: Datum) => d.dest, | ||
nodeLabel: (d: any) => countryLookup[d]?.name ?? d, | ||
sortPredicate: ([name1, node1]: ArrayEntry, [name2, node2]: ArrayEntry) => { | ||
if (name1 === 'Other' && name2 !== 'Other') return -1; | ||
if (name2 === 'Other' && name1 !== 'Other') return 1; | ||
|
||
// otherwise, use the increasing value order | ||
return node1.value - node2.value; | ||
}, | ||
fillLabel: { | ||
fontWeight: 100, | ||
maxFontSize: 16, | ||
valueFont: { | ||
fontFamily: 'Menlo', | ||
fontStyle: 'normal', | ||
fontWeight: 100, | ||
}, | ||
}, | ||
shape: { | ||
fillColor: (d: ShapeTreeNode) => categoricalColors.slice(0)[d[MODEL_KEY].sortIndex], | ||
}, | ||
}, | ||
]} | ||
config={{ | ||
partitionLayout: PartitionLayout.mosaic, | ||
}} | ||
/> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 { SB_SOURCE_PANEL } from '../utils/storybook'; | ||
|
||
export default { | ||
title: 'Mosaic (@alpha)', | ||
parameters: { | ||
options: { selectedPanel: SB_SOURCE_PANEL }, | ||
}, | ||
}; | ||
|
||
export { Example as simpleMosaic } from './10_mosaic_simple'; | ||
export { Example as otherSlices } from './20_mosaic_with_other'; |