|
|
@ -1,5 +1,5 @@ |
|
|
|
import { ChartwerkPod, VueChartwerkPodMixin, TimeFormat, CrosshairOrientation, BrushOrientation, yAxisOrientation } from '@chartwerk/core'; |
|
|
|
import { ChartwerkPod, VueChartwerkPodMixin, TimeFormat, CrosshairOrientation, BrushOrientation, yAxisOrientation } from '@chartwerk/core'; |
|
|
|
import { LineTimeSerie, LineOptions, MouseObj } from './types'; |
|
|
|
import { LineTimeSerie, LineOptions, MouseObj, AreaType } from './types'; |
|
|
|
import { Markers } from './components/markers'; |
|
|
|
import { Markers } from './components/markers'; |
|
|
|
import { Segments } from './components/segments'; |
|
|
|
import { Segments } from './components/segments'; |
|
|
|
|
|
|
|
|
|
|
@ -14,14 +14,9 @@ const METRIC_CIRCLE_RADIUS = 1.5; |
|
|
|
const CROSSHAIR_CIRCLE_RADIUS = 3; |
|
|
|
const CROSSHAIR_CIRCLE_RADIUS = 3; |
|
|
|
const CROSSHAIR_BACKGROUND_RAIDUS = 9; |
|
|
|
const CROSSHAIR_BACKGROUND_RAIDUS = 9; |
|
|
|
const CROSSHAIR_BACKGROUND_OPACITY = 0.3; |
|
|
|
const CROSSHAIR_BACKGROUND_OPACITY = 0.3; |
|
|
|
|
|
|
|
type Generator = d3.Line<[number, number]> | d3.Area<[number, number]>; |
|
|
|
|
|
|
|
|
|
|
|
class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
lineGenerator = null; |
|
|
|
|
|
|
|
areaGenerator = null; |
|
|
|
|
|
|
|
lineGeneratorY1 = null; |
|
|
|
|
|
|
|
areaGeneratorY1 = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private _markersLayer: Markers = null; |
|
|
|
private _markersLayer: Markers = null; |
|
|
|
private _segmentsLayer: Segments = null; |
|
|
|
private _segmentsLayer: Segments = null; |
|
|
|
|
|
|
|
|
|
|
@ -37,18 +32,18 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override renderMetrics(): void { |
|
|
|
override renderMetrics(): void { |
|
|
|
|
|
|
|
console.log('renderMetrics1'); |
|
|
|
this.clearAllMetrics(); |
|
|
|
this.clearAllMetrics(); |
|
|
|
|
|
|
|
|
|
|
|
this.updateCrosshair(); |
|
|
|
this.updateCrosshair(); |
|
|
|
this.initLineGenerator(); |
|
|
|
|
|
|
|
this.initAreaGenerator(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!this.series.isSeriesAvailable) { |
|
|
|
if(!this.series.isSeriesAvailable) { |
|
|
|
this.renderNoDataPointsMessage(); |
|
|
|
this.renderNoDataPointsMessage(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
for(const serie of this.series.visibleSeries) { |
|
|
|
for(const serie of this.series.visibleSeries) { |
|
|
|
this._renderMetric(serie); |
|
|
|
const generator = this.getRenderGenerator(serie.renderArea, serie.yOrientation); |
|
|
|
|
|
|
|
this._renderMetric(serie, generator); |
|
|
|
} |
|
|
|
} |
|
|
|
if(this._markersConf !== undefined) { |
|
|
|
if(this._markersConf !== undefined) { |
|
|
|
this._markersLayer = new Markers(this.d3Node, this._markersConf, this.state, this.margin); |
|
|
|
this._markersLayer = new Markers(this.d3Node, this._markersConf, this.state, this.margin); |
|
|
@ -65,31 +60,28 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
this._markersLayer?.clear(); |
|
|
|
this._markersLayer?.clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
initLineGenerator(): void { |
|
|
|
|
|
|
|
this.lineGenerator = d3.line() |
|
|
|
|
|
|
|
.x(d => this.state.xScale(d[0])) |
|
|
|
|
|
|
|
.y(d => this.state.yScale(d[1])); |
|
|
|
|
|
|
|
this.lineGeneratorY1 = d3.line() |
|
|
|
|
|
|
|
.x(d => this.state.xScale(d[0])) |
|
|
|
|
|
|
|
.y(d => this.state.y1Scale(d[1])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initAreaGenerator(): void { |
|
|
|
getRenderGenerator(renderArea: AreaType, yOrientation: yAxisOrientation): Generator { |
|
|
|
this.areaGenerator = d3.area() |
|
|
|
const yScale = yOrientation === yAxisOrientation.LEFT ? this.state.yScale : this.state.y1Scale; |
|
|
|
|
|
|
|
switch(renderArea) { |
|
|
|
|
|
|
|
case AreaType.NONE: |
|
|
|
|
|
|
|
// return line generator
|
|
|
|
|
|
|
|
return d3.line() |
|
|
|
.x(d => this.state.xScale(d[0])) |
|
|
|
.x(d => this.state.xScale(d[0])) |
|
|
|
.y1(d => this.state.yScale(d[1])) |
|
|
|
.y(d => yScale(d[1])); |
|
|
|
.y0(d => this.height); |
|
|
|
case AreaType.ABOVE: |
|
|
|
this.areaGeneratorY1 = d3.area() |
|
|
|
return d3.area() |
|
|
|
.x(d => this.state.xScale(d[0])) |
|
|
|
.x(d => this.state.xScale(d[0])) |
|
|
|
.y1(d => this.state.y1Scale(d[1])) |
|
|
|
.y0(this.height) |
|
|
|
.y0(d => this.height); |
|
|
|
.y1(d => yScale(d[1])); |
|
|
|
} |
|
|
|
case AreaType.BELOW: |
|
|
|
|
|
|
|
return d3.area() |
|
|
|
getRenderGenerator(renderArea: boolean, yOrientation: yAxisOrientation): any { |
|
|
|
.x(d => this.state.xScale(d[0])) |
|
|
|
if(renderArea) { |
|
|
|
.y0(d => yScale(d[1])) |
|
|
|
return yOrientation === yAxisOrientation.LEFT ? this.areaGenerator : this.areaGeneratorY1; |
|
|
|
.y1(0); |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new Error(`Unknown type of renderArea: ${renderArea}`); |
|
|
|
} |
|
|
|
} |
|
|
|
return yOrientation === yAxisOrientation.LEFT ? this.lineGenerator : this.lineGeneratorY1; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_renderDots(serie: LineTimeSerie): void { |
|
|
|
_renderDots(serie: LineTimeSerie): void { |
|
|
@ -105,9 +97,9 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
.attr('cy', d => this.state.getYScaleByOrientation(serie.yOrientation)(d[1])); |
|
|
|
.attr('cy', d => this.state.getYScaleByOrientation(serie.yOrientation)(d[1])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_renderLines(serie: LineTimeSerie): void { |
|
|
|
_renderLines(serie: LineTimeSerie, generator: Generator): void { |
|
|
|
const fillColor = serie.renderArea ? serie.color : 'none'; |
|
|
|
const fillColor = serie.renderArea !== AreaType.NONE ? serie.color : 'none'; |
|
|
|
const fillOpacity = serie.renderArea ? 0.5 : 'none'; |
|
|
|
const fillOpacity = serie.renderArea !== AreaType.NONE ? 0.5 : 'none'; |
|
|
|
|
|
|
|
|
|
|
|
this.metricContainer |
|
|
|
this.metricContainer |
|
|
|
.append('path') |
|
|
|
.append('path') |
|
|
@ -120,12 +112,12 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { |
|
|
|
.attr('stroke-opacity', 0.7) |
|
|
|
.attr('stroke-opacity', 0.7) |
|
|
|
.attr('pointer-events', 'none') |
|
|
|
.attr('pointer-events', 'none') |
|
|
|
.style('stroke-dasharray', serie.dashArray) |
|
|
|
.style('stroke-dasharray', serie.dashArray) |
|
|
|
.attr('d', this.getRenderGenerator(serie.renderArea, serie.yOrientation)); |
|
|
|
.attr('d', generator); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_renderMetric(serie: LineTimeSerie): void { |
|
|
|
_renderMetric(serie: LineTimeSerie, generator: Generator): void { |
|
|
|
if(serie.renderLines === true) { |
|
|
|
if(serie.renderLines === true) { |
|
|
|
this._renderLines(serie); |
|
|
|
this._renderLines(serie, generator); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(serie.renderDots === true) { |
|
|
|
if(serie.renderDots === true) { |
|
|
@ -490,4 +482,4 @@ export const VueChartwerkLinePod = { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export { LineTimeSerie, LineOptions, TimeFormat, LinePod }; |
|
|
|
export { LineTimeSerie, LineOptions, TimeFormat, LinePod, AreaType }; |
|
|
|