-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
demo.js
178 lines (166 loc) · 5.13 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
To do
- Remove chart.plotLeft, chart.plotTop from the calculations. Check axis
positioning.
- When to show reset zoom button? Not on mousewheel.
- Try replacing `minPixelPadding` translation roundtrip with `minPointOffset`.
It should mean the same.
- Rename `panningState` to `allExtremes`, having properties `dataMin` and
`dataMax`. Then it can be spread right into the extremes object if defined.
Also checked for `cropped` to avoid doing this for nothing.
- Refactor: touchpan and zoom now uses basically the same chart.axes.filter
expression
- Clean up mouseDownX, mouseDownY, lastTouches, pinchStart. See if we can store
one single event instead.
- MouseWheel hard to start when minPadding and maxPadding since
`allowZoomOutside` change. Check out if minPadding, maxPadding and threshold
can be refactored out and shared with setTickPositions.
- Check if marker/attr stuff is necessary in `getSelectionBox`. Simple .getBBox
should be sufficient.
*/
(async () => {
const data = await fetch(
'https://cdn.jsdelivr.net/gh/highcharts/highcharts@v10.3.3/samples/data/usdeur.json'
).then(response => response.json())
.then(data =>
data.map(p => p[1])
.slice(0, 20)
);
Highcharts.chart('container', {
chart: {
zoomType: 'xy',
panning: {
enabled: true
},
mouseWheel: {
enabled: true
},
panKey: 'shift',
width: 600
},
title: {
text: 'USD to EUR exchange rate over time',
align: 'left'
},
subtitle: {
text: document.ontouchstart === undefined ?
'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in',
align: 'left'
},
yAxis: {
title: {
text: 'Exchange rate'
}
},
tooltip: {
followTouchMove: false,
followPointer: true
},
legend: {
enabled: false
},
rangeSelector: {
selected: 2
},
plotOptions: {
area: {
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
},
marker: {
radius: 2
},
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
threshold: null
}
},
series: [{
type: 'column',
name: 'USD to EUR',
data
}]
});
/* eslint-disable-next-line no-extend-native */
Array.prototype.item = function (i) {
// eslint-disable-line no-extend-native
return this[i];
};
/*
setTimeout(function () {
const chart = Highcharts.charts[0],
offset = Highcharts.offset(chart.container);
// Perform dual touch zoom
chart.pointer.onContainerTouchStart({
type: 'touchstart',
touches: [
{
pageX: 200 + offset.left,
pageY: 100 + offset.top
},
{
pageX: 300 + offset.left,
pageY: 150 + offset.top
}
],
preventDefault: function () {}
});
chart.pointer.onContainerTouchMove({
type: 'touchmove',
touches: [
{
pageX: 180 + offset.left,
pageY: 80 + offset.top
},
{
pageX: 350 + offset.left,
pageY: 170 + offset.top
}
],
preventDefault: function () {}
});
setTimeout(function () {
chart.pointer.onContainerTouchMove({
type: 'touchmove',
touches: [
{
pageX: 200 + offset.left,
pageY: 100 + offset.top
},
{
pageX: 300 + offset.left,
pageY: 150 + offset.top
}
],
preventDefault: function () {}
});
chart.pointer.onDocumentTouchEnd({
type: 'touchend',
touches: [
{
pageX: 200 + offset.left,
pageY: 100 + offset.top
},
{
pageX: 300 + offset.left,
pageY: 150 + offset.top
}
]
});
}, 500);
}, 1000);
// */
})();