Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/6780_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix `Cannot read properties of undefined (reading '0')` when the mouse moves to x=0 while dragging a rangeslider [[#6780](https://github.com/plotly/plotly.js/pull/6780)], with thanks to @david-bezero for the contribution!
14 changes: 12 additions & 2 deletions src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ module.exports = function(gd) {
});
};

function eventX(event) {
if(typeof event.clientX === 'number') {
return event.clientX;
}
if(event.touches && event.touches.length > 0) {
return event.touches[0].clientX;
}
return 0;
}

function setupDragElement(rangeSlider, gd, axisOpts, opts) {
if(gd._context.staticPlot) return;

Expand All @@ -234,7 +244,7 @@ function setupDragElement(rangeSlider, gd, axisOpts, opts) {
function mouseDownHandler() {
var event = d3.event;
var target = event.target;
var startX = event.clientX || event.touches[0].clientX;
var startX = eventX(event);
var offsetX = startX - rangeSlider.node().getBoundingClientRect().left;
var minVal = opts.d2p(axisOpts._rl[0]);
var maxVal = opts.d2p(axisOpts._rl[1]);
Expand All @@ -247,7 +257,7 @@ function setupDragElement(rangeSlider, gd, axisOpts, opts) {
dragCover.addEventListener('mouseup', mouseUp);

function mouseMove(e) {
var clientX = e.clientX || e.touches[0].clientX;
var clientX = eventX(e);
var delta = +clientX - startX;
var pixelMin, pixelMax, cursor;

Expand Down