|
|
|
@ -17,7 +17,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
|
|
|
|
|
constructor(_el: HTMLElement, _series: LineTimeSerie[] = [], _options: LineOptions = {}) { |
|
|
|
|
super(_el, _series, _options); |
|
|
|
|
this.coreSeries = new LineSeries(_series); |
|
|
|
|
this.series = new LineSeries(_series); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderMetrics(): void { |
|
|
|
@ -27,12 +27,12 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
this.initLineGenerator(); |
|
|
|
|
this.initAreaGenerator(); |
|
|
|
|
|
|
|
|
|
if(!this.coreSeries.isSeriesAvailable) { |
|
|
|
|
if(!this.series.isSeriesAvailable) { |
|
|
|
|
this.renderNoDataPointsMessage(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(const serie of this.coreSeries.visibleSeries) { |
|
|
|
|
for(const serie of this.series.visibleSeries) { |
|
|
|
|
this._renderMetric(serie); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -111,7 +111,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
|
|
|
|
|
appendCrosshairCircles(): void { |
|
|
|
|
// circle for each serie
|
|
|
|
|
this.coreSeries.visibleSeries.forEach((serie: LineTimeSerie, serieIdx: number) => { |
|
|
|
|
this.series.visibleSeries.forEach((serie: LineTimeSerie, serieIdx: number) => { |
|
|
|
|
this.appendCrosshairCircle(serieIdx); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -124,7 +124,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
.attr('cx', -CROSSHAIR_BACKGROUND_RAIDUS) |
|
|
|
|
.attr('cy', -CROSSHAIR_BACKGROUND_RAIDUS) |
|
|
|
|
.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('pointer-events', 'none'); |
|
|
|
|
|
|
|
|
@ -134,7 +134,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
.attr('cy', -CROSSHAIR_CIRCLE_RADIUS) |
|
|
|
|
.attr('class', `crosshair-circle-${serieIdx}`) |
|
|
|
|
.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) |
|
|
|
|
.style('pointer-events', 'none'); |
|
|
|
|
} |
|
|
|
@ -146,7 +146,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
this.moveCrosshairLine(eventX, eventY); |
|
|
|
|
const datapoints = this.findAndHighlightDatapoints(values.x, values.y); |
|
|
|
|
|
|
|
|
|
this.coreOptions.callbackSharedCrosshairMove({ |
|
|
|
|
this.options.callbackSharedCrosshairMove({ |
|
|
|
|
datapoints: datapoints, |
|
|
|
|
eventX, eventY |
|
|
|
|
}); |
|
|
|
@ -157,7 +157,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
moveCrosshairLine(xPosition: number, yPosition: number): void { |
|
|
|
|
switch(this.coreOptions.crosshair.orientation) { |
|
|
|
|
switch(this.options.crosshair.orientation) { |
|
|
|
|
case CrosshairOrientation.VERTICAL: |
|
|
|
|
this.crosshair.select('#crosshair-line-x') |
|
|
|
|
.attr('x1', xPosition) |
|
|
|
@ -177,7 +177,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
.attr('y2', yPosition); |
|
|
|
|
return; |
|
|
|
|
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 { |
|
|
|
|
let columnIdx; // 0 for x value, 1 for y value,
|
|
|
|
|
let value; // xValue to y Value
|
|
|
|
|
switch(this.coreOptions.crosshair.orientation) { |
|
|
|
|
switch(this.options.crosshair.orientation) { |
|
|
|
|
case CrosshairOrientation.VERTICAL: |
|
|
|
|
columnIdx = 0; |
|
|
|
|
value = xValue; |
|
|
|
@ -219,7 +219,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
columnIdx = 1; |
|
|
|
|
value = yValue; |
|
|
|
|
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
|
|
|
|
@ -248,7 +248,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
// columnIdx: 1 for y, 0 for x
|
|
|
|
|
// inverval: x/y value interval between data points
|
|
|
|
|
// 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) { |
|
|
|
|
return undefined; |
|
|
|
|
} |
|
|
|
@ -272,7 +272,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
|
|
|
|
|
// TDOO: is shift key pressed
|
|
|
|
|
// TODO: need to refactor this object
|
|
|
|
|
this.coreOptions.callbackMouseMove({ |
|
|
|
|
this.options.callbackMouseMove({ |
|
|
|
|
x: d3.event.pageX, |
|
|
|
|
y: d3.event.pageY, |
|
|
|
|
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 }[] { |
|
|
|
|
if(!this.coreSeries.isSeriesAvailable) { |
|
|
|
|
if(!this.series.isSeriesAvailable) { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
if(closestDatapoint === undefined) { |
|
|
|
|
this.hideCrosshairCircle(serie.idx); |
|
|
|
@ -315,21 +315,21 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onMouseOut(): void { |
|
|
|
|
this.coreOptions.callbackMouseOut(); |
|
|
|
|
this.options.callbackMouseOut(); |
|
|
|
|
this.crosshair.style('display', 'none'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
|
if(d3.event.type === 'dblclick' && !this.isDoubleClickActive()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 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 yInterval = this.state.yValueRange[1] - this.state.yValueRange[0]; |
|
|
|
|
switch(orientation) { |
|
|
|
@ -364,7 +364,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
|
|
|
|
|
x: xAxisMiddleValue, |
|
|
|
|
y: yAxisMiddleValue |
|
|
|
|
} |
|
|
|
|
this.coreOptions.callbackZoomOut(centers); |
|
|
|
|
this.options.callbackZoomOut(centers); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|