import { boolean , select } from '@storybook/addon-knobs' ; import React from 'react' ; import { AreaSeries , Axis , Chart , CurveType , Position , ScaleType , Settings } from '@elastic/charts' ; import { TSVB_DATASET } from '@elastic/charts/src/utils/data_samples/test_dataset_tsvb' ; import { useBaseTheme } from '../../use_base_theme' ; import { arrayKnobs } from '../utils/knobs' ; export const Example = ( ) => { const showLegendDisplayValue = boolean ( 'show display value in legend' , true ) ; const legendPosition = select ( 'legendPosition' , { right : Position . Right , bottom : Position . Bottom , left : Position . Left , top : Position . Top , } , Position . Right ) ; const tsvbSeries = TSVB_DATASET . series ; const namesArray = arrayKnobs ( 'series names (in sort order)' , [ 'jpg' , 'php' , 'png' , 'css' , 'gif' ] ) ; const seriesComponents = tsvbSeries . map ( ( series ) => { const nameIndex = namesArray . findIndex ( ( name ) => name === series . label ) ; const sortIndex = nameIndex > - 1 ? nameIndex : undefined ; return ( < AreaSeries key = { `${ series . id }-${ series . label }` } id = { `${ series . id }-${ series . label }` } name = { series . label } xScaleType = { ScaleType . Time } yScaleType = { ScaleType . Linear } xAccessor = { 0 } yAccessors = { [ 1 ] } data = { series . data } curve = { series . lines . steps ? CurveType . CURVE_STEP : CurveType . LINEAR } sortIndex = { sortIndex } / > ) ; } ) ; return ( < Chart > < Settings showLegend legendPosition = { legendPosition } showLegendExtra = { showLegendDisplayValue } baseTheme = { useBaseTheme ( ) } / > < Axis id = "bottom" position = { Position . Bottom } title = "Bottom axis" showOverlappingTicks / > < Axis id = "left2" title = "Left axis" position = { Position . Left } tickFormat = { ( d ) => Number ( d ) . toFixed ( 2 ) } /> { seriesComponents } < /Chart>); } ;