|
|
@ -17,7 +17,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
|
|
|
|
|
|
|
|
constructor(_el: HTMLElement, _series: LineTimeSerie[] = [], _options: LineOptions = {}) { |
|
|
|
constructor(_el: HTMLElement, _series: LineTimeSerie[] = [], _options: LineOptions = {}) { |
|
|
|
super(_el, _series, _options); |
|
|
|
super(_el, _series, _options); |
|
|
|
this.coreSeries = new LineSeries(_series); |
|
|
|
this.series = new LineSeries(_series); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
renderMetrics(): void { |
|
|
|
renderMetrics(): void { |
|
|
@ -27,12 +27,12 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
this.initLineGenerator(); |
|
|
|
this.initLineGenerator(); |
|
|
|
this.initAreaGenerator(); |
|
|
|
this.initAreaGenerator(); |
|
|
|
|
|
|
|
|
|
|
|
if(!this.coreSeries.isSeriesAvailable) { |
|
|
|
if(!this.series.isSeriesAvailable) { |
|
|
|
this.renderNoDataPointsMessage(); |
|
|
|
this.renderNoDataPointsMessage(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(const serie of this.coreSeries.visibleSeries) { |
|
|
|
for(const serie of this.series.visibleSeries) { |
|
|
|
this._renderMetric(serie); |
|
|
|
this._renderMetric(serie); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -111,7 +111,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
|
|
|
|
|
|
|
|
appendCrosshairCircles(): void { |
|
|
|
appendCrosshairCircles(): void { |
|
|
|
// circle for each serie
|
|
|
|
// circle for each serie
|
|
|
|
this.coreSeries.visibleSeries.forEach((serie: LineTimeSerie, serieIdx: number) => { |
|
|
|
this.series.visibleSeries.forEach((serie: LineTimeSerie, serieIdx: number) => { |
|
|
|
this.appendCrosshairCircle(serieIdx); |
|
|
|
this.appendCrosshairCircle(serieIdx); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -124,7 +124,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
.attr('cx', -CROSSHAIR_BACKGROUND_RAIDUS) |
|
|
|
.attr('cx', -CROSSHAIR_BACKGROUND_RAIDUS) |
|
|
|
.attr('cy', -CROSSHAIR_BACKGROUND_RAIDUS) |
|
|
|
.attr('cy', -CROSSHAIR_BACKGROUND_RAIDUS) |
|
|
|
.attr('clip-path', `url(#${this.rectClipId})`) |
|
|
|
.attr('clip-path', `url(#${this.rectClipId})`) |
|
|
|
.attr('fill', this.coreSeries.visibleSeries[serieIdx].color) |
|
|
|
.attr('fill', this.series.visibleSeries[serieIdx].color) |
|
|
|
.style('opacity', CROSSHAIR_BACKGROUND_OPACITY) |
|
|
|
.style('opacity', CROSSHAIR_BACKGROUND_OPACITY) |
|
|
|
.style('pointer-events', 'none'); |
|
|
|
.style('pointer-events', 'none'); |
|
|
|
|
|
|
|
|
|
|
@ -134,7 +134,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
.attr('cy', -CROSSHAIR_CIRCLE_RADIUS) |
|
|
|
.attr('cy', -CROSSHAIR_CIRCLE_RADIUS) |
|
|
|
.attr('class', `crosshair-circle-${serieIdx}`) |
|
|
|
.attr('class', `crosshair-circle-${serieIdx}`) |
|
|
|
.attr('clip-path', `url(#${this.rectClipId})`) |
|
|
|
.attr('clip-path', `url(#${this.rectClipId})`) |
|
|
|
.attr('fill', this.coreSeries.visibleSeries[serieIdx].color) |
|
|
|
.attr('fill', this.series.visibleSeries[serieIdx].color) |
|
|
|
.attr('r', CROSSHAIR_CIRCLE_RADIUS) |
|
|
|
.attr('r', CROSSHAIR_CIRCLE_RADIUS) |
|
|
|
.style('pointer-events', 'none'); |
|
|
|
.style('pointer-events', 'none'); |
|
|
|
} |
|
|
|
} |
|
|
@ -146,7 +146,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
this.moveCrosshairLine(eventX, eventY); |
|
|
|
this.moveCrosshairLine(eventX, eventY); |
|
|
|
const datapoints = this.findAndHighlightDatapoints(values.x, values.y); |
|
|
|
const datapoints = this.findAndHighlightDatapoints(values.x, values.y); |
|
|
|
|
|
|
|
|
|
|
|
this.coreOptions.callbackSharedCrosshairMove({ |
|
|
|
this.options.callbackSharedCrosshairMove({ |
|
|
|
datapoints: datapoints, |
|
|
|
datapoints: datapoints, |
|
|
|
eventX, eventY |
|
|
|
eventX, eventY |
|
|
|
}); |
|
|
|
}); |
|
|
@ -157,7 +157,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
moveCrosshairLine(xPosition: number, yPosition: number): void { |
|
|
|
moveCrosshairLine(xPosition: number, yPosition: number): void { |
|
|
|
switch(this.coreOptions.crosshair.orientation) { |
|
|
|
switch(this.options.crosshair.orientation) { |
|
|
|
case CrosshairOrientation.VERTICAL: |
|
|
|
case CrosshairOrientation.VERTICAL: |
|
|
|
this.crosshair.select('#crosshair-line-x') |
|
|
|
this.crosshair.select('#crosshair-line-x') |
|
|
|
.attr('x1', xPosition) |
|
|
|
.attr('x1', xPosition) |
|
|
@ -177,7 +177,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
.attr('y2', yPosition); |
|
|
|
.attr('y2', yPosition); |
|
|
|
return; |
|
|
|
return; |
|
|
|
default: |
|
|
|
default: |
|
|
|
throw new Error(`Unknown type of crosshair orientaion: ${this.coreOptions.crosshair.orientation}`); |
|
|
|
throw new Error(`Unknown type of crosshair orientaion: ${this.options.crosshair.orientation}`); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -205,7 +205,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
getClosestIndex(datapoints: [number, number][], xValue: number, yValue: number): number { |
|
|
|
getClosestIndex(datapoints: [number, number][], xValue: number, yValue: number): number { |
|
|
|
let columnIdx; // 0 for x value, 1 for y value,
|
|
|
|
let columnIdx; // 0 for x value, 1 for y value,
|
|
|
|
let value; // xValue to y Value
|
|
|
|
let value; // xValue to y Value
|
|
|
|
switch(this.coreOptions.crosshair.orientation) { |
|
|
|
switch(this.options.crosshair.orientation) { |
|
|
|
case CrosshairOrientation.VERTICAL: |
|
|
|
case CrosshairOrientation.VERTICAL: |
|
|
|
columnIdx = 0; |
|
|
|
columnIdx = 0; |
|
|
|
value = xValue; |
|
|
|
value = xValue; |
|
|
@ -219,7 +219,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
columnIdx = 1; |
|
|
|
columnIdx = 1; |
|
|
|
value = yValue; |
|
|
|
value = yValue; |
|
|
|
default: |
|
|
|
default: |
|
|
|
throw new Error(`Unknown type of crosshair orientaion: ${this.coreOptions.crosshair.orientation}`); |
|
|
|
throw new Error(`Unknown type of crosshair orientaion: ${this.options.crosshair.orientation}`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: d3.bisect is not the best way. Use binary search
|
|
|
|
// TODO: d3.bisect is not the best way. Use binary search
|
|
|
@ -248,7 +248,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
// columnIdx: 1 for y, 0 for x
|
|
|
|
// columnIdx: 1 for y, 0 for x
|
|
|
|
// inverval: x/y value interval between data points
|
|
|
|
// inverval: x/y value interval between data points
|
|
|
|
// TODO: move it to base/state instead of timeInterval
|
|
|
|
// TODO: move it to base/state instead of timeInterval
|
|
|
|
const intervals = _.map(this.coreSeries.visibleSeries, serie => { |
|
|
|
const intervals = _.map(this.series.visibleSeries, serie => { |
|
|
|
if(serie.datapoints.length < 2) { |
|
|
|
if(serie.datapoints.length < 2) { |
|
|
|
return undefined; |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
} |
|
|
@ -272,7 +272,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
|
|
|
|
|
|
|
|
// TDOO: is shift key pressed
|
|
|
|
// TDOO: is shift key pressed
|
|
|
|
// TODO: need to refactor this object
|
|
|
|
// TODO: need to refactor this object
|
|
|
|
this.coreOptions.callbackMouseMove({ |
|
|
|
this.options.callbackMouseMove({ |
|
|
|
x: d3.event.pageX, |
|
|
|
x: d3.event.pageX, |
|
|
|
y: d3.event.pageY, |
|
|
|
y: d3.event.pageY, |
|
|
|
xVal: xValue, |
|
|
|
xVal: xValue, |
|
|
@ -284,11 +284,11 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
findAndHighlightDatapoints(xValue: number, yValue: number): { value: [number, number], color: string, label: string }[] { |
|
|
|
findAndHighlightDatapoints(xValue: number, yValue: number): { value: [number, number], color: string, label: string }[] { |
|
|
|
if(!this.coreSeries.isSeriesAvailable) { |
|
|
|
if(!this.series.isSeriesAvailable) { |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
} |
|
|
|
} |
|
|
|
let points = []; // datapoints in each metric that is closest to xValue/yValue position
|
|
|
|
let points = []; // datapoints in each metric that is closest to xValue/yValue position
|
|
|
|
this.coreSeries.visibleSeries.forEach((serie: LineTimeSerie) => { |
|
|
|
this.series.visibleSeries.forEach((serie: LineTimeSerie) => { |
|
|
|
const closestDatapoint = this.getClosestDatapoint(serie, xValue, yValue); |
|
|
|
const closestDatapoint = this.getClosestDatapoint(serie, xValue, yValue); |
|
|
|
if(closestDatapoint === undefined) { |
|
|
|
if(closestDatapoint === undefined) { |
|
|
|
this.hideCrosshairCircle(serie.idx); |
|
|
|
this.hideCrosshairCircle(serie.idx); |
|
|
@ -315,21 +315,21 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onMouseOut(): void { |
|
|
|
onMouseOut(): void { |
|
|
|
this.coreOptions.callbackMouseOut(); |
|
|
|
this.options.callbackMouseOut(); |
|
|
|
this.crosshair.style('display', 'none'); |
|
|
|
this.crosshair.style('display', 'none'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isDoubleClickActive(): boolean { |
|
|
|
isDoubleClickActive(): boolean { |
|
|
|
return this.coreOptions.doubleClickEvent.isActive; |
|
|
|
return this.options.doubleClickEvent.isActive; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// methods below rewrite cores, (move more methods here)
|
|
|
|
// methods below rewrite s, (move more methods here)
|
|
|
|
protected zoomOut(): void { |
|
|
|
protected zoomOut(): void { |
|
|
|
if(d3.event.type === 'dblclick' && !this.isDoubleClickActive()) { |
|
|
|
if(d3.event.type === 'dblclick' && !this.isDoubleClickActive()) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// TODO: its not clear, why we use this orientation here. Mb its better to use separate option
|
|
|
|
// TODO: its not clear, why we use this orientation here. Mb its better to use separate option
|
|
|
|
const orientation: BrushOrientation = this.coreOptions.mouseZoomEvent.orientation; |
|
|
|
const orientation: BrushOrientation = this.options.mouseZoomEvent.orientation; |
|
|
|
const xInterval = this.state.xValueRange[1] - this.state.xValueRange[0]; |
|
|
|
const xInterval = this.state.xValueRange[1] - this.state.xValueRange[0]; |
|
|
|
const yInterval = this.state.yValueRange[1] - this.state.yValueRange[0]; |
|
|
|
const yInterval = this.state.yValueRange[1] - this.state.yValueRange[0]; |
|
|
|
switch(orientation) { |
|
|
|
switch(orientation) { |
|
|
@ -364,7 +364,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
x: xAxisMiddleValue, |
|
|
|
x: xAxisMiddleValue, |
|
|
|
y: yAxisMiddleValue |
|
|
|
y: yAxisMiddleValue |
|
|
|
} |
|
|
|
} |
|
|
|
this.coreOptions.callbackZoomOut(centers); |
|
|
|
this.options.callbackZoomOut(centers); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|