-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
542ef18
commit 05d6885
Showing
9 changed files
with
146 additions
and
13 deletions.
There are no files selected for viewing
Binary file added
BIN
+1.84 KB
...ts-for-all-stories-bar-chart-tooltip-boundary-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
+17.9 KB
...ps-boundary-chart-should-contain-tooltip-inside-boundary-near-bottom-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
+18.6 KB
...ltips-boundary-chart-should-contain-tooltip-inside-boundary-near-top-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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, select } from '@storybook/addon-knobs'; | ||
import React, { useRef } from 'react'; | ||
|
||
import { Axis, BarSeries, Chart, Position, ScaleType, Settings, TooltipProps } from '../../src'; | ||
import { getRandomNumberGenerator, SeededDataGenerator } from '../../src/mocks/utils'; | ||
import { SB_KNOBS_PANEL } from '../utils/storybook'; | ||
|
||
const dg = new SeededDataGenerator(); | ||
const rng = getRandomNumberGenerator(); | ||
|
||
export const Example = () => { | ||
const showAxes = boolean('Show axes', false); | ||
const groups = number('Groups', 5, { min: 2, max: 20, step: 1 }); | ||
const data = dg.generateGroupedSeries(4, groups).map((d) => { | ||
return { | ||
...d, | ||
y1: rng(0, 20), | ||
y2: rng(0, 20), | ||
g1: `dog ${d.g}`, | ||
g2: `cat ${d.g}`, | ||
}; | ||
}); | ||
const red = useRef<HTMLDivElement | null>(null); | ||
const white = useRef<HTMLDivElement | null>(null); | ||
const blue = useRef<HTMLDivElement | null>(null); | ||
const boundaryMap: Record<string, TooltipProps['boundary'] | null> = { | ||
default: undefined, | ||
red: red.current, | ||
white: white.current, | ||
blue: blue.current, | ||
chart: 'chart', | ||
root: document.getElementById('story-root'), | ||
}; | ||
const boundarySting = select<string>( | ||
'Boundary Element', | ||
{ | ||
Default: 'default', | ||
'Root (blanchedalmond)': 'root', | ||
Red: 'red', | ||
White: 'white', | ||
Blue: 'blue', | ||
Chart: 'chart', | ||
}, | ||
'default', | ||
); | ||
const boundary = boundaryMap[boundarySting] ?? undefined; | ||
|
||
return ( | ||
<div ref={red} style={{ backgroundColor: 'red', padding: 30, height: '100%' }}> | ||
<div ref={white} style={{ backgroundColor: 'white', padding: 30, height: '100%' }}> | ||
<div ref={blue} style={{ backgroundColor: 'blue', padding: 30, height: '100%' }}> | ||
<Chart className="story-chart"> | ||
<Settings tooltip={{ boundary }} /> | ||
<Axis id="bottom" hide={!showAxes} position={Position.Bottom} title="Bottom axis" showOverlappingTicks /> | ||
<Axis | ||
id="left" | ||
hide={!showAxes} | ||
title="Left axis" | ||
position={Position.Left} | ||
tickFormat={(d: any) => Number(d).toFixed(2)} | ||
/> | ||
<BarSeries | ||
id="bars" | ||
xScaleType={ScaleType.Ordinal} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor="x" | ||
yAccessors={['y1', 'y2']} | ||
splitSeriesAccessors={['g1', 'g2']} | ||
data={data} | ||
/> | ||
</Chart> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
Example.story = { | ||
parameters: { | ||
options: { selectedPanel: SB_KNOBS_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
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