@teaui/core
Version:
A high-level terminal UI library for Node
41 lines • 1.05 kB
JavaScript
import { View } from '../../View.js';
/**
* Base class for chart types. A Chart is a View that knows how to compute
* its data ranges and render into a provided layout area.
*/
export class Chart extends View {
#data = [];
#style;
constructor(data, props = {}) {
const { style, ...viewProps } = props;
super(viewProps);
this.#data = data;
this.#style = style;
}
get data() {
return this.#data;
}
set data(value) {
this.#data = value;
this.invalidateRender();
}
get chartStyle() {
return this.#style;
}
naturalSize(available) {
return available;
}
render(viewport) {
if (viewport.isEmpty)
return;
const xRange = this.getXRange();
const yRange = this.getYRange();
this.renderChart(viewport, {
width: viewport.contentSize.width,
height: viewport.contentSize.height,
xRange,
yRange,
});
}
}
//# sourceMappingURL=Chart.js.map