|
|
|
@ -15,7 +15,7 @@ const DEFAULT_LINE_TYPE = LineType.NONE;
|
|
|
|
|
const DEFAULT_LINE_DASHED_AMOUNT = 4; |
|
|
|
|
|
|
|
|
|
export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOptions> { |
|
|
|
|
_metricsContainer: any; |
|
|
|
|
metricContainer: any; |
|
|
|
|
_delaunayDiagram: DelaunayDiagram; |
|
|
|
|
|
|
|
|
|
constructor(el: HTMLElement, _series: ScatterData[] = [], _options: ScatterOptions = {}) { |
|
|
|
@ -28,7 +28,6 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.updateCrosshair(); |
|
|
|
|
this.renderMetricContainer(); |
|
|
|
|
|
|
|
|
|
this._delaunayDiagram = new DelaunayDiagram(this.series, this.xScale, this.getYScale.bind(this)); |
|
|
|
|
|
|
|
|
@ -36,19 +35,13 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
this.renderPoints(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderMetricContainer(): void { |
|
|
|
|
// container for clip path
|
|
|
|
|
const clipContatiner = this.chartContainer |
|
|
|
|
.append('g') |
|
|
|
|
.attr('clip-path', `url(#${this.rectClipId})`) |
|
|
|
|
.attr('class', 'metrics-container'); |
|
|
|
|
// container for panning
|
|
|
|
|
this._metricsContainer = clipContatiner |
|
|
|
|
.append('g') |
|
|
|
|
.attr('class', ' metrics-rect'); |
|
|
|
|
clearAllMetrics(): void { |
|
|
|
|
// TODO: temporary hack before it will be implemented in core.
|
|
|
|
|
this.chartContainer.selectAll('.metric-el').remove(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected updateCrosshair(): void { |
|
|
|
|
this.crosshair.selectAll('circle').remove(); |
|
|
|
|
// TODO: Crosshair class, which can be used as Pod
|
|
|
|
|
this.appendCrosshairPoints(); |
|
|
|
|
} |
|
|
|
@ -109,10 +102,10 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
strokeDasharray = DEFAULT_LINE_DASHED_AMOUNT; |
|
|
|
|
} |
|
|
|
|
const lineGenerator = this.d3.line() |
|
|
|
|
.x((d: [number, number]) => this.xScale(d[1])) |
|
|
|
|
.y((d: [number, number]) => this.getYScale(orientation)(d[0])); |
|
|
|
|
.x((d: [number, number]) => this.xScale(d[0])) |
|
|
|
|
.y((d: [number, number]) => this.getYScale(orientation)(d[1])); |
|
|
|
|
|
|
|
|
|
this._metricsContainer |
|
|
|
|
this.metricContainer |
|
|
|
|
.append('path') |
|
|
|
|
.datum(datapoints) |
|
|
|
|
.attr('class', 'metric-path') |
|
|
|
@ -130,7 +123,7 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this._metricsContainer.selectAll(null) |
|
|
|
|
this.metricContainer.selectAll(null) |
|
|
|
|
.data(this._delaunayDiagram.data) |
|
|
|
|
.enter() |
|
|
|
|
.append('circle') |
|
|
|
@ -139,10 +132,10 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
.attr('r', (d: number[]) => this.series[_.last(d)].pointSize || DEFAULT_POINT_SIZE) |
|
|
|
|
.style('fill', (d: number[]) => this.getSerieColor(_.last(d))) |
|
|
|
|
.style('pointer-events', 'none') |
|
|
|
|
.attr('cx', (d: any[]) => this.xScale(d[1])) |
|
|
|
|
.attr('cy', (d: any[]) => this.getYScale(this.series[_.last(d)].yOrientation)(d[0])); |
|
|
|
|
.attr('cx', (d: any[]) => this.xScale(d[0])) |
|
|
|
|
.attr('cy', (d: any[]) => this.getYScale(this.series[_.last(d)].yOrientation)(d[1])); |
|
|
|
|
|
|
|
|
|
this._metricsContainer.selectAll(null) |
|
|
|
|
this.metricContainer.selectAll(null) |
|
|
|
|
.data(this._delaunayDiagram.data) |
|
|
|
|
.enter() |
|
|
|
|
.append('rect') |
|
|
|
@ -151,8 +144,8 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
.attr('r', (d: number[]) => this.series[_.last(d)].pointSize || DEFAULT_POINT_SIZE) |
|
|
|
|
.style('fill', (d: number[]) => this.getSerieColor(_.last(d))) |
|
|
|
|
.style('pointer-events', 'none') |
|
|
|
|
.attr('x', (d: number[]) => this.xScale(d[1]) - (this.series[_.last(d)].pointSize || DEFAULT_POINT_SIZE) / 2) |
|
|
|
|
.attr('y', (d: number[]) => this.getYScale(this.series[_.last(d)].yOrientation)(d[0]) - (this.series[_.last(d)].pointSize || DEFAULT_POINT_SIZE) / 2) |
|
|
|
|
.attr('x', (d: number[]) => this.xScale(d[0]) - (this.series[_.last(d)].pointSize || DEFAULT_POINT_SIZE) / 2) |
|
|
|
|
.attr('y', (d: number[]) => this.getYScale(this.series[_.last(d)].yOrientation)(d[1]) - (this.series[_.last(d)].pointSize || DEFAULT_POINT_SIZE) / 2) |
|
|
|
|
.attr('width', (d: number[]) => this.series[_.last(d)].pointSize || DEFAULT_POINT_SIZE) |
|
|
|
|
.attr('height', (d: number[]) => this.series[_.last(d)].pointSize || DEFAULT_POINT_SIZE); |
|
|
|
|
} |
|
|
|
@ -185,10 +178,10 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
const size = this.getCrosshairCircleBackgroundSize(serieIdx); |
|
|
|
|
const colorFormatter = this.series[serieIdx].colorFormatter; |
|
|
|
|
this.crosshair.selectAll(`.crosshair-point-${serieIdx}`) |
|
|
|
|
.attr('cx', this.xScale(datapoint[1])) |
|
|
|
|
.attr('cy', this.getYScale(serieOrientation)(datapoint[0])) |
|
|
|
|
.attr('x', this.xScale(datapoint[1]) - size / 2) |
|
|
|
|
.attr('y', this.getYScale(serieOrientation)(datapoint[0]) - size / 2) |
|
|
|
|
.attr('cx', this.xScale(datapoint[0])) |
|
|
|
|
.attr('cy', this.getYScale(serieOrientation)(datapoint[1])) |
|
|
|
|
.attr('x', this.xScale(datapoint[0]) - size / 2) |
|
|
|
|
.attr('y', this.getYScale(serieOrientation)(datapoint[1]) - size / 2) |
|
|
|
|
.attr('fill', colorFormatter !== undefined ? colorFormatter(datapoint) : this.series[serieIdx].color) |
|
|
|
|
.style('display', null); |
|
|
|
|
} |
|
|
|
|