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 8522913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:15:43+00:00 2026-06-11T07:15:43+00:00

I am trying to create partially filled circles like the ones in the final

  • 0

I am trying to create partially filled circles like the ones in the final NYT political convention visualization: http://www.nytimes.com/interactive/2012/09/06/us/politics/convention-word-counts.html

enter image description here

The two clearest code examples I’ve found for clipPaths in d3 ( https://gist.github.com/1067636 and http://bl.ocks.org/3422480) create individual div elements with unique ids for each clip-path and then apply these paths to single elements.

I can not figure out how to go from these examples to a visualization with a unique circular clipPath for each element in a set of elements based on data values so that I can create my effect.

Here is what I have so far:

Given data with the following structure:

data = [        
    {value: 500, pctFull: 0.20, name: "20%"}, 
    {value: 250, pctFull: 0.75, name: "75%"},
    {value: 700, pctFull: 0.50, name: "50%"},        
]

1) Create a force diagram with a circle for each object in the dataset. The area of the circle is derived from the objects value.

2) Calculate k (and h) from a proportion (pctFull) for each datapoint using the algorithm from the mbostock example http://bl.ocks.org/3422480

3) Use k to generate a rect for each datapoint that covers the appropriate area of the circle.

I think the illustration would be done if I could limit the visibility of each rect to its respective circle but this is where I am stuck. I’ve tried a bunch of things, none of which have worked.

Here’s the jsfilddle: http://jsfiddle.net/G8YxU/2/

enter image description here

  • 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-11T07:15:45+00:00Added an answer on June 11, 2026 at 7:15 am

    See a working fiddle here: http://jsfiddle.net/nrabinowitz/79yry/

    enter image description here

    // blue circle
    node.append("circle")
        .attr("r", function(d, i) {return rVals[i];})
        .style("fill", "#80dabe")                
        .style("stroke", "#1a4876");   
    
    // clip path for the brown circle
    node.append("clipPath")
        // make an id unique to this node
        .attr('id', function(d) { return "clip" + d.index })
      // use the rectangle to specify the clip path itself 
      .append('rect')
        .attr("x", function(d, i){ return rVals[i] * (-1);})
        .attr("width", function(d, i){ return rVals[i] * 2;})
        .attr("y", function(d, i) {return rVals[i] - (2  * rVals[i] * kVals[i]);})
        .attr("height", function(d, i) {return 2  * rVals[i] * kVals[i];});
    
    // brown circle
    node.append("circle")
        // clip with the node-specific clip path
        .attr("clip-path", function(d) { return "url(#clip" + d.index + ")"})
        .attr("r", function(d, i) {return rVals[i];})
        .style("fill", "#dabe80")                
        .style("stroke", "#1a4876");   
    
    • It looks like the only way to specify a clip path for an element is to use the url(IRI) notation in the clip-path attribute, which means that you’ll need a unique id for each clip path based on the node data. I’ve used the form clip<node index> for the id – so each node gets its own clip path, and other sub-elements of the node can refer to it.

    • It seemed easiest, following Mike’s example, to make two circles of different colors and use the rectangle itself for the clip path, rather than making a circle-based clip path. But you could do it either way.

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

Sidebar

Related Questions

I am trying to create a bunch of dynamic helper methods like these: show_admin_sidebar
I'm trying to write some python code which can create multipart mime http requests
I am trying to create an application which will be partially dependent on the
I am new to .net MVC structure. I am trying to create Partial view
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5
Trying to create a black line in my view to separate text blocks but
Trying to create a facebook app just to learn and coming across a strange
Trying to create a new Dedicated Cache Role in Windows Azure but get the

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.