From 19fcc4d7dee492ac286403e6cf60d09e4c806c6a Mon Sep 17 00:00:00 2001 From: l_samenv Date: Wed, 25 Sep 2024 10:48:28 +0200 Subject: [PATCH] fix setting cursor when clicked cursor should not be set when dragging (pan) --- client/jsFiles/SEAWebClientGraphics.js | 30 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/client/jsFiles/SEAWebClientGraphics.js b/client/jsFiles/SEAWebClientGraphics.js index 7d9dacb..4579678 100644 --- a/client/jsFiles/SEAWebClientGraphics.js +++ b/client/jsFiles/SEAWebClientGraphics.js @@ -395,9 +395,11 @@ function loadCurvesSettingsPopup(){ let graphs = (function (){ let dataset_to_graph_map = {}; // a dictionnary mapping a variable name to a two values array, containing its graph index and its position inside the graph let blocks, liveMode=true, top_vars=[], bottom_vars=[]; - let legendFlag = false, currentZoomMode = isTouchDevice ? 'xy' : 'x'; + let legendFlag = false; + let currentZoomMode = isTouchDevice ? 'xy' : 'x'; let prevTime = null, prevMin = null, prevMax = null, prevGraph = null; // zoom speed limitation let cursorLinePos = null; // the position of the cursor line (given by its x value) + let clickMode = 0; // 1: mouse is down, 2: pan is active, 0: after mouse down let type = 'linear'; // type of graphs axis to display @@ -701,9 +703,13 @@ let graphs = (function (){ legendFlag = true; let trect = evt.target.getBoundingClientRect(); let X = evt.clientX - trect.x, Y = evt.clientY - trect.y; - menuGraphicsPopup.hide(); - showLegends(true, false); - cursorLine(X); + if (X == cursorLinePos) { + cursorLine(null); + } else { + menuGraphicsPopup.hide(); + showLegends(true, false); + cursorLine(X); + } setLiveMode(); update(); for (let gr of graph_array.slice(0, ngraphs)) { @@ -714,7 +720,18 @@ let graphs = (function (){ } } } - container.addEventListener('click', clickHandler) + function mouseDown(evt) { + clickMode = 1; + } + function mouseUp(evt) { + if (clickMode == 1) { // mouse was down, but no pan happend + clickHandler(evt); + } + clickMode = 0; + } + // container.addEventListener('click', clickHandler) + container.addEventListener('mousedown', mouseDown); + container.addEventListener('mouseup', mouseUp); /** * Sets (overwrite) the data (curve) of the given variable @@ -926,6 +943,7 @@ let graphs = (function (){ function panCallback(graph){ let ax = graph.chart.options.scales.x; let xmin = ax.min, xmax = ax.max; + clickMode = 2; // mouse pan mode if (liveMode && xmax < lastTime) setLiveMode(false); setMinMax(xmin,xmax); update(); @@ -1491,7 +1509,7 @@ function Graph(gindex, container, x_label, y_label, tag, scaleType = "linear"){ if (gindex != 0) { // show time labels only on first chart - chart_options.scales.x.ticks.callback = function () { return ''; } + chart_options.scales.x.ticks.callback = function () { return ' '; } } chart = new Chart(ctx, {type: 'scatter', options: chart_options})