There was an issue with d3 version 4: the function this.setAttribute() was not

I am attempting to update the provided example to be compatible with d3 version 4 http://bl.ocks.org/ameyms/9184728

Most of the code has been successfully converted, but I am encountering difficulties with the following function:

this.el.transition().delay(100).duration(200).select('.needle').tween('reset-progress', function() {
    return function(percentOfPercent) {
      var progress = (1 - percentOfPercent) * oldValue;

      repaintGauge(progress);
      return d3.select(this).attr('d', recalcPointerPos.call(self, progress));
    };
});

The error message I am seeing is

this.setAttribute is not a function
on the line that contains the return statement. It has been confirmed that recalcPointerPos is functioning properly, which leads me to believe that the issue lies in the syntax of d3.select(this).attr. Is there a difference in how this type of selection is handled between versions 3 and 4 of d3?

View the fiddle here: https://jsfiddle.net/v1tok1k6/

Answer №1

The inner return select is utilizing an incorrect scope for selecting the element. The desired scope is that of the outer functions, representing the path element. To resolve this issue, it's recommended to perform the selection at the outer scope for effective caching.

this.el.transition().delay(300).duration(1500).select('.needle').tween('progress', function(d, i, e) {
  var needle = d3.select(this);
  return function(percentOfPercent) {
    var progress = percentOfPercent * perc;

    repaintGauge(progress);
    return needle.attr('d', recalcPointerPos.call(self, progress));
  };
});

Check out the updated fiddle here

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

Limit the focus to the dialog box using JavaScript

Is there a way to limit the tab and shift-tab key focus to only cycle through input elements within a specific popup dialog in HTML? I have a div with a high z-index that contains these input elements, and I want to restrict the keyboard navigation to st ...

Troubleshooting Vercel and Express DELETE request cross-origin resource sharing problem

Currently, I am in the process of developing an API using Vercel and ExpressJS. The GET and POST endpoints are functioning properly, however, I encountered an issue with the DELETE endpoint. When attempting to access the endpoint from my client-side JavaSc ...

The jQuery closest selector seems to be malfunctioning when trying to scroll and focus on a specific class

My HTML code snippet is as follows: <div class="main"> <div class="sub-1"> <select> <option>1</option> <option>2</option> </select> </div> <div class="sub-2"> ...

Tips for Drawing Lines and Preserving Them When a Condition is Met

I am currently utilizing Node.Js in an attempt to outline objects within an image based on certain conditions being met. My goal is to draw lines around specific portions of the image received from an API response. Whenever the response includes the keywor ...

The loading of the module from was hindered due to an invalid MIME type restriction

Exploring a three.js example and encountering an issue when utilizing import within a JavaScript module. The error message displayed is: Loading module from “http://localhost:8000/build/three.module.js” was blocked because of a disallowed MIME type ( ...

Verifying Username Availability with Struts2 and AJAX Request

Currently constructing a web application utilizing Struts2 as the primary framework. The main focus is to verify the availability of a username through an AJAX call (open to alternative approaches if there are simpler methods to achieve the same outcome.) ...

Am I causing my entire React component to re-render needlessly every time the state changes?

I've been attempting to develop an accordion component using React, but I seem to be encountering issues with the animation not functioning as expected. The approach I'm taking is quite standard - setting a max-height of 0 for each item body and ...

Transform a personalized Google map into a visual representation

I am facing a challenge with the following issue. I have implemented a custom overlay on a Google map and it works perfectly in the browser. However, my dilemma arises when I need to display an image with a marker for each point of interest on a different ...

Replicate and refresh characteristics

As a newcomer to this platform, I have found stackoverflow to be an invaluable resource over the past year. Currently, I am working on creating a complex form that requires the user to add subgroups. Using jquery (1.5.1 - perhaps it's time for an upd ...

Creating responsive data tables in HTML

My e-shop features a product description block using the code snippet below. While it looks great on larger screens, such as a 17" desktop monitor, it appears poorly on smaller smartphone screens. Friends have suggested that I learn Bootstrap/Flexbox and ...

Calculating the sum of all values in the database

In my database, I have a value called task_time. I want to add this value to itself so that the total time is calculated as totalTime = task_time + task_time + ... + task_time. This is how I retrieve the data: function getEndTasks() { $http.get(& ...

What is the best way to incorporate ng-pluralize into a loop and access the count value?

Is there a way to access the iterator in the count attribute when using ng-pluralize within a loop? <option ng-repeat="i in [1,2,3,4,5]" value="{{ i }}"> {{ i }} star<ng-pluralize count="i" when="{'1': '', 'other': ...

Create a JavaScript function to calculate a 2-tailed t distribution by adapting an already existing method

Can someone help me with implementing a two-tailed t-test in JavaScript? Resource: Student's t distribution in JavaScript for Google Spreadsheet I have taken a potential solution from the link and customized it to function outside of the form: func ...

Turn only one bracket on the accordion

When clicking on a specific header, I want only one chevron to rotate instead of all the chevrons rotating. I am currently unsure how to specify which chevron should rotate individually. My project is in ASP.NET MVC 5 and I am using razor view to loop th ...

Enhancing the visual appeal of my PLY file with vibrant hues using three.js

Hello everyone, I've run into a little issue with three.js. I'm trying to color a ply file and need some assistance. Specifically, I want to add red coloring to the eyes only, not any other part of the model. Can anyone help me with this using th ...

What is the reason skip does not function properly at the start of the aggregation pipeline, yet performs as expected at the conclusion of it?

Initially, the skip stage in this MongoDB database aggregation framework pipeline isn't functioning as expected: [ { $skip: (!offset)? 0 :(offset-1)*limit }, { $match: (query)? query : {} } , { $lookup: ..., ...

Place the script tags within the div element

After loading a page dynamically, I found that only the contents of the div id="example" were being executed. However, the script tag inside the div was not being executed. I attempted to use eval to solve this issue, but it was unsuccessful. <div id=" ...

Navigating through the browser history will allow you to view the

Currently, I am working on the localhost/mysite/users page. This page displays a list of users that is fetched through an ajax request. However, I have encountered a strange issue. Whenever I navigate back and then forward again, the content on the localh ...

I'm confused as to why I am only receiving one object entry in my fetch response instead of the expected list of entries

Is there a way to fetch all entries as a response instead of just one value? For example, when the next value returned by the fetch is {"next":"/heretagium"}, I can replace "/hustengium" with "heretagium" to get th ...

How can I redirect the page in CodeIgniter after successfully validating?

Currently, I am utilizing CodeIgniter for my project's development and implementing field validation using Bootstrap validator. Although the Bootstrap validator is functioning properly, I am encountering an issue. Upon successful validation, I expect ...