Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
Conditionnal colours on d3.js beeswarm plot

I'm trying to color a specific dot in my beeswarm plot. My condition is: color the dot if the id matches the id in the params.

Therefore, i'm guessing something like this : .attr("fill", function(d) {if("myCondition")return "red"; }) on the svg

My data looks like this : { id: 1, name: ItemA, size: 15 }

When i'm on the page of ItemA, its corresponding dot on the plot should be coloured red.

What should "myCondition" be to have this result ?

Here's the code on d3's website to fiddle with (where you can try colouring according to Year or Acceleration for example) https://observablehq.com/@d3/beeswarm

I'm quite sure my line of code has to be added in the const dot = svg.append("g") at the end

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For those interested, i did these modifications : In the d3.js file :

const idFetch = d3.map(data, item) //create an array of my data's ID

and in the svg creation :

.attr("fill",function(d) {if(idFetch[d] === activeSampleId) return 'red'}) //With active sample ID an option, equal to the ID of the page I'm on (item/{activeSampleId})

Then upon calling the Beeswarm function, in the options :

item: d => d.id,
activeSampleId: this.sampleId, //Vue options API
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!