|
|
@ -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,24 +680,33 @@ 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); |
|
|
|
const rescaleX = this.d3.event.transform.rescaleX(this.initScaleX); |
|
|
|
|
|
|
|
this.xAxisElement.call(this.d3.axisBottom(this.xScale).scale(rescaleX)); |
|
|
|
|
|
|
|
this.state.xValueRange = [rescaleX.invert(0), rescaleX.invert(this.width)]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if(panOrientation === PanOrientation.VERTICAL || panOrientation === PanOrientation.BOTH) { |
|
|
|
if(panOrientation === PanOrientation.VERTICAL || panOrientation === PanOrientation.BOTH) { |
|
|
|
this.state.transform = { y: event.transform.y }; |
|
|
|
this.rescaleAxisY(event.transform.y); |
|
|
|
const rescaleY = this.d3.event.transform.rescaleY(this.initScaleY); |
|
|
|
} |
|
|
|
this.yAxisElement.call(this.d3.axisLeft(this.yScale).scale(rescaleY)); |
|
|
|
} |
|
|
|
this.state.yValueRange = [rescaleY.invert(0), rescaleY.invert(this.height)]; |
|
|
|
|
|
|
|
if(this.y1AxisElement) { |
|
|
|
// TODO: refactor, divide between classes
|
|
|
|
const rescaleY1 = this.d3.event.transform.rescaleY(this.initScaleY1); |
|
|
|
rescaleAxisX(transformX: number): void { |
|
|
|
this.y1AxisElement.call(this.d3.axisLeft(this.y1Scale).scale(rescaleY1)); |
|
|
|
this.state.transform = { x: transformX }; |
|
|
|
this.state.y1ValueRange = [rescaleY1.invert(0), rescaleY1.invert(this.height)]; |
|
|
|
const rescaleX = this.d3.event.transform.rescaleX(this.initScaleX); |
|
|
|
// TODO: y1 axis jumps on panning
|
|
|
|
this.xAxisElement.call(this.d3.axisBottom(this.xScale).scale(rescaleX)); |
|
|
|
this.y1AxisElement.selectAll('line').attr('x2', 2); |
|
|
|
this.state.xValueRange = [rescaleX.invert(0), rescaleX.invert(this.width)]; |
|
|
|
this.y1AxisElement.selectAll('text').attr('x', 5); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rescaleAxisY(transformY: number): void { |
|
|
|
|
|
|
|
this.state.transform = { y: transformY }; |
|
|
|
|
|
|
|
const rescaleY = this.d3.event.transform.rescaleY(this.initScaleY); |
|
|
|
|
|
|
|
this.yAxisElement.call(this.d3.axisLeft(this.yScale).scale(rescaleY)); |
|
|
|
|
|
|
|
this.state.yValueRange = [rescaleY.invert(0), rescaleY.invert(this.height)]; |
|
|
|
|
|
|
|
if(this.y1AxisElement) { |
|
|
|
|
|
|
|
const rescaleY1 = this.d3.event.transform.rescaleY(this.initScaleY1); |
|
|
|
|
|
|
|
this.y1AxisElement.call(this.d3.axisLeft(this.y1Scale).scale(rescaleY1)); |
|
|
|
|
|
|
|
this.state.y1ValueRange = [rescaleY1.invert(0), rescaleY1.invert(this.height)]; |
|
|
|
|
|
|
|
// TODO: y1 axis jumps on panning
|
|
|
|
|
|
|
|
this.y1AxisElement.selectAll('line').attr('x2', 2); |
|
|
|
|
|
|
|
this.y1AxisElement.selectAll('text').attr('x', 5); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|