|
|
@ -1,5 +1,6 @@ |
|
|
|
import VueChartwerkPodMixin from './VueChartwerkPodMixin'; |
|
|
|
import VueChartwerkPodMixin from './VueChartwerkPodMixin'; |
|
|
|
import { PodState } from './state'; |
|
|
|
import { PodState } from './state'; |
|
|
|
|
|
|
|
import { Grid } from './components/grid'; |
|
|
|
|
|
|
|
|
|
|
|
import styles from './css/style.css'; |
|
|
|
import styles from './css/style.css'; |
|
|
|
|
|
|
|
|
|
|
@ -17,7 +18,8 @@ import { |
|
|
|
PanOrientation, |
|
|
|
PanOrientation, |
|
|
|
yAxisOrientation, |
|
|
|
yAxisOrientation, |
|
|
|
ScrollPanOrientation, |
|
|
|
ScrollPanOrientation, |
|
|
|
AxisOption |
|
|
|
AxisOption, |
|
|
|
|
|
|
|
SvgElOptions, |
|
|
|
} from './types'; |
|
|
|
} from './types'; |
|
|
|
import { uid } from './utils'; |
|
|
|
import { uid } from './utils'; |
|
|
|
import { palette } from './colors'; |
|
|
|
import { palette } from './colors'; |
|
|
@ -101,16 +103,6 @@ const DEFAULT_OPTIONS: Options = { |
|
|
|
format: AxisFormat.NUMERIC |
|
|
|
format: AxisFormat.NUMERIC |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
grid: { |
|
|
|
|
|
|
|
x: { |
|
|
|
|
|
|
|
isActive: true, |
|
|
|
|
|
|
|
ticksCount: 5, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
y: { |
|
|
|
|
|
|
|
isActive: true, |
|
|
|
|
|
|
|
ticksCount: 5, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
crosshair: { |
|
|
|
crosshair: { |
|
|
|
orientation: CrosshairOrientation.VERTICAL, |
|
|
|
orientation: CrosshairOrientation.VERTICAL, |
|
|
|
color: 'red' |
|
|
|
color: 'red' |
|
|
@ -146,6 +138,9 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> { |
|
|
|
protected deltaYTransform = 0; |
|
|
|
protected deltaYTransform = 0; |
|
|
|
protected debouncedRender = debounce(this.render.bind(this), 100); |
|
|
|
protected debouncedRender = debounce(this.render.bind(this), 100); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// components
|
|
|
|
|
|
|
|
protected grid: Grid; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: test variables instead of functions with cache
|
|
|
|
// TODO: test variables instead of functions with cache
|
|
|
|
private _xScale: d3.ScaleLinear<number, number> | null = null; |
|
|
|
private _xScale: d3.ScaleLinear<number, number> | null = null; |
|
|
|
private _yScale: d3.ScaleLinear<number, number> | null = null; |
|
|
|
private _yScale: d3.ScaleLinear<number, number> | null = null; |
|
|
@ -172,6 +167,9 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> { |
|
|
|
|
|
|
|
|
|
|
|
this.d3Node = this.d3.select(this.el); |
|
|
|
this.d3Node = this.d3.select(this.el); |
|
|
|
this.addEventListeners(); |
|
|
|
this.addEventListeners(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.createSvg(); |
|
|
|
|
|
|
|
this.initComponents(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected addEventListeners(): void { |
|
|
|
protected addEventListeners(): void { |
|
|
@ -185,7 +183,6 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> { |
|
|
|
public render(): void { |
|
|
|
public render(): void { |
|
|
|
this.clearScaleCache(); |
|
|
|
this.clearScaleCache(); |
|
|
|
|
|
|
|
|
|
|
|
this.renderSvg(); |
|
|
|
|
|
|
|
this.renderAxes(); |
|
|
|
this.renderAxes(); |
|
|
|
this.renderGrid(); |
|
|
|
this.renderGrid(); |
|
|
|
|
|
|
|
|
|
|
@ -237,11 +234,23 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> { |
|
|
|
public abstract renderSharedCrosshair(values: { x?: number, y?: number }): void; |
|
|
|
public abstract renderSharedCrosshair(values: { x?: number, y?: number }): void; |
|
|
|
public abstract hideSharedCrosshair(): void; |
|
|
|
public abstract hideSharedCrosshair(): void; |
|
|
|
|
|
|
|
|
|
|
|
protected initPodState() { |
|
|
|
protected initPodState(): void { |
|
|
|
this.state = new PodState(this.options); |
|
|
|
this.state = new PodState(this.options); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected renderSvg(): void { |
|
|
|
protected initComponents(): void { |
|
|
|
|
|
|
|
// TODO: make chartContainer a separate class with SvgElOptions inside to avoid duplication
|
|
|
|
|
|
|
|
const svgElOptions = { |
|
|
|
|
|
|
|
height: this.height, |
|
|
|
|
|
|
|
width: this.width, |
|
|
|
|
|
|
|
xScale: this.xScale, |
|
|
|
|
|
|
|
yScale: this.yScale, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.grid = new Grid(this.d3, this.chartContainer, svgElOptions, this.options.grid); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected createSvg(): void { |
|
|
|
this.d3Node.select('svg').remove(); |
|
|
|
this.d3Node.select('svg').remove(); |
|
|
|
this.svg = this.d3Node |
|
|
|
this.svg = this.d3Node |
|
|
|
.append('svg') |
|
|
|
.append('svg') |
|
|
@ -254,40 +263,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected renderGrid(): void { |
|
|
|
protected renderGrid(): void { |
|
|
|
this.chartContainer.selectAll('.grid').remove(); |
|
|
|
this.grid.render(); |
|
|
|
|
|
|
|
|
|
|
|
if(this.options.grid.x.isActive) { |
|
|
|
|
|
|
|
this.chartContainer |
|
|
|
|
|
|
|
.append('g') |
|
|
|
|
|
|
|
.attr('transform', `translate(0,${this.height})`) |
|
|
|
|
|
|
|
.attr('class', 'grid x-grid') |
|
|
|
|
|
|
|
.style('pointer-events', 'none') |
|
|
|
|
|
|
|
.call( |
|
|
|
|
|
|
|
this.d3.axisBottom(this.xScale) |
|
|
|
|
|
|
|
.ticks(this.options.grid.x.ticksCount) |
|
|
|
|
|
|
|
.tickSize(-this.height) |
|
|
|
|
|
|
|
.tickFormat(() => '') |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.options.grid.y.isActive) { |
|
|
|
|
|
|
|
this.chartContainer |
|
|
|
|
|
|
|
.append('g') |
|
|
|
|
|
|
|
.attr('class', 'grid y-grid') |
|
|
|
|
|
|
|
.style('pointer-events', 'none') |
|
|
|
|
|
|
|
.call( |
|
|
|
|
|
|
|
this.d3.axisLeft(this.yScale) |
|
|
|
|
|
|
|
.ticks(this.options.grid.y.ticksCount) |
|
|
|
|
|
|
|
.tickSize(-this.width) |
|
|
|
|
|
|
|
.tickFormat(() => '') |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.chartContainer.selectAll('.grid').selectAll('.tick') |
|
|
|
|
|
|
|
.attr('opacity', '0.5'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.chartContainer.selectAll('.grid').select('.domain') |
|
|
|
|
|
|
|
.style('pointer-events', 'none'); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected renderAxes(): void { |
|
|
|
protected renderAxes(): void { |
|
|
|