All files / owid-grapher/grapher/core Grapher.stories.tsx

95.73% Statements 157/164
100% Branches 13/13
86.67% Functions 13/15
95.73% Lines 157/164

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 165 166 167 168 169 170 171 172 1731x 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 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 { Grapher, GrapherProgrammaticInterface } from "./Grapher"
import {
    SampleColumnSlugs,
    SynthesizeGDPTable,
} from "../../coreTable/OwidTableSynthesizers"
import {
    ChartTypeName,
    FacetStrategy,
    GrapherTabOption,
} from "./GrapherConstants"
import { BlankOwidTable } from "../../coreTable/OwidTable"
import { action, observable } from "mobx"
import { observer } from "mobx-react"
import { ChartTypeSwitcher } from "../chart/ChartTypeSwitcher"
import { DimensionProperty } from "../../clientUtils/owidTypes"
 
export default {
    title: "Grapher",
    component: Grapher,
}
 
const table = SynthesizeGDPTable({ entityCount: 10 })
const basics: GrapherProgrammaticInterface = {
    table,
    selectedEntityNames: table.sampleEntityName(5),
    hasMapTab: true,
    yAxis: {
        canChangeScaleType: true,
    },
    xAxis: {
        canChangeScaleType: true,
    },
    dimensions: [
        {
            slug: SampleColumnSlugs.GDP,
            property: DimensionProperty.y,
            variableId: SampleColumnSlugs.GDP as any,
        },
        {
            slug: SampleColumnSlugs.Population,
            property: DimensionProperty.x,
            variableId: SampleColumnSlugs.Population as any,
        },
    ],
}
 
export const Line = (): JSX.Element => <Grapher {...basics} />
 
export const SlopeChart = (): JSX.Element => {
    const model = {
        type: ChartTypeName.SlopeChart,
        ...basics,
    }
    return <Grapher {...model} />
}
 
export const ScatterPlot = (): JSX.Element => {
    const model = {
        type: ChartTypeName.ScatterPlot,
        ...basics,
    }
    return <Grapher {...model} />
}
 
export const DiscreteBar = (): JSX.Element => {
    const model = {
        type: ChartTypeName.DiscreteBar,
        ...basics,
    }
    return <Grapher {...model} />
}
 
export const StackedBar = (): JSX.Element => {
    const model = {
        type: ChartTypeName.StackedBar,
        ...basics,
    }
    return <Grapher {...model} />
}
 
export const StackedArea = (): JSX.Element => {
    const model = {
        type: ChartTypeName.StackedArea,
        ...basics,
    }
    return <Grapher {...model} />
}
 
export const MapFirst = (): JSX.Element => {
    const model = {
        ...basics,
        tab: GrapherTabOption.map,
    }
    return <Grapher {...model} />
}
 
export const BlankGrapher = (): JSX.Element => {
    const model = {
        type: ChartTypeName.WorldMap,
        tab: GrapherTabOption.map,
        table: BlankOwidTable(),
        hasMapTab: true,
    }
    return <Grapher {...model} />
}
 
export const NoMap = (): JSX.Element => {
    const model = {
        ...basics,
        hasMapTab: false,
    }
    return <Grapher {...model} />
}
 
export const Faceting = (): JSX.Element => {
    const model = {
        type: ChartTypeName.StackedArea,
        facet: FacetStrategy.entity,
        ...basics,
    }
    return <Grapher {...model} />
}
 
export const WithAuthorTimeFilter = (): JSX.Element => {
    const model: GrapherProgrammaticInterface = {
        ...basics,
        timelineMinTime: 1993,
        timelineMaxTime: 1996,
    }
    return <Grapher {...model} />
}
 
@observer
class PerfGrapher extends React.Component {
    @action.bound loadBigTable(): void {
        this.table = SynthesizeGDPTable({
            entityCount: 200,
            timeRange: [1500, 2000],
        })
    }
 
    @observable.ref table = basics.table!
 
    @action.bound private changeChartType(type: ChartTypeName): void {
        this.chartTypeName = type
    }
 
    @observable chartTypeName = ChartTypeName.LineChart
 
    render(): JSX.Element {
        const key = Math.random() // I do this hack to force a rerender until can re-add the grapher model/grapher view that we used to have. @breck 10/29/2020
        return (
            <div>
                <div>
                    <button onClick={this.loadBigTable}>
                        Big Table for Perf
                    </button>
                    <ChartTypeSwitcher onChange={this.changeChartType} />
                </div>
                <Grapher
                    {...basics}
                    table={this.table}
                    type={this.chartTypeName}
                    key={key}
                />
            </div>
        )
    }
}
 
export const Perf = (): JSX.Element => <PerfGrapher />