All files / owid-grapher/grapher/lineCharts LineChart.stories.tsx

100% Statements 132/132
100% Branches 6/6
100% Functions 5/5
100% Lines 132/132

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 154 155 156 157 158 159 160 161 162 163 164 1651x 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 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 * as React from "react"
import { LineChart } from "../lineCharts/LineChart"
import {
    SampleColumnSlugs,
    SynthesizeFruitTable,
    SynthesizeFruitTableWithNonPositives,
    SynthesizeGDPTable,
} from "../../coreTable/OwidTableSynthesizers"
import { ScaleType } from "../core/GrapherConstants"
import { Bounds } from "../../clientUtils/Bounds"
import { makeAnnotationsSlug } from "../../clientUtils/Util"
import { OwidTableSlugs } from "../../coreTable/OwidTableConstants"
 
export default {
    title: "LineChart",
    component: LineChart,
}
 
export const SingleColumnMultiCountry = (): JSX.Element => {
    const table = SynthesizeGDPTable()
    const bounds = new Bounds(0, 0, 500, 250)
    return (
        <div>
            <svg width={500} height={250}>
                <LineChart
                    bounds={bounds}
                    manager={{
                        table,
                        yColumnSlugs: [SampleColumnSlugs.GDP],
                        selection: table.availableEntityNames,
                    }}
                />
            </svg>
            <div>With missing data:</div>
            <svg width={500} height={250}>
                <LineChart
                    bounds={bounds}
                    manager={{
                        table: table.dropRandomRows(50),
                        selection: table.availableEntityNames,
                        yColumnSlugs: [SampleColumnSlugs.GDP],
                    }}
                />
            </svg>
        </div>
    )
}
 
export const WithLogScaleAndNegativeAndZeroValues = (): JSX.Element => {
    const table = SynthesizeFruitTableWithNonPositives({
        entityCount: 2,
        timeRange: [1900, 2000],
    })
    const bounds = new Bounds(0, 0, 500, 250)
    const bounds2 = new Bounds(0, 270, 500, 250)
    return (
        <svg width={500} height={550}>
            <LineChart
                bounds={bounds}
                manager={{
                    table,
                    selection: table.availableEntityNames,
                    yColumnSlugs: [SampleColumnSlugs.Fruit],
                }}
            />
            <LineChart
                bounds={bounds2}
                manager={{
                    table,
                    selection: table.availableEntityNames,
                    yColumnSlugs: [SampleColumnSlugs.Fruit],
                    yAxisConfig: { scaleType: ScaleType.log },
                }}
            />
        </svg>
    )
}
 
export const WithoutCirclesOnPoints = (): JSX.Element => {
    const table = SynthesizeGDPTable({
        entityCount: 6,
        timeRange: [1900, 2000],
    })
    return (
        <div>
            <svg width={600} height={600}>
                <LineChart
                    manager={{
                        table,
                        yColumnSlugs: [SampleColumnSlugs.GDP],
                        selection: table.availableEntityNames,
                    }}
                />
            </svg>
        </div>
    )
}
 
export const WithAnnotations = (): JSX.Element => {
    let table = SynthesizeGDPTable({
        entityCount: 6,
        timeRange: [1900, 2000],
    })
    // todo: eventually we should create a better API for annotations
    table = table.appendColumns([
        {
            slug: makeAnnotationsSlug(SampleColumnSlugs.GDP),
            values: table
                .get(OwidTableSlugs.entityName)
                .values.map((name): string => `${name} is a country`),
        },
    ])
    return (
        <div>
            <svg width={600} height={600}>
                <LineChart
                    manager={{
                        table,
                        yColumnSlugs: [SampleColumnSlugs.GDP],
                        selection: table.availableEntityNames,
                    }}
                />
            </svg>
        </div>
    )
}
 
export const MultiColumnSingleCountry = (): JSX.Element => {
    const table = SynthesizeGDPTable()
    const bounds = new Bounds(0, 0, 500, 250)
    return (
        <div>
            <svg width={500} height={250}>
                <LineChart
                    bounds={bounds}
                    manager={{ table, selection: table.sampleEntityName(1) }}
                />
            </svg>
            <div>With missing data:</div>
            <svg width={500} height={250}>
                <LineChart
                    bounds={bounds}
                    manager={{
                        table: table.dropRandomRows(100),
                        selection: table.sampleEntityName(1),
                    }}
                />
            </svg>
        </div>
    )
}
 
export const MultiColumnMultiCountry = (): JSX.Element => {
    const table = SynthesizeFruitTable({ entityCount: 5 })
    const bounds = new Bounds(0, 0, 500, 250)
    return (
        <svg width={500} height={250}>
            <LineChart
                bounds={bounds}
                manager={{ table, selection: table.availableEntityNames }}
            />
        </svg>
    )
}