UNPKG

terriajs

Version:

Geospatial data visualization platform.

67 lines 2.46 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, override } from "mobx"; import FunctionParameter from "./FunctionParameter"; export default class NumberParameter extends FunctionParameter { static type = "number"; type = "number"; minimum; maximum; defaultValue; get rangeDescription() { if (this.minimum !== undefined && this.maximum !== undefined) { return `: must be between ${this.minimum} to ${this.maximum}`; } else if (this.minimum !== undefined) { return `: at least ${this.minimum}`; } else if (this.maximum !== undefined) { return `: at most ${this.maximum}`; } else { return ""; } } get value() { return super.value ?? this.defaultValue; } get isValid() { return super.value === undefined ? this.isValidRange : this.isValidRange && super.isValid; } get isValidRange() { let value = this.value !== undefined ? this.value : this.defaultValue; if (typeof value === "string") { value = parseFloat(value); } if (this.minimum !== undefined && value < this.minimum) { return false; } if (this.maximum !== undefined && value > this.maximum) { return false; } return true; } constructor(catalogFunction, options) { super(catalogFunction, options); makeObservable(this); this.minimum = options.minimum; this.maximum = options.maximum; this.defaultValue = options.defaultValue; } } __decorate([ computed ], NumberParameter.prototype, "rangeDescription", null); __decorate([ override ], NumberParameter.prototype, "value", null); __decorate([ override ], NumberParameter.prototype, "isValid", null); //# sourceMappingURL=NumberParameter.js.map