Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8895643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:50:07+00:00 2026-06-14T23:50:07+00:00

I’m playing around with ( https://gist.github.com/1499279 ) a custom gauge using d3js by Tomer.

  • 0

I’m playing around with ( https://gist.github.com/1499279 ) a custom gauge using d3js by Tomer. In his code, he calls updateGauges() gauges[key].redraw(30 + 50 * Math.random() - 30 * Math.random()); to generate random numbers for the pointer to animate to. I changed it to gauges[key].redraw(80); so that the pointer does not re-render.

During the initial load, the pointer follows a shortest path in getting to its destination instead of animating in an arched trajectory (clock wise like how real gauges operate). When 80 is passed in as parameter, the pointer animates anti clockwise from 0. Instead, it should always follow an arched trajectory.

What do you guys think should be modified/added?

*Soln Update:

this.drawPointer = function(value)
{
    var delta = this.config.range / 13;
    var n=value/2;

    var head = this.valueToPoint(n, 0.85);
    var head1 = this.valueToPoint(n - delta, 0.12);
    var head2 = this.valueToPoint(n + delta, 0.12);

    var headlast = this.valueToPoint(value, 0.85);
    var head1last = this.valueToPoint(value - delta, 0.12);
    var head2last = this.valueToPoint(value + delta, 0.12);

    var tailValue = n -  (this.config.range * (1/(270/360)) / 2);
    var tail = this.valueToPoint(tailValue, 0.28);
    var tail1 = this.valueToPoint(tailValue - delta, 0.12);
    var tail2 = this.valueToPoint(tailValue + delta, 0.12);

    var tailValuelast = value -  (this.config.range * (1/(270/360)) / 2);
    var taillast = this.valueToPoint(tailValuelast, 0.28);
    var tail1last = this.valueToPoint(tailValuelast - delta, 0.12);
    var tail2last = this.valueToPoint(tailValuelast + delta, 0.12);


    var data = [head, head1, tail2, tail, tail1, head2, head];

    var line = d3.svg.line()
                        .x(function(d) { return d.x })
                        .y(function(d) { return d.y })
                        .interpolate("basis");


    var pointerContainer = this.body.select(".pointerContainer");   

    var pointer = pointerContainer.selectAll("path").data([data])                                       

    pointer.enter()
            .append("svg:path")
                .attr("d", line)
                .style("fill", "#dc3912")
                .style("stroke", "#c63310")
                .style("fill-opacity", 0.7)

    pointer.transition()
                .attr("d", line) 
                .each("end", function () {      
                if (value!=0) {

                        var head = headlast;
                        var head1 = head1last;
                        var head2 = head2last;

                        var tailValue = tailValuelast;
                        var tail = taillast;
                        var tail1 = tail1last;
                        var tail2 = tail2last;

                        var data = [head, head1, tail2, tail, tail1, head2, head];

                        var line = d3.svg.line()
                                        .x(function(d) { return d.x })
                                        .y(function(d) { return d.y })
                                        .interpolate("basis");

                        var pointer = pointerContainer.selectAll("path").data([data])                                       

                        pointer.enter()
                            .append("svg:path")
                                .attr("d", line)
                                .style("fill", "#dc3912")
                                .style("stroke", "#c63310")
                                .style("fill-opacity", 0.7)

                        pointer.transition()
                                .attr("d", line) 
                                .ease("bounce")
                                .duration(600); 
                            }
                }
                )
                .duration(200);

    var fontSize = Math.round(this.config.size / 10);
    pointerContainer.selectAll("text")
                        .data([value])
                            .text(Math.round(value))
                        .enter()
                            .append("svg:text")
                                .attr("x", this.config.cx)
                                .attr("y", this.config.size - this.config.cy / 4 - fontSize)                        
                                .attr("dy", fontSize / 2)
                                .attr("text-anchor", "middle")
                                .text(Math.round(value))
                                .style("font-size", fontSize + "px")
                                .style("fill", "#000")
                                .style("stroke-width", "0px");
}

Regards,
Viswesh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:50:08+00:00Added an answer on June 14, 2026 at 11:50 pm

    I am also new to D3, but here is my humble understanding (please correct me if I am wrong):

    var line = d3.svg.line()
        .x(function(d) { return d.x })
        .y(function(d) { return d.y })
        .interpolate("basis");
    

    Here interpolate simply change x and y value from current value to target value.

    In your case, the y value needs to change from current value -> highest point(which is 100) -> to the target value.

    One of the solution i can think of is add control point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.