|
|
|
@ -1,65 +1,74 @@
|
|
|
|
|
import { ChartwerkPod, VueChartwerkPodMixin, TimeFormat, yAxisOrientation, CrosshairOrientation } from '@chartwerk/core'; |
|
|
|
|
import { ScatterData, ScatterOptions, PointType, LineType, HighlightedData, MouseMoveEvent, DelaunayDataRow } from './types'; |
|
|
|
|
import { ChartwerkPod, VueChartwerkPodMixin, TickOrientation, TimeFormat, yAxisOrientation, CrosshairOrientation, PanOrientation } from '@chartwerk/core'; |
|
|
|
|
import { ScatterData, ScatterOptions, PointType, LineType, ColorFormatter } from './types'; |
|
|
|
|
|
|
|
|
|
import { DelaunayDiagram } from './models/delaunay'; |
|
|
|
|
import { ScatterSeries } from './models/scatter_series'; |
|
|
|
|
import { DelaunayDiagram } from './delaunay'; |
|
|
|
|
|
|
|
|
|
import * as d3 from 'd3'; |
|
|
|
|
import * as _ from 'lodash'; |
|
|
|
|
|
|
|
|
|
// TODO: use pod state with defaults
|
|
|
|
|
const DEFAULT_POINT_SIZE = 4; |
|
|
|
|
const POINT_HIGHLIGHT_DIAMETER = 4; |
|
|
|
|
const CROSSHAIR_BACKGROUND_OPACITY = 0.3; |
|
|
|
|
const DEFAULT_POINT_TYPE = PointType.CIRCLE; |
|
|
|
|
const DEFAULT_LINE_TYPE = LineType.NONE; |
|
|
|
|
const DEFAULT_LINE_DASHED_AMOUNT = 4; |
|
|
|
|
|
|
|
|
|
export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOptions> { |
|
|
|
|
metricContainer: any; |
|
|
|
|
_metricsContainer: any; |
|
|
|
|
_delaunayDiagram: DelaunayDiagram; |
|
|
|
|
series: ScatterSeries; |
|
|
|
|
|
|
|
|
|
constructor(el: HTMLElement, _series: ScatterData[] = [], _options: ScatterOptions = {}) { |
|
|
|
|
super(el, _series, _options); |
|
|
|
|
this.series = new ScatterSeries(_series); |
|
|
|
|
super(d3, el, _series, _options); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderMetrics(): void { |
|
|
|
|
if(!this.series.isSeriesAvailable) { |
|
|
|
|
if(this.series.length === 0) { |
|
|
|
|
this.renderNoDataPointsMessage(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.updateCrosshair(); |
|
|
|
|
this.updateCrosshair();
|
|
|
|
|
this.renderMetricContainer(); |
|
|
|
|
|
|
|
|
|
this._delaunayDiagram = new DelaunayDiagram(this.series, this.state.xScale, this.getYScale.bind(this)); |
|
|
|
|
this._delaunayDiagram = new DelaunayDiagram(this.series, this.xScale, this.getYScale.bind(this)); |
|
|
|
|
|
|
|
|
|
this.renderLines(); |
|
|
|
|
this.renderPoints(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
clearAllMetrics(): void { |
|
|
|
|
// TODO: temporary hack before it will be implemented in core.
|
|
|
|
|
this.chartContainer.selectAll('.metric-el').remove(); |
|
|
|
|
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'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected updateCrosshair(): void { |
|
|
|
|
this.crosshair.selectAll('circle').remove(); |
|
|
|
|
// TODO: Crosshair class, which can be used as Pod
|
|
|
|
|
this.appendCrosshairPoints(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
appendCrosshairPoints(): void { |
|
|
|
|
this.series.visibleSeries.forEach((serie: ScatterData) => { |
|
|
|
|
this.appendCrosshairPoint(serie.idx, serie.pointType, serie.pointSize); |
|
|
|
|
this.series.forEach((serie: ScatterData, serieIdx: number) => { |
|
|
|
|
this.appendCrosshairPoint(serieIdx); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected appendCrosshairPoint(serieIdx: number, pointType: PointType, size: number): void { |
|
|
|
|
protected appendCrosshairPoint(serieIdx: number): void { |
|
|
|
|
// TODO: add Crosshair type options
|
|
|
|
|
const pointType = this.series[serieIdx].pointType || DEFAULT_POINT_TYPE; |
|
|
|
|
switch(pointType) { |
|
|
|
|
case PointType.NONE: |
|
|
|
|
return; |
|
|
|
|
case PointType.CIRCLE: |
|
|
|
|
this.crosshair.append('circle') |
|
|
|
|
.attr('class', `crosshair-point crosshair-point-${serieIdx} crosshair-background`) |
|
|
|
|
.attr('r', this.getCrosshairCircleBackgroundSize(size, pointType)) |
|
|
|
|
.attr('r', this.getCrosshairCircleBackgroundSize(serieIdx)) |
|
|
|
|
.attr('clip-path', `url(#${this.rectClipId})`) |
|
|
|
|
.style('opacity', CROSSHAIR_BACKGROUND_OPACITY) |
|
|
|
|
.style('pointer-events', 'none') |
|
|
|
@ -68,8 +77,8 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
case PointType.RECTANGLE: |
|
|
|
|
this.crosshair.append('rect') |
|
|
|
|
.attr('class', `crosshair-point crosshair-point-${serieIdx} crosshair-background`) |
|
|
|
|
.attr('width', this.getCrosshairCircleBackgroundSize(size, pointType)) |
|
|
|
|
.attr('height', this.getCrosshairCircleBackgroundSize(size, pointType)) |
|
|
|
|
.attr('width', this.getCrosshairCircleBackgroundSize(serieIdx)) |
|
|
|
|
.attr('height', this.getCrosshairCircleBackgroundSize(serieIdx)) |
|
|
|
|
.attr('clip-path', `url(#${this.rectClipId})`) |
|
|
|
|
.style('opacity', CROSSHAIR_BACKGROUND_OPACITY) |
|
|
|
|
.style('pointer-events', 'none') |
|
|
|
@ -81,97 +90,82 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected renderLines(): void { |
|
|
|
|
this.series.visibleSeries.forEach(serie => { |
|
|
|
|
this.renderLine(serie); |
|
|
|
|
this.series.forEach((serie, serieIdx) => { |
|
|
|
|
if(serie.visible === false) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const lineType = serie.lineType || DEFAULT_LINE_TYPE; |
|
|
|
|
this.renderLine(serie.datapoints, lineType, this.getSerieColor(serieIdx), serie.yOrientation); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderLine(serie: ScatterData): void { |
|
|
|
|
if(serie.lineType === LineType.NONE) { |
|
|
|
|
renderLine(datapoints: number[][], lineType: LineType, color: string, orientation: yAxisOrientation): void { |
|
|
|
|
if(lineType === LineType.NONE) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
let strokeDasharray; |
|
|
|
|
// TODO: move to option
|
|
|
|
|
if(serie.lineType === LineType.DASHED) { |
|
|
|
|
if(lineType === LineType.DASHED) { |
|
|
|
|
strokeDasharray = DEFAULT_LINE_DASHED_AMOUNT; |
|
|
|
|
} |
|
|
|
|
const lineGenerator = d3.line() |
|
|
|
|
.x((d: [number, number]) => this.state.xScale(d[0])) |
|
|
|
|
.y((d: [number, number]) => this.getYScale(serie.yOrientation)(d[1])); |
|
|
|
|
const lineGenerator = this.d3.line() |
|
|
|
|
.x((d: [number, number]) => this.xScale(d[1])) |
|
|
|
|
.y((d: [number, number]) => this.getYScale(orientation)(d[0])); |
|
|
|
|
|
|
|
|
|
this.metricContainer |
|
|
|
|
this._metricsContainer |
|
|
|
|
.append('path') |
|
|
|
|
.datum(serie.datapoints) |
|
|
|
|
.datum(datapoints) |
|
|
|
|
.attr('class', 'metric-path') |
|
|
|
|
.attr('d', lineGenerator) |
|
|
|
|
.attr('fill', 'none') |
|
|
|
|
.attr('stroke', serie.color) |
|
|
|
|
.style('pointer-events', 'none') |
|
|
|
|
.attr('stroke', color) |
|
|
|
|
.attr('stroke-width', 1) |
|
|
|
|
.attr('stroke-opacity', 0.7) |
|
|
|
|
.attr('stroke-dasharray', strokeDasharray) |
|
|
|
|
.style('pointer-events', serie.clickCallback ? 'auto' : 'none') |
|
|
|
|
.style('cursor', serie.clickCallback ? 'pointer' : 'crosshair') |
|
|
|
|
.on('click', () => { serie.clickCallback({ target: serie.target, class: serie.class, alias: serie.alias }) }); |
|
|
|
|
.attr('d', lineGenerator); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected renderPoints(): void { |
|
|
|
|
if(!this._delaunayDiagram.data) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.metricContainer.selectAll(null) |
|
|
|
|
|
|
|
|
|
this._metricsContainer.selectAll(null) |
|
|
|
|
.data(this._delaunayDiagram.data) |
|
|
|
|
.enter() |
|
|
|
|
.append('circle') |
|
|
|
|
.filter((d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.pointType !== PointType.RECTANGLE) |
|
|
|
|
.filter((d: number[]) => this.series[_.last(d)].pointType !== PointType.RECTANGLE) |
|
|
|
|
.attr('class', (d, i: number) => `metric-element metric-circle point-${i}`) |
|
|
|
|
.attr('r', (d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.pointSize) |
|
|
|
|
.attr('cx', (d: DelaunayDataRow) => this.state.xScale(d[0])) |
|
|
|
|
.attr('cy', (d: DelaunayDataRow) => this.getYScale(this.series.getSerieByTarget(d[4])?.yOrientation)(d[1])) |
|
|
|
|
.style('fill', (d: DelaunayDataRow, i: number) => this.getSeriesColorFromDataRow(d, i)) |
|
|
|
|
.style('pointer-events', (d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.clickCallback ? 'auto' : 'none') |
|
|
|
|
.style('cursor', (d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.clickCallback ? 'pointer' : 'crosshair') |
|
|
|
|
.on('click', (d: DelaunayDataRow) => { |
|
|
|
|
d3.event.stopPropagation(); |
|
|
|
|
const serie = this.series.getSerieByTarget(d[4]); |
|
|
|
|
const serieData = { target: serie?.target, class: serie?.class, alias: serie?.alias }; |
|
|
|
|
serie?.clickCallback(serieData, d); |
|
|
|
|
}); |
|
|
|
|
.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])); |
|
|
|
|
|
|
|
|
|
this.metricContainer.selectAll(null) |
|
|
|
|
this._metricsContainer.selectAll(null) |
|
|
|
|
.data(this._delaunayDiagram.data) |
|
|
|
|
.enter() |
|
|
|
|
.append('rect') |
|
|
|
|
.filter((d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.pointType === PointType.RECTANGLE) |
|
|
|
|
.filter((d: number[]) => this.series[_.last(d)].pointType === PointType.RECTANGLE) |
|
|
|
|
.attr('class', (d, i: number) => `metric-element metric-circle point-${i}`) |
|
|
|
|
.attr('r', (d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.pointSize) |
|
|
|
|
.attr('x', (d: DelaunayDataRow) => this.state.xScale(d[0]) - this.series.getSerieByTarget(d[4])?.pointSize / 2) |
|
|
|
|
.attr('y', (d: DelaunayDataRow) => this.getYScale(this.series.getSerieByTarget(d[4])?.yOrientation)(d[1]) - this.series.getSerieByTarget(d[4])?.pointSize / 2) |
|
|
|
|
.attr('width', (d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.pointSize) |
|
|
|
|
.attr('height', (d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.pointSize) |
|
|
|
|
.style('fill', (d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.color) |
|
|
|
|
.style('pointer-events', (d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.clickCallback ? 'auto' : 'none') |
|
|
|
|
.style('cursor', (d: DelaunayDataRow) => this.series.getSerieByTarget(d[4])?.clickCallback ? 'pointer' : 'crosshair') |
|
|
|
|
.on('click', (d: DelaunayDataRow) => { |
|
|
|
|
d3.event.stopPropagation(); |
|
|
|
|
const serie = this.series.getSerieByTarget(d[4]); |
|
|
|
|
const serieData = { target: serie?.target, class: serie?.class, alias: serie?.alias }; |
|
|
|
|
serie?.clickCallback(serieData, d); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getSeriesColorFromDataRow(values: DelaunayDataRow, rowIdx: number): string { |
|
|
|
|
const serie = this.series.getSerieByTarget(values[4]); |
|
|
|
|
if(serie?.colorFormatter) { |
|
|
|
|
return serie.colorFormatter(values, rowIdx); |
|
|
|
|
} |
|
|
|
|
return serie.color; |
|
|
|
|
.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('width', (d: number[]) => this.series[_.last(d)].pointSize || DEFAULT_POINT_SIZE) |
|
|
|
|
.attr('height', (d: number[]) => this.series[_.last(d)].pointSize || DEFAULT_POINT_SIZE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onPanningEnd(): void { |
|
|
|
|
this.isPanning = false; |
|
|
|
|
this.onMouseOut(); |
|
|
|
|
this._delaunayDiagram.setDelaunayDiagram(this.state.xScale, this.getYScale.bind(this)); |
|
|
|
|
this.options.callbackPanningEnd([this.state.xValueRange, this.state.yValueRange, this.state.y1ValueRange]); |
|
|
|
|
this._delaunayDiagram.setDelaunayDiagram(this.xScale, this.getYScale.bind(this)); |
|
|
|
|
if(this.options.eventsCallbacks !== undefined && this.options.eventsCallbacks.panningEnd !== undefined) { |
|
|
|
|
this.options.eventsCallbacks.panningEnd([this.state.xValueRange, this.state.yValueRange, this.state.y1ValueRange]); |
|
|
|
|
} else { |
|
|
|
|
console.log('on panning end, but there is no callback'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unhighlight(): void { |
|
|
|
@ -181,37 +175,47 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
highlight(pointIdx: number): void { |
|
|
|
|
this.unhighlight(); |
|
|
|
|
|
|
|
|
|
const row = this._delaunayDiagram.getDataRowByIndex(pointIdx); |
|
|
|
|
if(row === undefined || row === null) { |
|
|
|
|
const datapoint = this._delaunayDiagram.getDataRowByIndex(pointIdx); |
|
|
|
|
if(datapoint === undefined || datapoint === null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const serie = this.series.getSerieByTarget(row[4]); |
|
|
|
|
const size = this.getCrosshairCircleBackgroundSize(serie.pointSize, serie.pointType); |
|
|
|
|
this.crosshair.selectAll(`.crosshair-point-${serie.idx}`) |
|
|
|
|
.attr('cx', this.state.xScale(row[0])) |
|
|
|
|
.attr('cy', this.getYScale(serie.yOrientation)(row[1])) |
|
|
|
|
.attr('x', this.state.xScale(row[0]) - size / 2) |
|
|
|
|
.attr('y', this.getYScale(serie.yOrientation)(row[1]) - size / 2) |
|
|
|
|
.attr('fill', this.getSeriesColorFromDataRow(row, pointIdx)) |
|
|
|
|
|
|
|
|
|
const serieIdx = _.last(datapoint); |
|
|
|
|
const serieOrientation = this.series[serieIdx].yOrientation; |
|
|
|
|
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('fill', colorFormatter !== undefined ? colorFormatter(datapoint) : this.series[serieIdx].color) |
|
|
|
|
.style('display', null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected getCrosshairCircleBackgroundSize(pointSize: number, pointType: PointType): number { |
|
|
|
|
protected getCrosshairCircleBackgroundSize(serieIdx: number): number { |
|
|
|
|
const seriePointSize = this.series[serieIdx].pointSize || DEFAULT_POINT_SIZE; |
|
|
|
|
const pointType = this.series[serieIdx].pointType || DEFAULT_POINT_TYPE; |
|
|
|
|
let highlightDiameter = POINT_HIGHLIGHT_DIAMETER; |
|
|
|
|
if(pointType === PointType.RECTANGLE) { |
|
|
|
|
highlightDiameter = highlightDiameter * 2; |
|
|
|
|
} |
|
|
|
|
return pointSize + highlightDiameter; |
|
|
|
|
return seriePointSize + highlightDiameter; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public renderSharedCrosshair(values: { x?: number, y?: number }): void { |
|
|
|
|
this.onMouseOver(); // TODO: refactor to use it once
|
|
|
|
|
const eventX = this.state.xScale(values.x); |
|
|
|
|
const eventY = this.state.yScale(values.y); |
|
|
|
|
const eventX = this.xScale(values.x); |
|
|
|
|
const eventY = this.yScale(values.y); |
|
|
|
|
this.moveCrosshairLine(eventX, eventY); |
|
|
|
|
const datapoints = this.findAndHighlightDatapoints(values.x, values.y); |
|
|
|
|
|
|
|
|
|
this.options.callbackSharedCrosshairMove({ |
|
|
|
|
if(this.options.eventsCallbacks === undefined || this.options.eventsCallbacks.sharedCrosshairMove === undefined) { |
|
|
|
|
console.log('Shared crosshair move, but there is no callback'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.options.eventsCallbacks.sharedCrosshairMove({ |
|
|
|
|
datapoints, |
|
|
|
|
eventX, eventY |
|
|
|
|
}); |
|
|
|
@ -242,44 +246,33 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
findAndHighlightDatapoints(eventX: number, eventY: number): { |
|
|
|
|
xValue: number, yValue: number, customValue: number, |
|
|
|
|
pointIdx: number, totalPointIdx: number, |
|
|
|
|
serieInfo: { target: string, alias?: string, class?: string, idx?: number } |
|
|
|
|
} | null { |
|
|
|
|
if(!this.series.isSeriesAvailable) { |
|
|
|
|
findAndHighlightDatapoints(eventX: number, eventY: number): { values: any[], pointIdx: number } | null { |
|
|
|
|
if(this.series === undefined || this.series.length === 0) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const pointIndex = this._delaunayDiagram.findPointIndex(eventX, eventY); |
|
|
|
|
if(pointIndex === undefined) { |
|
|
|
|
this.unhighlight(); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
this.highlight(pointIndex); |
|
|
|
|
const row = this._delaunayDiagram.data[pointIndex]; |
|
|
|
|
const serie = this.series.getSerieByTarget(row[4]); |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
xValue: row[0], |
|
|
|
|
yValue: row[1], |
|
|
|
|
customValue: row[2], |
|
|
|
|
pointIdx: row[3], |
|
|
|
|
serieInfo: { |
|
|
|
|
target: serie.target, |
|
|
|
|
alias: serie.alias, |
|
|
|
|
class: serie.class, |
|
|
|
|
idx: serie.idx, |
|
|
|
|
}, |
|
|
|
|
totalPointIdx: pointIndex, |
|
|
|
|
values: this._delaunayDiagram.data[pointIndex], |
|
|
|
|
pointIdx: pointIndex, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected getYScale(orientation: yAxisOrientation): d3.ScaleLinear<number, number> { |
|
|
|
|
if(orientation === undefined || orientation === yAxisOrientation.BOTH) { |
|
|
|
|
return this.yScale; |
|
|
|
|
} |
|
|
|
|
switch(orientation) { |
|
|
|
|
case yAxisOrientation.LEFT: |
|
|
|
|
return this.state.yScale; |
|
|
|
|
return this.yScale; |
|
|
|
|
case yAxisOrientation.RIGHT: |
|
|
|
|
return this.state.y1Scale; |
|
|
|
|
return this.y1Scale; |
|
|
|
|
default: |
|
|
|
|
throw new Error(`Unknown type of y axis orientation: ${orientation}`)
|
|
|
|
|
} |
|
|
|
@ -290,11 +283,12 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onMouseMove(): void { |
|
|
|
|
const mousePosition = d3.mouse(this.chartContainer.node()); |
|
|
|
|
const mousePosition = this.d3.mouse(this.chartContainer.node()); |
|
|
|
|
const eventX = mousePosition[0]; |
|
|
|
|
const eventY = mousePosition[1]; |
|
|
|
|
|
|
|
|
|
if(this.isPanning === true || this.isBrushing === true) { |
|
|
|
|
// TODO: seems isOutOfChart is deprecated (check clippath correctness)
|
|
|
|
|
if(this.isOutOfChart() === true || this.isPanning === true || this.isBrushing === true) { |
|
|
|
|
this.crosshair.style('display', 'none'); |
|
|
|
|
return; |
|
|
|
|
} else { |
|
|
|
@ -305,25 +299,24 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
|
|
|
|
|
// TOOD: it should be two different methods
|
|
|
|
|
const highlighted = this.findAndHighlightDatapoints(eventX, eventY); |
|
|
|
|
this.options.callbackMouseMove({ |
|
|
|
|
bbox: { |
|
|
|
|
clientX: d3.event.clientX, |
|
|
|
|
clientY: d3.event.clientY, |
|
|
|
|
x: eventX, |
|
|
|
|
y: eventY, |
|
|
|
|
chartWidth: this.width, |
|
|
|
|
chartHeight: this.height, |
|
|
|
|
}, |
|
|
|
|
data: { |
|
|
|
|
xval: this.state.xScale.invert(eventX), |
|
|
|
|
yval: this.state.xScale.invert(eventY), |
|
|
|
|
highlighted, |
|
|
|
|
} |
|
|
|
|
if(this.options.eventsCallbacks === undefined || this.options.eventsCallbacks.mouseMove === undefined) { |
|
|
|
|
console.log('Mouse move, but there is no callback'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// TODO: group fields
|
|
|
|
|
this.options.eventsCallbacks.mouseMove({ |
|
|
|
|
x: this.d3.event.clientX, |
|
|
|
|
y: this.d3.event.clientY, |
|
|
|
|
xval: this.xScale.invert(eventX), |
|
|
|
|
yval: this.xScale.invert(eventY), |
|
|
|
|
highlighted, |
|
|
|
|
chartX: eventX, |
|
|
|
|
chartWidth: this.width |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onMouseOver(): void { |
|
|
|
|
if(this.isPanning === true || this.isBrushing === true) { |
|
|
|
|
if(this.isOutOfChart() === true || this.isPanning === true || this.isBrushing === true) { |
|
|
|
|
this.crosshair.style('display', 'none'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -331,7 +324,9 @@ export class ChartwerkScatterPod extends ChartwerkPod<ScatterData, ScatterOption
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onMouseOut(): void { |
|
|
|
|
this.options.callbackMouseOut(); |
|
|
|
|
if(this.options.eventsCallbacks !== undefined && this.options.eventsCallbacks.mouseOut !== undefined) { |
|
|
|
|
this.options.eventsCallbacks.mouseOut(); |
|
|
|
|
} |
|
|
|
|
this.crosshair.style('display', 'none'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -361,4 +356,4 @@ export const VueChartwerkScatterPodObject = {
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export { ScatterData, ScatterOptions, TimeFormat, PointType, LineType, HighlightedData, MouseMoveEvent }; |
|
|
|
|
export { ScatterData, ScatterOptions, TickOrientation, TimeFormat, PointType, LineType }; |
|
|
|
|