import { boolean , select } from '@storybook/addon-knobs' ; import React from 'react' ; import { Axis , BarSeries , Chart , LineSeries , niceTimeFormatByDay , Position , ScaleType , Settings , timeFormatter , TooltipType , } from '@elastic/charts' ; import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana' ; import { useBaseTheme } from '../../use_base_theme' ; import { getChartRotationKnob } from '../utils/knobs' ; export const Example = ( ) => { const hideBars = boolean ( 'hideBars' , false ) ; const formatter = timeFormatter ( niceTimeFormatByDay ( 1 ) ) ; const chartRotation = getChartRotationKnob ( ) ; const numberFormatter = ( d ) => Number ( d ) . toFixed ( 2 ) ; const tooltipType = select ( 'tooltipType' , { cross : TooltipType . Crosshairs , vertical : TooltipType . VerticalCursor , follow : TooltipType . Follow , none : TooltipType . None , } , TooltipType . Crosshairs ) ; const tooltipProps = { type : tooltipType , snap : boolean ( 'tooltip snap to grid' , true ) , } ; return ( < Chart > < Settings debug = { boolean ( 'debug' , false ) } tooltip = { tooltipProps } baseTheme = { useBaseTheme ( ) } rotation = { chartRotation } / > < Axis id = "bottom" position = { Position . Bottom } title = "Bottom axis" tickFormat = { [ 0 , 180 ] . includes ( chartRotation ) ? formatter : numberFormatter } / > < Axis id = "left2" title = "Left axis" domain = { { min : NaN , max : NaN , fit : hideBars , } } position = { Position . Left } tickFormat = { [ 0 , 180 ] . includes ( chartRotation ) ? numberFormatter : formatter } / > { ! hideBars && ( < > < BarSeries id = "data 1" xScaleType = { ScaleType . Time } yScaleType = { ScaleType . Linear } xAccessor = { 0 } yAccessors = { [ 1 ] } stackAccessors = { [ 0 ] } data = { KIBANA_METRICS . metrics . kibana_os_load [ 0 ] . data . slice ( 0 , 20 ) } / > < BarSeries id = "data 2" xScaleType = { ScaleType . Time } yScaleType = { ScaleType . Linear } xAccessor = { 0 } yAccessors = { [ 1 ] } stackAccessors = { [ 0 ] } data = { KIBANA_METRICS . metrics . kibana_os_load [ 1 ] . data . slice ( 0 , 20 ) } / > < />)} < LineSeries id = "data 3" xScaleType = { ScaleType . Time } yScaleType = { ScaleType . Linear } xAccessor = { 0 } yAccessors = { [ 1 ] } data = { KIBANA_METRICS . metrics . kibana_os_load [ 2 ] . data . slice ( 0 , 20 ) } / > < /Chart>); } ;