|
|
@ -71,6 +71,7 @@ const DEFAULT_OPTIONS: Options = { |
|
|
|
zoom: { |
|
|
|
zoom: { |
|
|
|
isActive: true, |
|
|
|
isActive: true, |
|
|
|
keyEvent: KeyEvent.MAIN, |
|
|
|
keyEvent: KeyEvent.MAIN, |
|
|
|
|
|
|
|
orientation: PanOrientation.BOTH, |
|
|
|
}, |
|
|
|
}, |
|
|
|
pan: { |
|
|
|
pan: { |
|
|
|
isActive: false, |
|
|
|
isActive: false, |
|
|
@ -648,7 +649,27 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if(scrollZoomOptions.isActive === true && this.isD3EventKeyEqualOption(event, scrollZoomOptions.keyEvent)) { |
|
|
|
if(scrollZoomOptions.isActive === true && this.isD3EventKeyEqualOption(event, scrollZoomOptions.keyEvent)) { |
|
|
|
this.state.transform = { k: event.transform.k }; |
|
|
|
const orientation = scrollZoomOptions.orientation; |
|
|
|
|
|
|
|
let k; |
|
|
|
|
|
|
|
switch(orientation) { |
|
|
|
|
|
|
|
case PanOrientation.HORIZONTAL: |
|
|
|
|
|
|
|
k = `${event.transform.k},1`; |
|
|
|
|
|
|
|
this.rescaleAxisX(event.transform.x); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case PanOrientation.VERTICAL: |
|
|
|
|
|
|
|
k = `1,${event.transform.k}`; |
|
|
|
|
|
|
|
this.rescaleAxisY(event.transform.y); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case PanOrientation.BOTH: |
|
|
|
|
|
|
|
k = event.transform.k; |
|
|
|
|
|
|
|
this.rescaleAxisX(event.transform.x); |
|
|
|
|
|
|
|
this.rescaleAxisY(event.transform.y); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new Error(`Unknown type of PanOrientation: ${orientation}`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.state.transform.k = k; |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const isPanActive = this.options.zoomEvents.mouse.pan.isActive; |
|
|
|
const isPanActive = this.options.zoomEvents.mouse.pan.isActive; |
|
|
@ -659,13 +680,23 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> { |
|
|
|
|
|
|
|
|
|
|
|
const panOrientation = this.options.zoomEvents.mouse.pan.orientation; |
|
|
|
const panOrientation = this.options.zoomEvents.mouse.pan.orientation; |
|
|
|
if(panOrientation === PanOrientation.HORIZONTAL || panOrientation === PanOrientation.BOTH) { |
|
|
|
if(panOrientation === PanOrientation.HORIZONTAL || panOrientation === PanOrientation.BOTH) { |
|
|
|
this.state.transform = { x: event.transform.x }; |
|
|
|
this.rescaleAxisX(event.transform.x); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(panOrientation === PanOrientation.VERTICAL || panOrientation === PanOrientation.BOTH) { |
|
|
|
|
|
|
|
this.rescaleAxisY(event.transform.y); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: refactor, divide between classes
|
|
|
|
|
|
|
|
rescaleAxisX(transformX: number): void { |
|
|
|
|
|
|
|
this.state.transform = { x: transformX }; |
|
|
|
const rescaleX = this.d3.event.transform.rescaleX(this.initScaleX); |
|
|
|
const rescaleX = this.d3.event.transform.rescaleX(this.initScaleX); |
|
|
|
this.xAxisElement.call(this.d3.axisBottom(this.xScale).scale(rescaleX)); |
|
|
|
this.xAxisElement.call(this.d3.axisBottom(this.xScale).scale(rescaleX)); |
|
|
|
this.state.xValueRange = [rescaleX.invert(0), rescaleX.invert(this.width)]; |
|
|
|
this.state.xValueRange = [rescaleX.invert(0), rescaleX.invert(this.width)]; |
|
|
|
} |
|
|
|
} |
|
|
|
if(panOrientation === PanOrientation.VERTICAL || panOrientation === PanOrientation.BOTH) { |
|
|
|
|
|
|
|
this.state.transform = { y: event.transform.y }; |
|
|
|
rescaleAxisY(transformY: number): void { |
|
|
|
|
|
|
|
this.state.transform = { y: transformY }; |
|
|
|
const rescaleY = this.d3.event.transform.rescaleY(this.initScaleY); |
|
|
|
const rescaleY = this.d3.event.transform.rescaleY(this.initScaleY); |
|
|
|
this.yAxisElement.call(this.d3.axisLeft(this.yScale).scale(rescaleY)); |
|
|
|
this.yAxisElement.call(this.d3.axisLeft(this.yScale).scale(rescaleY)); |
|
|
|
this.state.yValueRange = [rescaleY.invert(0), rescaleY.invert(this.height)]; |
|
|
|
this.state.yValueRange = [rescaleY.invert(0), rescaleY.invert(this.height)]; |
|
|
@ -678,7 +709,6 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> { |
|
|
|
this.y1AxisElement.selectAll('text').attr('x', 5); |
|
|
|
this.y1AxisElement.selectAll('text').attr('x', 5); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected onScrollPanningRescale(event: d3.D3ZoomEvent<any, any>): void { |
|
|
|
protected onScrollPanningRescale(event: d3.D3ZoomEvent<any, any>): void { |
|
|
|
const scrollPanOptions = this.options.zoomEvents.scroll.pan; |
|
|
|
const scrollPanOptions = this.options.zoomEvents.scroll.pan; |
|
|
|