-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: merge series domain with the domain of another group (#912)
This commit will fix a regression that prevents the correct use of `useDefaultGroupDomain`. It also includes a small feature that allows the consumer to specify a `groupId` on the same prop to allow merging the series domain with the domain of a different `groupId`. Co-authored-by: nickofthyme <nick.ryan.partridge@gmail.com>
- Loading branch information
1 parent
642abc0
commit 325b013
Showing
15 changed files
with
299 additions
and
51 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
+17.5 KB
...all-stories-bar-chart-dual-axis-same-y-domain-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
+9.95 KB
...bar-chart-specify-domain-from-different-group-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
+11.8 KB
...or-all-stories-bar-chart-stacked-only-grouped-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
+16 KB
...ts-bar-series-stories-different-group-id-render-different-axis-scale-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
+13.6 KB
...ferent-group-id-render-the-same-domain-with-use-default-group-domain-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
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,148 @@ | ||
/* | ||
* 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 { Axis, BarSeries, Settings, Chart, Position, ScaleType } from '../../src'; | ||
import { SB_KNOBS_PANEL } from '../utils/storybook'; | ||
|
||
export const Example = () => { | ||
const data1 = [ | ||
[1, 2], | ||
[2, 2], | ||
[3, 3], | ||
[4, 5], | ||
]; | ||
const data2 = [ | ||
[1, 1], | ||
[2, 2], | ||
[3, 3], | ||
[4, 4], | ||
]; | ||
const data3 = [ | ||
[1, 6], | ||
[2, 6], | ||
[3, 3], | ||
[4, 2], | ||
]; | ||
const data4 = [ | ||
[1, 2], | ||
[2, 6], | ||
[3, 2], | ||
[4, 9], | ||
]; | ||
const data5 = [ | ||
[1, 1], | ||
[2, 7], | ||
[3, 5], | ||
[4, 6], | ||
]; | ||
const useDifferentGroup = boolean('Apply a different groupId to some series', false); | ||
const useDefaultDomain = boolean('Use the same data domain for each group', false); | ||
|
||
return ( | ||
<Chart renderer="canvas" className="story-chart"> | ||
<Settings /> | ||
<Axis id="bottom" position={Position.Bottom} /> | ||
<Axis | ||
id="left y" | ||
title="Default groupId" | ||
position={Position.Left} | ||
tickFormat={(d: any) => Number(d).toFixed(2)} | ||
/> | ||
<Axis | ||
id="right y" | ||
groupId={useDifferentGroup && !useDefaultDomain ? 'otherGroupId' : undefined} | ||
title={useDifferentGroup ? 'Other groupId' : 'Default groupId'} | ||
position={Position.Right} | ||
tickFormat={(d: any) => Number(d).toFixed(2)} | ||
/> | ||
<BarSeries | ||
id="stacked bar 1" | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
stackAccessors={[0]} | ||
data={data1} | ||
/> | ||
<BarSeries | ||
id="stacked bar 2" | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
stackAccessors={[0]} | ||
data={data2} | ||
/> | ||
|
||
<BarSeries | ||
id="stacked bar A" | ||
groupId={useDifferentGroup ? 'otherGroupId' : undefined} | ||
useDefaultGroupDomain={useDefaultDomain} | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
stackAccessors={[0]} | ||
data={data4} | ||
/> | ||
<BarSeries | ||
id="stacked bar B" | ||
groupId={useDifferentGroup ? 'otherGroupId' : undefined} | ||
useDefaultGroupDomain={useDefaultDomain} | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
stackAccessors={[0]} | ||
data={data5} | ||
/> | ||
<BarSeries | ||
id="non stacked bar" | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
data={data3} | ||
/> | ||
</Chart> | ||
); | ||
}; | ||
|
||
// storybook configuration | ||
Example.story = { | ||
parameters: { | ||
options: { selectedPanel: SB_KNOBS_PANEL }, | ||
info: { | ||
text: `You can group together series specifying a \`groupId\` prop on the series. | ||
In the case of barchart, series with the same \`groupId\` will be grouped and eventually stacked together. | ||
The data Y domain of each group, specified by \`groupId\`, is computed independently. This is reflected also on the rendering | ||
where the Y value position is scaled independently on the Y axis from the other groups. An axis with the same \`groupId\` | ||
will reflect that scale. | ||
Use \`useDefaultGroupDomain\` if the same domain is required on every series. If you sent a \`boolean\` value, it will use | ||
the group id applied by default on every series with no specific groupId. You can also pass a \`string\` to use a different \`groupId\` | ||
see next storybook example. | ||
`, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.