Hastic standalone https://hastic.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

import { AxisRange } from "@chartwerk/core/dist/types";
3 years ago
import { LinePod, LineTimeSerie } from "@chartwerk/line-pod";
3 years ago
export type TimeRange = { from: number, to: number };
export type UpdateDataCallback = (range: TimeRange) => Promise<LineTimeSerie[]>;
3 years ago
export class HasticPod extends LinePod {
private _udc: UpdateDataCallback;
constructor(el: HTMLElement, udc: UpdateDataCallback) {
super(el, undefined, {
3 years ago
renderLegend: false,
eventsCallbacks: {
3 years ago
zoomIn: range => { this._updateRange(range) },
zoomOut: ({x, y}) => { this._zoomOut({x, y}) },
panningEnd: range => { this._updateRange(range) }
}
3 years ago
});
this._udc = udc;
// TODO: move to params
const to = Math.floor(Date.now() / 1000);
const from = to - 5000; // -5000 seconds
this._udc({ from, to })
.then(ts => { this.updateData(ts); })
.catch(() => { /* set "error" message */ })
3 years ago
}
renderMetrics() {
super.renderMetrics();
console.log('render my metrics');
}
3 years ago
private async _updateRange(range: AxisRange[]) {
console.log('update range');
console.log(range);
const ts = await this._udc({ from: range[0][0], to: range[0][1] });
const options = { axis: { x: { range: range[0] } } };
this.updateData(ts, options);
}
private _zoomOut({x, y}) {
console.log(`${x} -- ${y}`);
}
private _renderSegments() {
const m = this.metricContainer;
console.log(m);
}
3 years ago
}