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

190
Views
How to make a working slider with VegaLite API and Observable

I am currently working on an Observable notebook using the VegaLite API and want to add a slider that allows a user to see COVID cases in states on specific dates.

The map

The code for the map:

{  
  const legend = {
    title: "Cases on " + string,
    orient: "none"
  };
  
  const state = vl.markGeoshape()
    .data(vl.topojson(usa).feature("states"))
    .params(string)
    .transform(
      vl.lookup("id")
      .from(vl.data(StatesFileTyped).params(string).transform({type: "filter", filter: "date", equal: "string", expr: "datum.date === string"}).key("fips").fields("state", "new_case", "date")),
    )
    .encode(
      vl.color().fieldQ("new_case")
        .scale({domain: [0, 51000]})
        .legend(legend),
      vl.tooltip().fieldQ("new_case")
    );
  
  const states = vl.markGeoshape({fill: null, stroke: "grey", strokeWidth: .25})
    .data(vl.topojson(usa).mesh("states"));

  return vl.layer(state, states)
    .project(vl.projection("albersUsa"))
    .width(width - 100)
    .height(Math.floor(0.6 * width - 100))
  .render()

}

Here is the code for the slider:

viewof days_in = Inputs.range([0, 845], {step: 1, label: "Day of the Pandemic"});

date_selected = d3.utcFormat("%m/%d/%Y")(timeScale.invert(days_in)).split("/");

string = {
  let stringDate = "";
  for (let i = 0; i < date_selected.length; i++) {
    if (i == date_selected.length - 1) {
      stringDate += parseInt(date_selected[i], 10);
    } else {
      stringDate += parseInt(date_selected[i], 10) + "/";
    }
  }
  return stringDate;
}

The data itself

about 4 years ago · Juan Pablo Isaza
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!