UNPKG

terriajs

Version:

Geospatial data visualization platform.

104 lines 3.87 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { computed, makeObservable } from "mobx"; export default class TableStyleMap { tableModel; styleTraits; key; constructor(tableModel, styleTraits, key) { this.tableModel = tableModel; this.styleTraits = styleTraits; this.key = key; makeObservable(this); } /** Get traits for TableStyleMapSymbolTraits */ get commonTraits() { return this.styleTraits[this.key]; } /** Get all traits (this includes TableStyleMapTraits and specific SymbolTraits) */ get traits() { return this.styleTraits[this.key]; } /** Get all trait values for this TableStyleMapModel. * This is a JSON object */ get traitValues() { return this.styleTraits.traits[this.key].toJson(this.traits); } get column() { return this.traitValues.column ? this.tableModel.tableColumns.find((column) => column.name === this.traitValues.column) : undefined; } /** * */ get styleMap() { // If column type is `scalar` and binStyles if ((this.traitValues.mapType === "bin" || !this.traitValues.mapType) && this.traitValues.bin && this.traitValues.bin.length > 0) { const mapValueToStyle = (value) => { if (typeof value !== "number") { return this.traitValues.null; } const binStyles = this.traitValues.bin ?? []; let i; for (i = 0; i < binStyles.length - 1 && value > (binStyles[i].maxValue ?? Infinity); ++i) { continue; } return { ...this.traitValues.null, ...(this.traitValues.bin?.[i] ?? {}) }; }; return { type: "bin", mapRowIdToStyle: (rowId) => mapValueToStyle(this.column?.valuesForType[rowId]), mapValueToStyle }; } else if ((this.traitValues.mapType === "enum" || !this.traitValues.mapType) && this.traitValues.enum && this.traitValues.enum.length > 0) { const mapValueToStyle = (value) => { const style = this.traitValues.enum.find((enumStyle) => enumStyle.value !== null && enumStyle.value === value); return { ...this.traitValues.null, ...(style ?? {}) }; }; return { type: "enum", mapRowIdToStyle: (rowId) => mapValueToStyle(this.column?.values[rowId]), mapValueToStyle }; } // Return default settings return { type: "constant", style: this.traitValues.null }; } } __decorate([ computed ], TableStyleMap.prototype, "commonTraits", null); __decorate([ computed ], TableStyleMap.prototype, "traits", null); __decorate([ computed ], TableStyleMap.prototype, "traitValues", null); __decorate([ computed ], TableStyleMap.prototype, "column", null); __decorate([ computed ], TableStyleMap.prototype, "styleMap", null); export function isConstantStyleMap(map) { return map.type === "constant"; } //# sourceMappingURL=TableStyleMap.js.map