-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add histogram small multiples example (#975)
- Loading branch information
1 parent
9569ccb
commit 89d4bdb
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+10 KB
...-stories-small-multiples-alpha-histogram-bars-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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, number } from '@storybook/addon-knobs'; | ||
import { NumberTypeKnobOptions } from '@storybook/addon-knobs/dist/components/types'; | ||
import React from 'react'; | ||
|
||
import { ScaleType, Position, Chart, Axis, GroupBy, SmallMultiples, Settings, BarSeries } from '../../src'; | ||
import { SB_SOURCE_PANEL } from '../utils/storybook'; | ||
|
||
const data = [ | ||
{ x: 30, split: 'Cloudy', y: 9 }, | ||
{ x: 45, split: 'Sunny', y: 8 }, | ||
{ x: 60, split: 'Rain', y: 5 }, | ||
{ x: 75, split: 'Sunny', y: 7 }, | ||
{ x: 90, split: 'Rain', y: 6 }, | ||
{ x: 105, split: 'Rain', y: 7 }, | ||
{ x: 120, split: 'Clear', y: 7 }, | ||
{ x: 135, split: 'Cloudy', y: 8 }, | ||
{ x: 150, split: 'Cloudy', y: 8 }, | ||
{ x: 165, split: 'Rain', y: 8 }, | ||
{ x: 180, split: 'Rain', y: 10 }, | ||
{ x: 195, split: 'Rain', y: 10 }, | ||
{ x: 210, split: 'Sunny', y: 9 }, | ||
{ x: 225, split: 'Rain', y: 10 }, | ||
{ x: 240, split: 'Clear', y: 12 }, | ||
{ x: 255, split: 'Cloudy', y: 9 }, | ||
{ x: 270, split: 'Clear', y: 12 }, | ||
{ x: 285, split: 'Cloudy', y: 5 }, | ||
{ x: 300, split: 'Rain', y: 7 }, | ||
{ x: 315, split: 'Sunny', y: 8 }, | ||
{ x: 330, split: 'Cloudy', y: 8 }, | ||
{ x: 345, split: 'Sunny', y: 8 }, | ||
{ x: 360, split: 'Sunny', y: 10 }, | ||
]; | ||
const numberOptions: NumberTypeKnobOptions = { | ||
min: 0, | ||
max: 1, | ||
step: 0.01, | ||
}; | ||
|
||
export const Example = () => { | ||
const enableHistogramMode = boolean('EnableHistogramMode', true); | ||
const barsPadding = number('barsPadding', 0, numberOptions); | ||
const histogramPadding = number('histogramPadding', 0, numberOptions); | ||
|
||
return ( | ||
<Chart className="story-chart"> | ||
<Settings theme={{ scales: { barsPadding, histogramPadding } }} /> | ||
<Axis id="x" position={Position.Bottom} /> | ||
<Axis id="y" title="Count" position={Position.Left} /> | ||
|
||
<GroupBy id="splitId" by={(_, datum) => datum.split} sort="dataIndex" /> | ||
<SmallMultiples splitHorizontally="splitId" /> | ||
|
||
<BarSeries | ||
id="bars" | ||
enableHistogramMode={enableHistogramMode} | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
data={data} | ||
/> | ||
</Chart> | ||
); | ||
}; | ||
Example.story = { | ||
parameters: { | ||
options: { selectedPanel: SB_SOURCE_PANEL }, | ||
}, | ||
}; |
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