Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda