import _ from 'lodash'; import React from 'react'; import { Meta, Story } from '@storybook/react'; import * as chartConstants from '../../constants/charts'; import * as formatters from '../../util/formatters'; import Resizer from '../Resizer/Resizer'; import BarChart, { IBarChartProps } from './BarChart'; import Legend from '../Legend/Legend'; export default { title: 'Visualizations/BarChart', component: BarChart, parameters: { docs: { description: { component: BarChart.peek.description, }, }, }, } as Meta; /* Basic */ export const Basic: Story = (args) => { const data = [ { x: '2015-01-01', y: 1 }, { x: '2015-01-02', y: 2 }, { x: '2015-01-03', y: 3 }, { x: '2015-01-04', y: 5 }, ]; const style = { paddingTop: '4rem', }; return (
); }; /* Basic Responsive */ export const BasicResponsive: Story = (args) => { const data = [ { x: '2015-01-01', y: 1 }, { x: '2015-01-02', y: 2 }, { x: '2015-01-03', y: 3 }, { x: '2015-01-04', y: 5 }, ]; const style = { paddingTop: '4rem', }; return (
{(width /*, height */) => ( )}
); }; BasicResponsive.storyName = 'BasicResponsive'; /* Grouped */ export const Grouped: Story = (args) => { /* eslint-disable comma-spacing */ const data = [ { x: 'Monday', apples: 10, pears: 20, peaches: 35, bananas: 15, oranges: 5, }, { x: 'Tuesday', apples: 20, pears: 5, peaches: 20, bananas: 25, oranges: 27, }, { x: 'Wednesday', apples: 5, pears: 15, peaches: 5, bananas: 20, oranges: 35, }, ]; const style = { paddingTop: '10rem', }; return (
); }; /* Grouped With Legend */ export const GroupedWithLegend: Story = (args) => { /* eslint-disable comma-spacing */ const data = [ { x: 'Monday', apples: 10, pears: 20, peaches: 35, bananas: 15, oranges: 5, }, { x: 'Tuesday', apples: 20, pears: 5, peaches: 20, bananas: 25, oranges: 27, }, { x: 'Wednesday', apples: 5, pears: 15, peaches: 5, bananas: 20, oranges: 35, }, ]; const yAxisFields = ['apples', 'pears', 'peaches', 'bananas', 'oranges']; const palette = chartConstants.PALETTE_7; const style = { paddingTop: '10rem', }; return (
{_.map(yAxisFields, (field, i) => ( {field} ))}
); }; GroupedWithLegend.storyName = 'GroupedWithLegend'; /* Limited Ticks */ export const LimitedTicks: Story = (args) => { const data = [ { x: '2015-01-01', y: 1 }, { x: '2015-01-02', y: 2 }, { x: '2015-01-03', y: 3 }, { x: '2015-01-04', y: 5 }, { x: '2015-01-05', y: 2 }, { x: '2015-01-06', y: 3 }, { x: '2015-01-07', y: 2 }, { x: '2015-01-08', y: 2 }, { x: '2015-01-09', y: 5 }, { x: '2015-01-10', y: 3 }, { x: '2015-01-11', y: 4 }, { x: '2015-01-12', y: 4 }, { x: '2015-01-13', y: 5 }, { x: '2015-01-14', y: 3 }, { x: '2015-01-15', y: 4 }, { x: '2015-01-16', y: 3 }, { x: '2015-01-17', y: 6 }, ]; const style = { paddingTop: '4rem', }; return (
); }; LimitedTicks.storyName = 'LimitedTicks'; /* All The Things */ export const AllTheThings: Story = (args) => { /* eslint-disable comma-spacing */ const data = [ { day: 'monday', apples: 2000, oranges: 3000 }, { day: 'tuesday', apples: 2000, oranges: 5000 }, { day: 'wednesday', apples: 3000, oranges: 2000 }, { day: 'thursday', apples: 5000, oranges: 6000 }, ]; const yFormatter = (d: any) => `${d / 1000}k`; const xFormatter = (d: any) => d.toUpperCase().slice(0, 3); const style = { paddingTop: '6rem', }; return (
); }; AllTheThings.storyName = 'AllTheThings'; /* Stacked */ export const Stacked: Story = (args) => { const data = [ { x: 'Monday', apples: 10, pears: 20, peaches: 35 }, { x: 'Tuesday', apples: 20, pears: 5, peaches: 20 }, { x: 'Wednesday', apples: 5, pears: 15, peaches: 5 }, ]; const style = { paddingTop: '7rem', }; return (
); }; /* Unformatted Tooltips */ export const UnformattedTooltips: Story = (args) => { const data = [ { x: '2015-01-01', y: 1200 }, { x: '2015-01-02', y: 900 }, { x: '2015-01-03', y: 1800 }, { x: '2015-01-04', y: 3000 }, ]; const style = { paddingTop: '4rem', }; return (
yValue} />
); }; UnformattedTooltips.storyName = 'UnformattedTooltips'; /* Formatted Tooltip Values */ export const FormattedTooltipValues: Story = (args) => { const data = [ { x: '2015-01-01', y: 1200 }, { x: '2015-01-02', y: 900 }, { x: '2015-01-03', y: 1800 }, { x: '2015-01-04', y: 3000 }, ]; const style = { paddingTop: '4rem', }; return (
); }; FormattedTooltipValues.storyName = 'FormattedTooltipValues'; /* Formatted Tooltips */ export const FormattedTooltips: Story = (args) => { const data = [ { x: '2015-01-01', y: 1200 }, { x: '2015-01-02', y: 900 }, { x: '2015-01-03', y: 1800 }, { x: '2015-01-04', y: 3000 }, ]; const style = { paddingTop: '4rem', }; return (
`x value = ${dataPoint.x} and y value = ${dataPoint.y}` } />
); }; FormattedTooltips.storyName = 'FormattedTooltips'; /* Empty */ export const Empty: Story = (args) => { return ; }; /* Empty With Custom Title And Body */ export const EmptyWithCustomTitleAndBody: Story = (args) => { const { EmptyStateWrapper, EmptyStateWrapper: { Title, Body }, } = BarChart; return ( Something went wrong. Echo park poutine esse tempor squid do. Lo-fi ramps XOXO chicharrones laboris, portland fugiat locavore. Fap four dollar toast keytar, cronut kogi fingerstache distillery microdosing everyday carry austin DIY dreamcatcher. Distillery flexitarian meditation laboris roof party. Cred raclette gastropub tilde PBR&B. Shoreditch poke adipisicing, reprehenderit lumbersexual succulents mustache officia franzen vinyl nostrud af. Hashtag bitters organic, before they sold out butcher cronut sapiente. ); }; EmptyWithCustomTitleAndBody.storyName = 'EmptyWithCustomTitleAndBody'; /* Many Bars */ export const ManyBars: Story = (args) => { const data = _.map(_.range(0, 70), (n) => ({ x: (new Date(0) as any) + n * 60 * 60 * 24, y: n, })); const style = { paddingTop: '5rem', }; return (
); }; ManyBars.storyName = 'ManyBars';