Chartwerk Line Pod
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.

51 lines
1.6 KiB

import { MarkerSerie } from "../models/marker";
6 months ago
import { PodState } from "@chartwerk/core";
import { LineTimeSerie, LineOptions } from "../types";
import d3 from "d3";
export class Markers {
// TODO: more semantic name
6 months ago
private _d3Holder = null;
6 months ago
constructor(private _markers: MarkerSerie[], private _state: PodState<LineTimeSerie, LineOptions>) {
6 months ago
}
6 months ago
render(metricContainer: d3.Selection<SVGGElement, unknown, null, undefined>) {
6 months ago
if(this._d3Holder !== null) {
this._d3Holder.remove();
}
this._d3Holder = metricContainer.append('g').attr('class', 'markers-layer');
for (const ms of this._markers) {
this.renderSerie(ms);
}
}
6 months ago
protected renderSerie(serie: MarkerSerie) {
serie.data.forEach((d) => {
let linePosition = this._state.xScale(d) as number;
this._d3Holder.append('line')
6 months ago
.attr('class', 'gap-line')
.attr('stroke', serie.color)
6 months ago
.attr('stroke-width', '1px')
.attr('stroke-opacity', '0.3')
.attr('stroke-dasharray', '4')
.attr('x1', linePosition)
.attr('x2', linePosition)
.attr('y1', 0)
6 months ago
// @ts-ignore // TODO: remove ignore but boxParams are protected
6 months ago
.attr('y2', this._state.boxParams.height)
.attr('pointer-events', 'none');
this._d3Holder.append('circle')
6 months ago
.attr('class', 'gap-circle')
.attr('stroke', serie.color)
6 months ago
.attr('stroke-width', '2px')
.attr('r', 4)
.attr('cx', linePosition)
.attr('cy', 5)
6 months ago
.attr('pointer-events', 'none') // TODO: make all on implementation of Events
6 months ago
.style('cursor', 'pointer')
});
6 months ago
}
}