ag-charts-community
Version:
Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue
148 lines • 5.18 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var secondaryAxisTicks_1 = require("../../util/secondaryAxisTicks");
var linearScale_1 = require("../../scale/linearScale");
var array_1 = require("../../util/array");
var value_1 = require("../../util/value");
var chartAxis_1 = require("../chartAxis");
// Instead of clamping the values outside of domain to the range,
// return NaNs to indicate invalid input.
function clamper(domain) {
var _a;
var a = domain[0];
var b = domain[domain.length - 1];
if (a > b) {
_a = __read([b, a], 2), a = _a[0], b = _a[1];
}
return function (x) { return x >= a && x <= b ? x : NaN; };
}
exports.clamper = clamper;
var NumberAxis = /** @class */ (function (_super) {
__extends(NumberAxis, _super);
function NumberAxis() {
var _this = _super.call(this, new linearScale_1.LinearScale()) || this;
_this._nice = true;
_this._min = NaN;
_this._max = NaN;
_this.scale.clamper = clamper;
return _this;
}
Object.defineProperty(NumberAxis.prototype, "nice", {
get: function () {
return this._nice;
},
set: function (value) {
if (this._nice !== value) {
this._nice = value;
if (value && this.scale.nice) {
this.scale.nice(this.tick.count);
}
}
},
enumerable: true,
configurable: true
});
NumberAxis.prototype.setDomain = function (domain, primaryTickCount) {
var _a = this, scale = _a.scale, min = _a.min, max = _a.max;
if (domain.length > 2) {
domain = array_1.extent(domain, value_1.isContinuous, Number) || [0, 1];
}
domain = [
isNaN(min) ? domain[0] : min,
isNaN(max) ? domain[1] : max
];
if (primaryTickCount) {
// when `primaryTickCount` is supplied the current axis is a secondary axis which needs to be aligned to
// the primary by constraining the tick count to the primary axis tick count
var _b = __read(secondaryAxisTicks_1.calculateNiceSecondaryAxis(domain, primaryTickCount), 2), d = _b[0], ticks = _b[1];
scale.domain = d;
this.ticks = ticks;
return;
}
else {
scale.domain = domain;
this.onLabelFormatChange(this.label.format); // not sure why this is required?
this.scale.clamp = true;
if (this.nice && this.scale.nice) {
this.scale.nice(this.tick.count);
}
}
};
Object.defineProperty(NumberAxis.prototype, "domain", {
get: function () {
return this.scale.domain;
},
set: function (domain) {
this.setDomain(domain);
},
enumerable: true,
configurable: true
});
Object.defineProperty(NumberAxis.prototype, "min", {
get: function () {
return this._min;
},
set: function (value) {
if (this._min !== value) {
this._min = value;
if (!isNaN(value)) {
this.scale.domain = [value, this.scale.domain[1]];
}
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(NumberAxis.prototype, "max", {
get: function () {
return this._max;
},
set: function (value) {
if (this._max !== value) {
this._max = value;
if (!isNaN(value)) {
this.scale.domain = [this.scale.domain[0], value];
}
}
},
enumerable: true,
configurable: true
});
NumberAxis.prototype.formatDatum = function (datum) {
return datum.toFixed(2);
};
NumberAxis.className = 'NumberAxis';
NumberAxis.type = 'number';
return NumberAxis;
}(chartAxis_1.ChartAxis));
exports.NumberAxis = NumberAxis;
//# sourceMappingURL=numberAxis.js.map