File: //usr/share/opensearch-dashboards/node_modules/@elastic/charts/dist/scales/scale_band.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScaleBand = void 0;
var d3_scale_1 = require("d3-scale");
var common_1 = require("../utils/common");
var constants_1 = require("./constants");
var ScaleBand = (function () {
function ScaleBand(domain, range, overrideBandwidth, barsPadding) {
if (barsPadding === void 0) { barsPadding = 0; }
this.type = constants_1.ScaleType.Ordinal;
this.d3Scale = d3_scale_1.scaleBand();
this.d3Scale.domain(domain);
this.d3Scale.range(range);
var safeBarPadding = 0;
if (typeof barsPadding === 'object') {
this.d3Scale.paddingInner(barsPadding.inner);
this.d3Scale.paddingOuter(barsPadding.outer);
this.barsPadding = barsPadding.inner;
}
else {
safeBarPadding = common_1.maxValueWithUpperLimit(barsPadding, 0, 1);
this.d3Scale.paddingInner(safeBarPadding);
this.barsPadding = safeBarPadding;
this.d3Scale.paddingOuter(safeBarPadding / 2);
}
this.outerPadding = this.d3Scale.paddingOuter();
this.innerPadding = this.d3Scale.paddingInner();
this.bandwidth = this.d3Scale.bandwidth() || 0;
this.originalBandwidth = this.d3Scale.bandwidth() || 0;
this.step = this.d3Scale.step();
this.domain = this.d3Scale.domain();
this.range = range.slice();
if (overrideBandwidth) {
this.bandwidth = overrideBandwidth * (1 - safeBarPadding);
}
this.bandwidthPadding = this.bandwidth;
this.isInverted = this.domain[0] > this.domain[1];
this.invertedScale = d3_scale_1.scaleQuantize().domain(range).range(this.domain);
this.minInterval = 0;
}
ScaleBand.prototype.getScaledValue = function (value) {
var scaleValue = this.d3Scale(common_1.stringifyNullsUndefined(value));
if (scaleValue === undefined || isNaN(scaleValue)) {
return null;
}
return scaleValue;
};
ScaleBand.prototype.scaleOrThrow = function (value) {
var scaleValue = this.scale(value);
if (scaleValue === null) {
throw new Error("Unable to scale value: " + scaleValue + ")");
}
return scaleValue;
};
ScaleBand.prototype.scale = function (value) {
return this.getScaledValue(value);
};
ScaleBand.prototype.pureScale = function (value) {
return this.getScaledValue(value);
};
ScaleBand.prototype.ticks = function () {
return this.domain;
};
ScaleBand.prototype.invert = function (value) {
return this.invertedScale(value);
};
ScaleBand.prototype.invertWithStep = function (value) {
return {
value: this.invertedScale(value),
withinBandwidth: true,
};
};
ScaleBand.prototype.isSingleValue = function () {
return this.domain.length < 2;
};
ScaleBand.prototype.isValueInDomain = function (value) {
return this.domain.includes(value);
};
return ScaleBand;
}());
exports.ScaleBand = ScaleBand;
//# sourceMappingURL=scale_band.js.map