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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // todo: remove
import { Grapher } from "../core/Grapher"
import { computed } from "mobx"
import { excludeUndefined, findIndex, sortBy } from "../../clientUtils/Util"
import { ChartDimension } from "./ChartDimension"
import { DimensionProperty } from "../../clientUtils/owidTypes"
export class DimensionSlot {
private grapher: Grapher
property: DimensionProperty
constructor(grapher: Grapher, property: DimensionProperty) {
this.grapher = grapher
this.property = property
}
@computed get name(): string {
const names = {
y: this.grapher.isDiscreteBar ? "X axis" : "Y axis",
x: "X axis",
size: "Size",
color: "Color",
filter: "Filter",
}
return (names as any)[this.property] || ""
}
@computed get allowMultiple(): boolean {
return (
this.property === DimensionProperty.y &&
this.grapher.supportsMultipleYColumns
)
}
@computed get isOptional(): boolean {
return this.allowMultiple
}
@computed get dimensions(): ChartDimension[] {
return this.grapher.dimensions.filter(
(d) => d.property === this.property
)
}
@computed get dimensionsOrderedAsInPersistedSelection(): ChartDimension[] {
const legacyConfig = this.grapher.legacyConfigAsAuthored
const variableIDsInSelectionOrder = excludeUndefined(
legacyConfig.selectedData?.map(
(item) => legacyConfig.dimensions?.[item.index]?.variableId
) ?? []
)
return sortBy(this.grapher.filledDimensions || [], (dim) =>
findIndex(
variableIDsInSelectionOrder,
(variableId) => dim.variableId === variableId
)
).filter((dim) => dim.property === this.property)
}
}
|