-
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.
fix: clip bar highlighter edges (#447)
- Loading branch information
Showing
5 changed files
with
48 additions
and
222 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
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 |
---|---|---|
@@ -1,227 +1,38 @@ | ||
import React, { Fragment } from 'react'; | ||
import React from 'react'; | ||
import { | ||
Axis, | ||
Chart, | ||
getAxisId, | ||
getSpecId, | ||
Position, | ||
ScaleType, | ||
Settings, | ||
LineAnnotation, | ||
getAnnotationId, | ||
AnnotationDomainTypes, | ||
RectAnnotation, | ||
Rotation, | ||
HistogramBarSeries, | ||
DARK_THEME, | ||
Settings, | ||
} from '../src'; | ||
import { KIBANA_METRICS } from '../src/utils/data_samples/test_dataset_kibana'; | ||
import { LoremIpsum } from 'lorem-ipsum'; | ||
const lorem = new LoremIpsum({ | ||
sentencesPerParagraph: { | ||
max: 8, | ||
min: 4, | ||
}, | ||
wordsPerSentence: { | ||
max: 16, | ||
min: 4, | ||
}, | ||
}); | ||
interface State { | ||
showChart1: boolean; | ||
rotation: number; | ||
vAxis: number; | ||
hAxis: number; | ||
} | ||
const ROTATIONS: Rotation[] = [0, 90, -90, 180]; | ||
const RECT_ANNOTATION_TEXT = lorem.generateSentences(3); | ||
export class Playground extends React.Component<{}, State> { | ||
state = { | ||
showChart1: true, | ||
rotation: 0, | ||
vAxis: 0, | ||
hAxis: 0, | ||
}; | ||
rotateChart = (evt: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { | ||
const sense = evt.metaKey ? -1 : 1; | ||
|
||
this.setState((prevState) => { | ||
const val = prevState.rotation + sense < 0 ? 4 + sense : prevState.rotation + sense; | ||
return { | ||
rotation: val % 4, | ||
}; | ||
}); | ||
}; | ||
rotateVerticalAxis = () => { | ||
this.setState((prevState) => { | ||
return { | ||
vAxis: (prevState.vAxis + 1) % 2, | ||
}; | ||
}); | ||
}; | ||
rotateHorizontalAxis = () => { | ||
this.setState((prevState) => { | ||
return { | ||
hAxis: (prevState.hAxis + 1) % 2, | ||
}; | ||
}); | ||
}; | ||
removeChart = () => { | ||
this.setState((prevState) => { | ||
return { | ||
showChart1: !prevState.showChart1, | ||
}; | ||
}); | ||
}; | ||
export class Playground extends React.Component { | ||
render() { | ||
const data = KIBANA_METRICS.metrics.kibana_os_load[0].data.slice(0, 30); | ||
const data = KIBANA_METRICS.metrics.kibana_os_load[0].data.slice(0, 5); | ||
return ( | ||
this.state.showChart1 && ( | ||
<Fragment> | ||
<div id="controls"> | ||
<button onClick={this.removeChart}>remove chart</button> | ||
<button onClick={this.rotateChart}>rotateChart {ROTATIONS[this.state.rotation]}</button> | ||
<button onClick={this.rotateVerticalAxis}> | ||
Axis to {[Position.Left, Position.Right][this.state.vAxis]} | ||
</button> | ||
<button onClick={this.rotateHorizontalAxis}> | ||
Axis to {[Position.Bottom, Position.Top][this.state.hAxis]} | ||
</button> | ||
</div> | ||
<div className="chart"> | ||
<Chart> | ||
<Settings rotation={ROTATIONS[this.state.rotation]} /> | ||
<Axis id={getAxisId('x')} position={[Position.Bottom, Position.Top][this.state.hAxis]} /> | ||
<Axis id={getAxisId('y')} position={[Position.Left, Position.Right][this.state.vAxis]} /> | ||
|
||
<HistogramBarSeries | ||
id={getSpecId('series bars chart')} | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
data={data} | ||
yScaleToDataExtent={true} | ||
/> | ||
<RectAnnotation | ||
annotationId={getAnnotationId('annrec')} | ||
style={{ | ||
fill: 'red', | ||
stroke: 'red', | ||
opacity: 0.3, | ||
}} | ||
dataValues={[ | ||
{ | ||
coordinates: { | ||
x0: data[0][0], | ||
x1: data[10][0], | ||
y0: 14, | ||
}, | ||
details: RECT_ANNOTATION_TEXT, | ||
}, | ||
]} | ||
/> | ||
</Chart> | ||
|
||
<Chart> | ||
<Settings rotation={ROTATIONS[this.state.rotation]} /> | ||
<Axis id={getAxisId('x')} position={[Position.Bottom, Position.Top][this.state.hAxis]} /> | ||
<Axis id={getAxisId('y')} position={[Position.Left, Position.Right][this.state.vAxis]} /> | ||
<div className="chart"> | ||
<Chart> | ||
<Settings theme={DARK_THEME} rotation={180} /> | ||
<Axis id={getAxisId('x')} position={Position.Bottom} /> | ||
<Axis id={getAxisId('y')} position={Position.Left} /> | ||
|
||
<HistogramBarSeries | ||
id={getSpecId('series bars chart')} | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
data={data} | ||
yScaleToDataExtent={true} | ||
/> | ||
{/* <BarSeries | ||
id={getSpecId('series bars char2')} | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
stackAccessors={[0]} | ||
data={KIBANA_METRICS.metrics.kibana_os_load[1].data} | ||
yScaleToDataExtent={true} | ||
/> | ||
<BarSeries | ||
id={getSpecId('series bars char3')} | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
stackAccessors={[0]} | ||
data={KIBANA_METRICS.metrics.kibana_os_load[1].data} | ||
yScaleToDataExtent={true} | ||
/> */} | ||
<RectAnnotation | ||
annotationId={getAnnotationId('annrec')} | ||
style={{ | ||
fill: 'red', | ||
stroke: 'red', | ||
opacity: 0.3, | ||
}} | ||
dataValues={[ | ||
{ | ||
coordinates: { | ||
x0: data[0][0], | ||
x1: data[10][0], | ||
y0: 14, | ||
}, | ||
details: RECT_ANNOTATION_TEXT, | ||
}, | ||
]} | ||
/> | ||
<LineAnnotation | ||
annotationId={getAnnotationId('annline')} | ||
domainType={AnnotationDomainTypes.XDomain} | ||
dataValues={[ | ||
// { | ||
// dataValue: data2[1].x, | ||
// details: 'LINE ANNOTATION long title', | ||
// }, | ||
// { | ||
// dataValue: data2[data2.length - 1].x, | ||
// details: 'LINE ANNOTATION', | ||
// }, | ||
{ | ||
dataValue: data[10][0], | ||
details: 'X DOMAIN ANNOTATION', | ||
}, | ||
]} | ||
hideLinesTooltips={false} | ||
marker={<div style={{ width: 40, height: 20, background: 'blue', lineHeight: '20px' }}>X ANN</div>} | ||
/> | ||
<LineAnnotation | ||
annotationId={getAnnotationId('yannline')} | ||
domainType={AnnotationDomainTypes.YDomain} | ||
dataValues={[ | ||
// { | ||
// dataValue: 7, | ||
// details: 'LINE ANNOTATION long title', | ||
// }, | ||
// { | ||
// dataValue: 6, | ||
// details: 'LINE ANNOTATION', | ||
// }, | ||
// { | ||
// dataValue: 7.6, | ||
// details: 'LINE ANNOTATION long title', | ||
// }, | ||
{ | ||
dataValue: 14, | ||
details: 'Y Annotation', | ||
}, | ||
]} | ||
hideLinesTooltips={false} | ||
// marker={<div style={{ width: 40, height: 20, background: 'red', lineHeight: '20px' }}>Y ANN</div>} | ||
/> | ||
</Chart> | ||
</div> | ||
</Fragment> | ||
) | ||
<HistogramBarSeries | ||
id={getSpecId('series bars chart')} | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
data={data} | ||
yScaleToDataExtent={true} | ||
/> | ||
</Chart> | ||
</div> | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2029,7 +2029,7 @@ | |
lodash "^4.17.4" | ||
read-pkg-up "^6.0.0" | ||
|
||
"@storybook/addon-actions@^5.1.9": | ||
"@storybook/[email protected]": | ||
version "5.1.9" | ||
resolved "https://registry.yarnpkg.com/@storybook/addon-actions/-/addon-actions-5.1.9.tgz#a515b62b109cb886ccd75ef2f5b12f8c27b43dd3" | ||
integrity sha512-h/csHPotBESyEUYlML3yyF2jUlDChB+u3TUNC3Ztzh/x7HzLqy88SL0INSIdY0dCBGx4TK5Gh+rMI7z28Hfdyw== | ||
|
@@ -2049,7 +2049,7 @@ | |
react-inspector "^3.0.2" | ||
uuid "^3.3.2" | ||
|
||
"@storybook/addon-info@^5.1.9": | ||
"@storybook/[email protected]": | ||
version "5.1.9" | ||
resolved "https://registry.yarnpkg.com/@storybook/addon-info/-/addon-info-5.1.9.tgz#324066b02c7b76bd459d44ad3e6fe5640b7a8781" | ||
integrity sha512-KWGhW8kv/VUj4OnWyOmZx/Kq7CzSLGMIXFI6UQY9f6j6QiyShSaOKXgbNIhynjiYHq0hEnfbgUvws2DC9dDFuw== | ||
|
@@ -2070,7 +2070,7 @@ | |
react-lifecycles-compat "^3.0.4" | ||
util-deprecate "^1.0.2" | ||
|
||
"@storybook/addon-knobs@^5.1.9": | ||
"@storybook/[email protected]": | ||
version "5.1.9" | ||
resolved "https://registry.yarnpkg.com/@storybook/addon-knobs/-/addon-knobs-5.1.9.tgz#74db07fd644b41e63274f8754fbfb18f43d4cf01" | ||
integrity sha512-7/bICMYtR9CaTqfZX1kT2pBOTLZo3HxeslyQKWWsWlNElV33Ym2d0PPL5eS36eFxG/ZOp6lQWIFhunNnlmP5xg== | ||
|
@@ -2284,7 +2284,7 @@ | |
pretty-hrtime "^1.0.3" | ||
regenerator-runtime "^0.12.1" | ||
|
||
"@storybook/react@^5.1.9": | ||
"@storybook/[email protected]": | ||
version "5.1.9" | ||
resolved "https://registry.yarnpkg.com/@storybook/react/-/react-5.1.9.tgz#4052f4b88e91d5a823bb9cbb61104c530fcfb1a1" | ||
integrity sha512-Byykpsttf6p2jv3LvqFtntEYfbUZSNTts0TjcZHNsHoUGmT7/M1PyqTeB7JUcYUNwSgdACY8FbowCrwZwDJDWQ== | ||
|