Skip to content

Commit a0054bc

Browse files
committed
v5.5.1
1 parent 1097ead commit a0054bc

File tree

6 files changed

+78
-14
lines changed

6 files changed

+78
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netdata/charts",
3-
"version": "5.5.0",
3+
"version": "5.5.1",
44
"description": "Netdata frontend SDK and chart utilities",
55
"main": "dist/index.js",
66
"module": "dist/es6/index.js",

src/chartLibraries/dygraph/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import makeHoverX from "./hoverX"
1717
import makeOverlays from "./overlays"
1818
import crosshair from "./crosshair"
1919

20+
const touchEvents = ["touchstart", "touchmove", "touchend"]
21+
2022
export default (sdk, chart) => {
2123
const chartUI = makeChartUI(sdk, chart)
2224
let dygraph = null
@@ -120,6 +122,16 @@ export default (sdk, chart) => {
120122
() => chartUI.trigger("resize")
121123
)
122124

125+
touchEvents.forEach(eventType => {
126+
element.addEventListener(
127+
eventType,
128+
event => {
129+
event.preventDefault()
130+
},
131+
{ passive: false }
132+
)
133+
})
134+
123135
hoverX.toggle(attributes.enabledHover)
124136
navigation.toggle(attributes.enabledNavigation, attributes.navigation)
125137

src/chartLibraries/dygraph/navigation/generic.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
import Dygraph from "dygraphs"
2+
import DygraphInteraction from "dygraphs/src/dygraph-interaction-model"
13
import { debounce } from "throttle-debounce"
24
import limitRange from "@/helpers/limitRange"
5+
import makeHoverX from "../hoverX"
6+
7+
const doubleTapDelay = 300
38

49
export default chartUI => {
10+
const { highlight, destroy } = makeHoverX(chartUI)
11+
512
const updateNavigation = (
613
navigation,
714
prevNavigation = chartUI.chart.getAttribute("navigation")
@@ -91,11 +98,60 @@ export default chartUI => {
9198
zoom(dygraph, percentage, xPct)
9299
}
93100

101+
let lastTouchEndTime = 0
102+
let dygraphLastTouchMove = 0
103+
let dygraphLastTouchPageX = 0
104+
105+
const touchStart = (event, dygraph, context) => {
106+
Dygraph.defaultInteractionModel.touchstart(event, dygraph, context)
107+
108+
context.touchDirections = { x: true, y: false }
109+
110+
dygraphLastTouchMove = 0
111+
dygraphLastTouchPageX = event.touches[0].pageX || 0
112+
}
113+
114+
const touchMove = (event, dygraph, context) => {
115+
Dygraph.defaultInteractionModel.touchmove(event, dygraph, context)
116+
117+
if (!dygraphLastTouchMove) chartUI.sdk.trigger("panStart", chartUI.chart)
118+
119+
dygraphLastTouchMove = Date.now()
120+
}
121+
122+
const touchEnd = (event, dygraph, context) => {
123+
const now = Date.now()
124+
125+
if (now - lastTouchEndTime < doubleTapDelay) {
126+
chartUI.trigger("dblclick", event, dygraph, context)
127+
lastTouchEndTime = now
128+
return
129+
}
130+
131+
lastTouchEndTime = now
132+
133+
Dygraph.defaultInteractionModel.touchend(event, dygraph, context)
134+
135+
if (dygraphLastTouchMove === 0 && dygraphLastTouchPageX !== 0) {
136+
chartUI.chart.updateAttribute("clickX", [context.initialTouches?.[0]?.dataX, null])
137+
return
138+
}
139+
140+
if (chartUI.chart.getAttribute("panning"))
141+
chartUI.sdk.trigger("panEnd", chartUI.chart, dygraph.dateWindow_)
142+
}
143+
94144
const unregister = chartUI
95145
.on("mousedown", mousedown)
96146
.on("mouseup", mouseup)
97147
.on("wheel", onZoom)
98148
.on("dblclick", chartUI.chart.resetNavigation)
149+
.on("touchstart", touchStart)
150+
.on("touchmove", touchMove)
151+
.on("touchend", touchEnd)
99152

100-
return () => unregister()
153+
return () => {
154+
unregister()
155+
destroy()
156+
}
101157
}

src/chartLibraries/dygraph/navigation/pan.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ export default chartUI => {
77
Dygraph.startPan(event, g, context)
88
context.is2DPan = false
99

10-
chartUI
11-
.on("mousemove", mousemove)
12-
.on("mouseout", mouseup)
13-
.on("mouseup", mouseup)
14-
.on("touchmove", mousemove)
15-
.on("touchend", mouseup)
10+
chartUI.on("mousemove", mousemove).on("mouseout", mouseup).on("mouseup", mouseup)
1611
}
1712

1813
const mousemove = (event, g, context) => {
@@ -30,9 +25,7 @@ export default chartUI => {
3025
chartUI.off("mousemove", mousemove)
3126
chartUI.off("mouseup", mouseup)
3227
chartUI.off("mouseout", mouseup)
33-
chartUI.off("touchmove", mousemove)
34-
chartUI.off("touchend", mouseup)
3528
}
3629

37-
return chartUI.on("mousedown", mousedown).on("touchstart", mousedown)
30+
return chartUI.on("mousedown", mousedown)
3831
}

src/helpers/eventOffset.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
export default e => {
1+
export default (e, ctx = {}) => {
22
const target = e.target || e.srcElement
33
const rect = target.getBoundingClientRect()
4-
return { offsetX: e.clientX - rect.left, offsetY: e.clientY - rect.top }
4+
const [x, y] = /touch/.test(e.type)
5+
? [ctx.initialTouches?.[0]?.pageX, ctx.initialTouches?.[0]?.pageY]
6+
: [e.clientX, e.clientY]
7+
return { offsetX: x - rect.left, offsetY: y - rect.top }
58
}

src/sdk/plugins/play.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default sdk => {
3737

3838
if (
3939
active &&
40-
!autofetch &&
40+
(!autofetch || lastAfter - lastBefore !== fetchAfter - fetchBefore) &&
4141
(force || (loaded && (lastAfter !== fetchAfter || lastBefore !== fetchBefore)))
4242
) {
4343
if (fetchStartedAt && now - chart.getUpdateEvery() <= fetchStartedAt) return

0 commit comments

Comments
 (0)