|
|
@ -1,4 +1,3 @@ |
|
|
|
import { AxisRange } from './types'; |
|
|
|
|
|
|
|
import VueChartwerkPodMixin from './VueChartwerkPodMixin'; |
|
|
|
import VueChartwerkPodMixin from './VueChartwerkPodMixin'; |
|
|
|
import { Grid } from './components/grid'; |
|
|
|
import { Grid } from './components/grid'; |
|
|
|
|
|
|
|
|
|
|
@ -31,13 +30,15 @@ import { palette } from './colors'; |
|
|
|
|
|
|
|
|
|
|
|
import * as d3 from 'd3'; |
|
|
|
import * as d3 from 'd3'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import first from 'lodash/first'; |
|
|
|
|
|
|
|
import last from 'lodash/last'; |
|
|
|
import debounce from 'lodash/debounce'; |
|
|
|
import debounce from 'lodash/debounce'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const DEFAULT_TICK_SIZE = 2; |
|
|
|
const DEFAULT_TICK_SIZE = 2; |
|
|
|
|
|
|
|
const MILISECONDS_IN_MINUTE = 60 * 1000; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected series: CoreSeries<T>; |
|
|
|
protected series: CoreSeries<T>; |
|
|
|
protected options: CoreOptions<O>; |
|
|
|
protected options: CoreOptions<O>; |
|
|
@ -79,8 +80,7 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
_series: T[] = [], |
|
|
|
_series: T[] = [], |
|
|
|
_options: O |
|
|
|
_options: O |
|
|
|
) { |
|
|
|
) { |
|
|
|
// need to call explicitly because option lazyStyleTag
|
|
|
|
// TODO: test if it's necessary
|
|
|
|
// in webpack style-loader
|
|
|
|
|
|
|
|
styles.use(); |
|
|
|
styles.use(); |
|
|
|
|
|
|
|
|
|
|
|
this.options = new CoreOptions(_options); |
|
|
|
this.options = new CoreOptions(_options); |
|
|
@ -116,7 +116,6 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
|
|
|
|
|
|
|
|
this.renderLegend(); |
|
|
|
this.renderLegend(); |
|
|
|
this.renderYLabel(); |
|
|
|
this.renderYLabel(); |
|
|
|
this.renderY1Label(); |
|
|
|
|
|
|
|
this.renderXLabel(); |
|
|
|
this.renderXLabel(); |
|
|
|
|
|
|
|
|
|
|
|
this.options.callbackRenderEnd(); |
|
|
|
this.options.callbackRenderEnd(); |
|
|
@ -153,13 +152,12 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
this.series.updateSeries(newSeries); |
|
|
|
this.series.updateSeries(newSeries); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected renderMetrics(): void {} |
|
|
|
protected abstract renderMetrics(): void; |
|
|
|
protected onMouseOver(): void {} |
|
|
|
protected abstract onMouseOver(): void; |
|
|
|
protected onMouseOut(): void {} |
|
|
|
protected abstract onMouseOut(): void; |
|
|
|
protected onMouseMove(): void {} |
|
|
|
protected abstract onMouseMove(): void; |
|
|
|
protected onMouseClick(): void {} |
|
|
|
public abstract renderSharedCrosshair(values: { x?: number, y?: number }): void; |
|
|
|
public renderSharedCrosshair(values: { x?: number, y?: number }): void {} |
|
|
|
public abstract hideSharedCrosshair(): void; |
|
|
|
public hideSharedCrosshair(): void {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected initPodState(): void { |
|
|
|
protected initPodState(): void { |
|
|
|
const boxPararms = { |
|
|
|
const boxPararms = { |
|
|
@ -329,21 +327,12 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
// TODO: refactor for a new mouse/scroll events
|
|
|
|
// TODO: refactor for a new mouse/scroll events
|
|
|
|
const panKeyEvent = this.options.mousePanEvent.keyEvent; |
|
|
|
const panKeyEvent = this.options.mousePanEvent.keyEvent; |
|
|
|
const isPanActive = this.options.mousePanEvent.isActive; |
|
|
|
const isPanActive = this.options.mousePanEvent.isActive; |
|
|
|
const isBrushActive = this.options.mouseZoomEvent.isActive; |
|
|
|
if(isPanActive === true && panKeyEvent === KeyEvent.MAIN) { |
|
|
|
if(panKeyEvent === KeyEvent.MAIN) { |
|
|
|
this.initPan(); |
|
|
|
if(isPanActive) { |
|
|
|
this.initBrush(); |
|
|
|
this.initPan(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(isBrushActive) { |
|
|
|
|
|
|
|
this.initBrush(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if(isBrushActive) { |
|
|
|
this.initBrush(); |
|
|
|
this.initBrush(); |
|
|
|
this.initPan(); |
|
|
|
} |
|
|
|
|
|
|
|
if(isPanActive) { |
|
|
|
|
|
|
|
this.initPan(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
this.ensureOverlayExisting(); |
|
|
|
this.ensureOverlayExisting(); |
|
|
|
|
|
|
|
|
|
|
@ -352,7 +341,6 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
.on('mouseover', this.onMouseOver.bind(this)) |
|
|
|
.on('mouseover', this.onMouseOver.bind(this)) |
|
|
|
.on('mouseout', this.onMouseOut.bind(this)) |
|
|
|
.on('mouseout', this.onMouseOut.bind(this)) |
|
|
|
.on('mousemove', this.onMouseMove.bind(this)) |
|
|
|
.on('mousemove', this.onMouseMove.bind(this)) |
|
|
|
.on('click', this.onMouseClick.bind(this)) |
|
|
|
|
|
|
|
.on('dblclick', () => { |
|
|
|
.on('dblclick', () => { |
|
|
|
d3.event.stopPropagation(); |
|
|
|
d3.event.stopPropagation(); |
|
|
|
// TODO: add the same check as we have in line-pod
|
|
|
|
// TODO: add the same check as we have in line-pod
|
|
|
@ -384,6 +372,10 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected initBrush(): void { |
|
|
|
protected initBrush(): void { |
|
|
|
|
|
|
|
const isBrushActive = this.options.mouseZoomEvent.isActive; |
|
|
|
|
|
|
|
if(isBrushActive === false) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
switch(this.options.mouseZoomEvent.orientation) { |
|
|
|
switch(this.options.mouseZoomEvent.orientation) { |
|
|
|
case BrushOrientation.VERTICAL: |
|
|
|
case BrushOrientation.VERTICAL: |
|
|
|
this.brush = d3.brushY(); |
|
|
|
this.brush = d3.brushY(); |
|
|
@ -417,9 +409,9 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
// TODO: refactor
|
|
|
|
// TODO: refactor
|
|
|
|
switch(key) { |
|
|
|
switch(key) { |
|
|
|
case KeyEvent.MAIN: |
|
|
|
case KeyEvent.MAIN: |
|
|
|
return () => !d3.event.shiftKey && !d3.event.button; |
|
|
|
return () => !d3.event.shiftKey; |
|
|
|
case KeyEvent.SHIFT: |
|
|
|
case KeyEvent.SHIFT: |
|
|
|
return () => d3.event.shiftKey && !d3.event.button; |
|
|
|
return () => d3.event.shiftKey; |
|
|
|
default: |
|
|
|
default: |
|
|
|
throw new Error(`Unknown type of KeyEvent: ${key}`); |
|
|
|
throw new Error(`Unknown type of KeyEvent: ${key}`); |
|
|
|
} |
|
|
|
} |
|
|
@ -510,8 +502,8 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this.chartContainer.append('text') |
|
|
|
this.chartContainer.append('text') |
|
|
|
.attr('y', -this.margin.left) |
|
|
|
.attr('y', 0 - this.margin.left) |
|
|
|
.attr('x', -(this.height / 2)) |
|
|
|
.attr('x', 0 - (this.height / 2)) |
|
|
|
.attr('dy', '1em') |
|
|
|
.attr('dy', '1em') |
|
|
|
.attr('class', 'y-axis-label') |
|
|
|
.attr('class', 'y-axis-label') |
|
|
|
.attr('transform', 'rotate(-90)') |
|
|
|
.attr('transform', 'rotate(-90)') |
|
|
@ -521,22 +513,6 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
.text(this.options.axis.y.label); |
|
|
|
.text(this.options.axis.y.label); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected renderY1Label(): void { |
|
|
|
|
|
|
|
if(this.options.axis.y1?.label === undefined) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.chartContainer.append('text') |
|
|
|
|
|
|
|
.attr('y', -this.width - this.margin.right) |
|
|
|
|
|
|
|
.attr('x', (this.height / 2)) |
|
|
|
|
|
|
|
.attr('dy', '1em') |
|
|
|
|
|
|
|
.attr('class', 'y-axis-label') |
|
|
|
|
|
|
|
.attr('transform', 'rotate(90)') |
|
|
|
|
|
|
|
.style('text-anchor', 'middle') |
|
|
|
|
|
|
|
.style('font-size', '14px') |
|
|
|
|
|
|
|
.style('fill', 'currentColor') |
|
|
|
|
|
|
|
.text(this.options.axis.y1.label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected renderXLabel(): void { |
|
|
|
protected renderXLabel(): void { |
|
|
|
if(this.options.axis.x.label === undefined) { |
|
|
|
if(this.options.axis.x.label === undefined) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -817,7 +793,8 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
this.state.yValueRange = yRange; |
|
|
|
this.state.yValueRange = yRange; |
|
|
|
this.brushStartSelection = null; |
|
|
|
this.brushStartSelection = null; |
|
|
|
} |
|
|
|
} |
|
|
|
this.zoomIn([xRange, yRange]); |
|
|
|
|
|
|
|
|
|
|
|
this.options.callbackZoomIn([xRange, yRange]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected zoomOut(): void { |
|
|
|
protected zoomOut(): void { |
|
|
@ -830,10 +807,6 @@ class ChartwerkPod<T extends Serie, O extends Options> { |
|
|
|
this.options.callbackZoomOut(centers); |
|
|
|
this.options.callbackZoomOut(centers); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected zoomIn(ranges: AxisRange[]): void { |
|
|
|
|
|
|
|
this.options.callbackZoomIn(ranges); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getAxisTicksFormatter(axisOptions: AxisOption): (d: any, i: number) => any { |
|
|
|
getAxisTicksFormatter(axisOptions: AxisOption): (d: any, i: number) => any { |
|
|
|
// TODO: ticksCount === 0 -> suspicious option
|
|
|
|
// TODO: ticksCount === 0 -> suspicious option
|
|
|
|
if(axisOptions.ticksCount === 0) { |
|
|
|
if(axisOptions.ticksCount === 0) { |
|
|
|