Skip to content

Commit e12ce7c

Browse files
committed
fix(charts): reversing scroll direction on touch devices and trackpads
Scroll direction is now natural which is the default for touch devices. Closes react-financial#57
1 parent 7494730 commit e12ce7c

File tree

4 files changed

+107
-86
lines changed

4 files changed

+107
-86
lines changed

.vscode/launch.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "chrome",
9+
"request": "launch",
10+
"name": "Launch Chrome against localhost",
11+
"sourceMaps": true,
12+
"url": "http://localhost:4444",
13+
"webRoot": "${workspaceFolder}"
14+
}
15+
]
16+
}

packages/charts/src/ChartCanvas.tsx

+18-7
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
725725
});
726726
}
727727
}
728+
728729
public handlePinchZoomEnd(initialPinch, e) {
729730
const { xAccessor } = this.state;
730731

@@ -751,6 +752,7 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
751752
});
752753
}
753754
}
755+
754756
public handleZoom(zoomDirection, mouseXY, e) {
755757
if (this.panInProgress) {
756758
return;
@@ -813,6 +815,7 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
813815
}
814816
});
815817
}
818+
816819
public xAxisZoom(newDomain) {
817820
const { xScale, plotData, chartConfig } = this.calculateStateForDomain(newDomain);
818821
this.clearThreeCanvas();
@@ -832,6 +835,7 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
832835
if (start < end) { onLoadMore(start, end); }
833836
});
834837
}
838+
835839
public yAxisZoom(chartId, newDomain) {
836840
this.clearThreeCanvas();
837841
const { chartConfig: initialChartConfig } = this.state;
@@ -873,17 +877,18 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
873877
}
874878
});
875879
}
880+
876881
public redraw() {
877882
this.clearThreeCanvas();
878883
this.draw({ force: true });
879884
}
885+
880886
public panHelper(mouseXY, initialXScale, { dx, dy }, chartsToPan) {
881887
const { xAccessor, displayXAccessor, chartConfig: initialChartConfig } = this.state;
882888
const { filterData } = this.state;
883889
const { fullData } = this;
884890
const { postCalculator } = this.props;
885891

886-
// console.log(dx, dy);
887892
if (isNotDefined(initialXScale.invert)) {
888893
throw new Error("xScale provided does not have an invert() method."
889894
+ "You are likely using an ordinal scale. This scale does not support zoom, pan");
@@ -904,7 +909,6 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
904909

905910
const updatedScale = initialXScale.copy().domain(domain);
906911
const plotData = postCalculator(beforePlotData);
907-
// console.log(last(plotData));
908912

909913
const currentItem = getCurrentItem(updatedScale, xAccessor, mouseXY, plotData);
910914
const chartConfig = getChartConfigWithUpdatedYScales(
@@ -916,7 +920,6 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
916920
);
917921
const currentCharts = getCurrentCharts(chartConfig, mouseXY);
918922

919-
// console.log(initialXScale.domain(), newDomain, updatedScale.domain());
920923
return {
921924
xScale: updatedScale,
922925
plotData,
@@ -926,6 +929,7 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
926929
currentItem,
927930
};
928931
}
932+
929933
public handlePan(mousePosition, panStartXScale, dxdy, chartsToPan, e) {
930934
if (!this.waitingForPanAnimationFrame) {
931935
this.waitingForPanAnimationFrame = true;
@@ -939,7 +943,6 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
939943
this.hackyWayToStopPanBeyondBounds__domain = state.xScale.domain();
940944

941945
this.panInProgress = true;
942-
// console.log(panStartXScale.domain(), state.xScale.domain());
943946

944947
this.triggerEvent("pan", state, e);
945948

@@ -955,15 +958,14 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
955958
});
956959
}
957960
}
961+
958962
public handlePanEnd(mousePosition, panStartXScale, dxdy, chartsToPan, e) {
959963
const state = this.panHelper(mousePosition, panStartXScale, dxdy, chartsToPan);
960-
// console.log(this.canvasDrawCallbackList.map(d => d.type));
961964
this.hackyWayToStopPanBeyondBounds__plotData = null;
962965
this.hackyWayToStopPanBeyondBounds__domain = null;
963966

964967
this.panInProgress = false;
965968

966-
// console.log("PANEND", panEnd++);
967969
const {
968970
xScale,
969971
plotData,
@@ -979,7 +981,6 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
979981
const firstItem = head(fullData);
980982
const start = head(xScale.domain());
981983
const end = xAccessor(firstItem);
982-
// console.log(start, end, start < end ? "Load more" : "I have it");
983984

984985
const { onLoadMore } = this.props;
985986

@@ -994,14 +995,17 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
994995
});
995996
});
996997
}
998+
997999
public handleMouseDown(mousePosition, currentCharts, e) {
9981000
this.triggerEvent("mousedown", this.mutableState, e);
9991001
}
1002+
10001003
public handleMouseEnter(e) {
10011004
this.triggerEvent("mouseenter", {
10021005
show: true,
10031006
}, e);
10041007
}
1008+
10051009
public handleMouseMove(mouseXY, inputType, e) {
10061010
if (!this.waitingForMouseMoveAnimationFrame) {
10071011
this.waitingForMouseMoveAnimationFrame = true;
@@ -1032,14 +1036,17 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
10321036
});
10331037
}
10341038
}
1039+
10351040
public handleMouseLeave(e) {
10361041
this.triggerEvent("mouseleave", { show: false }, e);
10371042
this.clearMouseCanvas();
10381043
this.draw({ trigger: "mouseleave" });
10391044
}
1045+
10401046
public handleDragStart({ startPos }, e) {
10411047
this.triggerEvent("dragstart", { startPos }, e);
10421048
}
1049+
10431050
public handleDrag({ startPos, mouseXY }, e) {
10441051
const { chartConfig, plotData, xScale, xAccessor } = this.state;
10451052
const currentCharts = getCurrentCharts(chartConfig, mouseXY);
@@ -1063,6 +1070,7 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
10631070
this.draw({ trigger: "drag" });
10641071
});
10651072
}
1073+
10661074
public handleDragEnd({ mouseXY }, e) {
10671075
this.triggerEvent("dragend", { mouseXY }, e);
10681076

@@ -1071,6 +1079,7 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
10711079
this.draw({ trigger: "dragend" });
10721080
});
10731081
}
1082+
10741083
public handleClick(mousePosition, e) {
10751084
this.triggerEvent("click", this.mutableState, e);
10761085

@@ -1079,9 +1088,11 @@ export class ChartCanvas extends React.Component<ChartCanvasProps, ChartCanvasSt
10791088
this.draw({ trigger: "click" });
10801089
});
10811090
}
1091+
10821092
public handleDoubleClick(mousePosition, e) {
10831093
this.triggerEvent("dblclick", {}, e);
10841094
}
1095+
10851096
public getChildContext() {
10861097
const dimensions = getDimensions(this.props);
10871098
return {

0 commit comments

Comments
 (0)