The issue of panning not functioning properly when hovering over lines in Plotly.js

There seems to be an issue with panning while hovering over a marker.

To replicate the problem, follow these steps -> select pan -> hover on a marker -> drag the plot -> the plot reverts back to its original position.

var data = [{
      mode: "lines+markers",
      x:["December", "January", "February"],
      y:[4,1,3]
    }]

Plotly.react('myDiv', data).then(gd => {
      gd.on('plotly_hover', d => {
      var width_vals = gd.data.map(x => 5)
      Plotly.restyle(gd, 'line.width', width_vals)
      
      }).on('plotly_unhover', d => {
      var width_vals = gd.data.map(x => 1)
      Plotly.restyle(gd, 'line.width', width_vals)
      })
})
<head>
    <!-- Load plotly.js into the DOM -->
    <script src='https://cdn.plot.ly/plotly-2.12.1.min.js'></script>
</head>

<body>
    <div id='myDiv'><!-- The Plotly chart will be displayed inside this DIV --></div>
</body>

https://i.sstatic.net/7LdJe.gif

If you have any suggestions, please feel free to share!

Answer №1

Ensure that you set xaxis.uirevision to a truthy value and maintain consistency across re-renders. For more information, refer to the documentation at

var data = [{
      mode: "lines+markers",
      x:["December", "January", "February"],
      y:[4,1,3]
    }]

Plotly.react('myDiv', data).then(gd => {
      gd.on('plotly_hover', d => {
      var width_vals = gd.data.map(x => 5)
      Plotly.restyle(gd, { 'line.width': width_vals, 'xaxis.uirevision': 'anyvalue' })
      
      }).on('plotly_unhover', d => {
      var width_vals = gd.data.map(x => 1)
      Plotly.restyle(gd, { 'line.width': width_vals, 'xaxis.uirevision': 'anyvalue' } )
      })
})
<head>
    <!-- Load plotly.js into the DOM -->
    <script src='https://cdn.plot.ly/plotly-2.12.1.min.js'></script>
</head>

<body>
    <div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>
</body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: The node.js V12.18.2 software encountered a problem and is unable to read the property 'startsWith' of an undefined variable

I'm new to this platform, so please forgive any errors in my formatting. I'm facing an issue with Node.js on my laptop - it doesn't work here but works perfectly fine on another computer. Below is the code I am using: const Discord = require ...

Error alert: The system could not locate Google when trying to drop pins

Every time I attempt to place pins on the map, I encounter the "google is not defined" error. The map itself displays without any issues until I add the lines following the initMap() function. I have come across similar posts but none of the suggested so ...

How to selectively disable buttons in a group using React

I am working with an array of data const projectTypeValues = [ { name: 'Hour', value: 'hour'}, { name: 'Day', value: 'day'}, { name: 'Session', value: 'session'}, { name: 'project', valu ...

What is the process for examining promises within the node.js debugger?

I recently developed an application in node.js where I utilized cujojs' when module to create promises that are then stored in an array. The ultimate goal is to trigger a happy message once all promises are fulfilled. However, the fulfillment of some ...

Evaluating an AngularJS application with the help of Selenium and PhantomJS

I'm looking to try out Selenium and PhantomJS for testing my AngularJS app, but I can't seem to find a beginner-friendly resource or tutorial. Do you have any recommendations for where I should start? ...

How to dynamically load bootstrap-multiselect within a loop in a vueJs application

I am attempting to dynamically load bootstrap-multiselect in a loop using VueJs. My desired implementation looks something like this: <div class="col-xs-6 col-sm-4 mb-1" v-for="params in param"> <select class="mult" multiple="multiple"> ...

What is causing the Jquery form submit event to not trigger?

I am attempting to use jQuery to submit a form. I need the form submit event to be triggered when jQuery submits the form. However, the submit event handler is not being called successfully after the form is submitted. Here is the code snippet: <html ...

The set for generating dgeni documents is not currently specified

I am facing issues with the dgeni document generation tool where I encounter an error stating that 'Set is not defined', which leads me to believe the error is related to this issue. I have installed dgeni using npm install on both Windows 7 and ...

Acquiring variables from a JQuery Ajax request while invoking a JavaScript file

I'm currently experimenting with using JQuery Ajax to retrieve a javascript file. I need to pass some parameters to it, but I'm not entirely sure how to do so in Javascript (PHP seems easier for this). Here is my current setup: function getDocum ...

What are the steps to creating a duplicate of JotForm?

After exploring JotForm, I discovered it is an extremely interactive form builder utilizing the Prototype JS library. I am curious to know which JS framework or library would be a solid foundation for creating a similar form builder - JQuery, Prototype, ...

The magic of React.js in creating fluid scrolling single page applications

Embarking on my journey with react.js, my aim is to develop a single page application where the top navigation links smoothly scroll to the relevant sections on the front page akin to THIS SITE. Currently, my application utilizes React.js and React-Router ...

NodeJS Like/Dislike System: Leveraging the Power of NodeJS

(Please refer to my solution in the answer post below) Hello there! Today, I have a question about implementing a like/dislike system using nodeJs with data stored in MongoDB. What is the current scenario? I'm tasked with creating the backend for ...

What is the best way to send events to connected sockets using socket.io directly from my Express 4 routes?

I have a question that others have asked before, but I'm struggling to benefit from their answers due to the unique Express setup I have. Currently, I have socket.io implemented and running smoothly on my server in a simple manner. Here is how it is ...

Tips for securely integrating freelancers into your web project

Looking for a secure way to bring in freelancers to assist with tasks on our website, where the freelancer only has write access to specific pages. I'm aware that this can be done with tools like Windows Team Foundation Server. However, I need the fr ...

Adding data to a pre-made JavaScript file template to create a fresh document

In my web application, I have a form with multiple inputs: <form action=""> Title1:<br> <input type="text" name="title1"> <input type="text" name="title1Description"> <br> Title2:<br> <input t ...

It is more advantageous to utilize information from a table on the webpage or a pre-existing JavaScript variable in your PHP/JavaScript code

After searching, I came across a few similar questions but none that quite fit the bill. I apologize if this has been asked before. I have designed a page with a table populated by PHP using information from a database. The user is able to choose a row in ...

Is there a built-in method or library for extracting data from JSON strings in programming languages?

Duplicate Query: how to parse json in javascript The data sent back by my server is in JSON format, but it doesn't follow the usual key/value pairs structure. Here's an example of the data I'm receiving: ["Value1","Value2","Value3"] ...

Removing cookies after sending a beacon during the window unload event in Chrome

Here's the situation: I need to make sure that when the browser is closed or the tab is closed, the following steps are taken: Send a reliable post request to my server every time. After sending the request, delete the cookies using my synchronous fu ...

I find myself facing a roadblock in navigating Servlets and HTML

I'm currently immersed in a project aimed at launching an innovative online food ordering platform. To bring this vision to life, I've harnessed the power of HTML, CSS, and JavaScript for frontend development, Java (Servlets) for backend function ...

PHP + MySQL + JavaScript for an Interactive Web Communication Platform

My goal is to develop a Web Chat system using PHP, MySQL, and JavaScript. Currently, I store messages in a MySQL database with an incremental ID (indexed), timestamp, sender, and message. To retrieve new messages, I use AJAX to query the database every 50 ...