@rcsb/rcsb-charts
Version:
37 lines • 1.57 kB
JavaScript
import { ChartTools } from "./ChartTools";
export class HistogramChartDataProvider {
setData(chartData, config) {
this.config = config !== null && config !== void 0 ? config : {};
const data = ChartTools.normalizeData(ChartTools.labelsAsNumber(chartData));
const barData = this.transformData(data);
this.data = barData.sort((r, s) => (r.x - s.x));
}
getChartData() {
return { data: this.data };
}
xDomain() {
var _a, _b, _c, _d;
const dx = (((_a = this.config) === null || _a === void 0 ? void 0 : _a.histogramBinIncrement) ? ((_b = this.config) === null || _b === void 0 ? void 0 : _b.histogramBinIncrement) * 0.5 : 0);
return [
(_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.domainMinValue) !== null && _d !== void 0 ? _d : Math.floor(Math.min(...this.data.map(d => d.x))) - dx,
Math.ceil(Math.max(...this.data.map(d => d.x))) + dx
];
}
tickValues() {
var _a;
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.tickIncrement) {
const tickValues = [];
for (let i = this.config.tickIncrement.origin; i <= this.xDomain()[1]; i += this.config.tickIncrement.increment) {
tickValues.push(i);
}
return tickValues;
}
return undefined;
}
transformData(data) {
if (!data)
return [];
return data.map(d => ({ x: d.x, y: d.y }));
}
}
//# sourceMappingURL=HistogramChartDataProvider.js.map