|
|
@ -1,34 +1,40 @@ |
|
|
|
import { SegmentSerie } from "../models/segment"; |
|
|
|
import { SegmentSerie, SegmentElement } from "../models/segment"; |
|
|
|
import { PodState } from "@chartwerk/core"; |
|
|
|
import { PodState } from "@chartwerk/core"; |
|
|
|
import { LineTimeSerie, LineOptions } from "../types"; |
|
|
|
import { LineTimeSerie, LineOptions } from "../types"; |
|
|
|
|
|
|
|
|
|
|
|
import d3 from "d3"; |
|
|
|
import * as d3 from "d3"; |
|
|
|
|
|
|
|
|
|
|
|
export class Segments { |
|
|
|
export class Segments { |
|
|
|
// TODO: more semantic name
|
|
|
|
// TODO: more semantic name
|
|
|
|
private _d3Holder = null; |
|
|
|
private _d3Holder = null; |
|
|
|
|
|
|
|
private _metricCon = null; |
|
|
|
|
|
|
|
|
|
|
|
constructor(private _series: SegmentSerie[], private _state: PodState<LineTimeSerie, LineOptions>) { |
|
|
|
constructor( |
|
|
|
|
|
|
|
private _series: SegmentSerie[], |
|
|
|
|
|
|
|
private _state: PodState<LineTimeSerie, LineOptions> |
|
|
|
|
|
|
|
) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render(metricContainer: d3.Selection<SVGGElement, unknown, null, undefined>) { |
|
|
|
render(metricContainer: d3.Selection<SVGGElement, unknown, null, undefined>, chartContainer: d3.Selection<SVGGElement, unknown, null, undefined>) { |
|
|
|
if(this._d3Holder !== null) { |
|
|
|
if(this._d3Holder !== null) { |
|
|
|
this._d3Holder.remove(); |
|
|
|
this._d3Holder.remove(); |
|
|
|
} |
|
|
|
} |
|
|
|
this._d3Holder = metricContainer.append('g').attr('class', 'markers-layer'); |
|
|
|
this._d3Holder = metricContainer.append('g').attr('class', 'markers-layer'); |
|
|
|
for (const s of this._series) { |
|
|
|
for (const s of this._series) { |
|
|
|
this.renderSerie(s); |
|
|
|
this.renderSerie(chartContainer, s); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected renderSerie(serie: SegmentSerie) { |
|
|
|
protected renderSerie(chartContainer: d3.Selection<SVGGElement, unknown, null, undefined>, serie: SegmentSerie) { |
|
|
|
|
|
|
|
// TODO: it's hack with core, need to find a better way
|
|
|
|
|
|
|
|
const overlay = chartContainer.select('.overlay'); |
|
|
|
serie.data.forEach((d) => { |
|
|
|
serie.data.forEach((d) => { |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
const startPositionX = this._state.xScale(d[0]) as number; |
|
|
|
const startPositionX = this._state.xScale(d[0]) as number; |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
const endPositionX = this._state.xScale(d[1]) as number; |
|
|
|
const endPositionX = this._state.xScale(d[1]) as number; |
|
|
|
const width = endPositionX - startPositionX // Math.max(endPositionX - startPositionX, MIMIMUM_SEGMENT_WIDTH);
|
|
|
|
const width = endPositionX - startPositionX // Math.max(endPositionX - startPositionX, MIMIMUM_SEGMENT_WIDTH);
|
|
|
|
|
|
|
|
|
|
|
|
this._d3Holder.append('rect') |
|
|
|
this._d3Holder.append('rect') |
|
|
|
.attr('class', 'segment') |
|
|
|
.attr('class', 'segment') |
|
|
|
.attr('x', startPositionX) |
|
|
|
.attr('x', startPositionX) |
|
|
@ -38,8 +44,26 @@ export class Segments { |
|
|
|
.attr('height', this._state.boxParams.height) |
|
|
|
.attr('height', this._state.boxParams.height) |
|
|
|
.attr('opacity', 0.3) |
|
|
|
.attr('opacity', 0.3) |
|
|
|
.style('fill', serie.color) |
|
|
|
.style('fill', serie.color) |
|
|
|
.style('pointer-events', 'none'); |
|
|
|
.on('mouseover', function() { |
|
|
|
|
|
|
|
if(serie.select === true) { |
|
|
|
|
|
|
|
d3.select(this).attr('opacity', 0.5); |
|
|
|
|
|
|
|
if(serie.onSelect) { |
|
|
|
|
|
|
|
serie.onSelect(d); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.on('mouseout', function(e) { |
|
|
|
|
|
|
|
if(serie.select === true) { |
|
|
|
|
|
|
|
d3.select(this).attr('opacity', 0.3); |
|
|
|
|
|
|
|
if(serie.onUnselect) { |
|
|
|
|
|
|
|
serie.onUnselect(d); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.on('mousemove', function(e) { |
|
|
|
|
|
|
|
var event = new MouseEvent('mousemove', d3.event); |
|
|
|
|
|
|
|
overlay.node().dispatchEvent(event) |
|
|
|
|
|
|
|
}) |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |