Time series chart: touch drag (data zoom pan, slider, handles) stops after the first move on touch devices; the next tap continues the lost drag
Environment
- ThingsBoard PE 4.3.1.5. The chart code is shared with CE, and
masterstill has the same line. - Mobile browsers (Android Chrome, iOS Safari) and the ThingsBoard mobile app WebView. Also reproducible in desktop Chrome DevTools device mode with touch emulation.
Steps to reproduce
- Add a Time series chart widget with Data zoom enabled and a few hundred points.
- Open the dashboard on a touch device.
- Zoom in, then drag the chart sideways with one finger. Or drag the slider window or one of its handles.
Expected The chart, slider window or handle follows the finger until the finger is lifted.
Actual
- The drag stops after the first move. It feels as if the chart "lets go" of the finger.
- It works only when the touch happens to start on an element that is not redrawn.
- ECharts never receives
touchend, so its drag state stays active. The next touch continues the lost drag:- a still tap on the plot moves the zoom window;
- a tap after a lost handle drag moves one border of the window, which looks like a zoom.
Root cause
TbTimeSeriesChart.drawChart()initialises ECharts with the SVG renderer (ui-ngx/.../widget/lib/chart/time-series-chart.ts:echarts.init(this.chartElement, null, { renderer: 'svg' })).- The first move of a drag causes a redraw. The redraw replaces the SVG element that was under the finger when the touch started.
- Browsers keep sending the rest of a touch sequence (
touchmove,touchend) to that original target, even after it has been detached from the document. The events no longer bubble to zrender's root element, so ECharts never sees them. - zrender has no
touchcancelhandler, so nothing resets the drag.
Measurements (headless Chrome, touch emulation, ECharts 5.5 with the widget's dataZoom options)
Case | SVG as used by TB | Canvas renderer, or SVG with the CSS fix below -- | -- | -- 80 px pan: events reaching the page | only the first touchmove, no touchend | every touchmove and touchend 80 px pan: window moved (expected about 5.5 %) | 1.4 % | 5.5 % Still tap after that pan | window jumped 41.4 % → 35.9 % | nothing moved Tooltip on tap | shown | shownSuggested fix (verified) Make the SVG transparent to pointer events, so that touches land on zrender's wrapper, which is never replaced. zrender finds the element under the pointer by coordinates, not by DOM target, so tooltips and clicks keep working:
.tb-time-series-chart-shape svg {
pointer-events: none;
}
Alternatives: use the canvas renderer, at least on touch devices; or, in zrender, keep listening for touchmove/touchend on document after touchstart and handle touchcancel.
Workaround for users Put the rule above into the widget's Advanced → Widget CSS.
Probably the other chart widgets built on TbTimeSeriesChart with data zoom are affected too; only the Time series chart was checked
Source: thingsboard/thingsboard