All files / owid-grapher/grapher/stackedCharts StackedAreaChart.stories.tsx

100% Statements 93/93
100% Branches 6/6
100% Functions 6/6
100% Lines 93/93

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1541x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                                                                                          
import { ChartManager } from "../chart/ChartManager"
import {
    SampleColumnSlugs,
    SynthesizeFruitTable,
    SynthesizeGDPTable,
} from "../../coreTable/OwidTableSynthesizers"
import * as React from "react"
import { StackedAreaChart } from "./StackedAreaChart"
 
export default {
    title: "StackedAreaChart",
    component: StackedAreaChart,
}
 
const seed = Date.now()
const table = SynthesizeGDPTable(
    {
        entityCount: 10,
        timeRange: [1950, 2010],
    },
    seed
)
const entitiesChart: ChartManager = {
    table,
    selection: table.sampleEntityName(5),
    yColumnSlugs: [SampleColumnSlugs.GDP],
}
 
export const EntitiesAsSeriesRelative = (): JSX.Element => (
    <svg width={600} height={600}>
        <StackedAreaChart
            manager={{ ...entitiesChart, isRelativeMode: true }}
        />
    </svg>
)
 
export const EntitiesAsSeries = (): JSX.Element => (
    <svg width={600} height={600}>
        <StackedAreaChart
            manager={{ ...entitiesChart, isRelativeMode: false }}
        />
    </svg>
)
 
export const EntitiesAsSeriesWithMissingRowsAndInterpolation =
    (): JSX.Element => (
        <svg width={600} height={600}>
            <StackedAreaChart
                manager={{
                    ...entitiesChart,
                    table: table.dropRandomRows(30, seed),
                }}
            />
        </svg>
    )
 
export const EntitiesAsSeriesWithMissingRowsNoInterpolation =
    (): JSX.Element => (
        <svg width={600} height={600}>
            <StackedAreaChart
                disableLinearInterpolation={true}
                manager={{
                    ...entitiesChart,
                    table: table.dropRandomRows(30, seed),
                }}
            />
        </svg>
    )
 
export const EntitiesAsSeriesWithMissingRowsAndInterpolationRelative =
    (): JSX.Element => (
        <svg width={600} height={600}>
            <StackedAreaChart
                manager={{
                    ...entitiesChart,
                    table: table.dropRandomRows(30, seed),
                    isRelativeMode: true,
                }}
            />
        </svg>
    )
 
export const EntitiesAsSeriesWithMissingRowsNoInterpolationRelative =
    (): JSX.Element => (
        <svg width={600} height={600}>
            <StackedAreaChart
                disableLinearInterpolation={true}
                manager={{
                    ...entitiesChart,
                    table: table.dropRandomRows(30, seed),
                    isRelativeMode: true,
                }}
            />
        </svg>
    )
 
const colTable = SynthesizeFruitTable()
const columnsChart: ChartManager = {
    table: colTable,
    selection: colTable.sampleEntityName(1),
}
 
export const ColumnsAsSeries = (): JSX.Element => (
    <svg width={600} height={600}>
        <StackedAreaChart manager={columnsChart} />
    </svg>
)
 
export const ColumnsAsSeriesRelative = (): JSX.Element => (
    <svg width={600} height={600}>
        <StackedAreaChart manager={{ ...columnsChart, isRelativeMode: true }} />
    </svg>
)
 
export const ColumnsAsSeriesWithMissingCells = (): JSX.Element => {
    const table = SynthesizeFruitTable().replaceRandomCells(200, [
        SampleColumnSlugs.Fruit,
    ])
    return (
        <svg width={600} height={600}>
            <StackedAreaChart
                manager={{
                    selection: table.sampleEntityName(1),
                    table,
                }}
            />
        </svg>
    )
}
 
export const ColumnsAsSeriesWithMissingRowsAndInterpolationRelative =
    (): JSX.Element => {
        let table = SynthesizeFruitTable().dropRandomRows(30, seed)
        const firstCol = table.columnsAsArray[0]
        const junkFoodColumn = {
            ...firstCol.def,
            slug: "junkFood",
            name: "JunkFood",
            values: firstCol.values.slice().reverse(),
        }
        table = table.appendColumns([junkFoodColumn])
        return (
            <svg width={600} height={600}>
                <StackedAreaChart
                    manager={{
                        selection: table.sampleEntityName(1),
                        table,
                        isRelativeMode: true,
                    }}
                />
            </svg>
        )
    }