Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda