storybook/stories/stylings/5_partial_custom_theme.story.tsx (45 lines of code) (raw):
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { color } from '@storybook/addon-knobs';
import React from 'react';
import type { PartialTheme } from '@elastic/charts';
import { Axis, BarSeries, Chart, LegendValue, Position, ScaleType, Settings } from '@elastic/charts';
import { SeededDataGenerator } from '@elastic/charts/src/mocks/utils';
import type { ChartsStory } from '../../types';
import { useBaseTheme } from '../../use_base_theme';
const dg = new SeededDataGenerator();
const data1 = dg.generateGroupedSeries(40, 4);
export const Example: ChartsStory = (_, { title, description }) => {
const customPartialTheme: PartialTheme = {
barSeriesStyle: {
rectBorder: {
stroke: color('BarBorderStroke', 'white'),
visible: true,
},
},
background: {
color: color('Change background container color', 'white'),
},
};
return (
<Chart title={title} description={description}>
<Settings
showLegend
legendValues={[LegendValue.CurrentAndLastValue]}
theme={customPartialTheme}
baseTheme={useBaseTheme()}
legendPosition={Position.Right}
/>
<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)} />
<Axis id="top" position={Position.Top} title="Top axis" showOverlappingTicks />
<Axis id="right" title="Right axis" position={Position.Right} tickFormat={(d) => Number(d).toFixed(2)} />
<BarSeries
id="bars"
xScaleType={ScaleType.Linear}
yScaleType={ScaleType.Linear}
xAccessor="x"
yAccessors={['y']}
splitSeriesAccessors={['g']}
stackAccessors={['x']}
data={data1}
/>
</Chart>
);
};
Example.parameters = {
background: { disable: true },
};