<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Growth rates</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.0/css/bulma.min.css">
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,700&display=swap" rel="stylesheet">
    <script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/d3@5.15.0/dist/d3.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega@5.9.0"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-lite@4.0.2"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-embed@6.2.1"></script>

    <style>
    #vis {
        width: 100%;
        margin: 1em;
    }
    </style>
  </head>
  <body>
  <section class="section">
    <div class="container">
      <h1 class="title">
        Growth rates
      </h1>
      <p class="subtitle">
        Each point denotes a single taxon in a single sample. Shown are the
        predicted growth rates only if growth was observed (growth rate larger
        than numerical tolerance of the solver).<br>
        Click a point to select points from only that sample. Click on an
        empty region of the plot to reset the selection.<br>
        Hover over each point to see its annotations. Use the "..." menu in the
        upper right hand side to export the plot into various formats.
      </p>
    </div>
    <!-- Container for the visualization -->
    <div class="container">
    <div id="vis"></div>
    <a href="growth_rates.csv" class="button is-primary">Download as CSV...</a>

    </div>
    <script>
      // Assign the specification to a local variable vlSpec.
      var vlSpec = {
        $schema: "https://vega.github.io/schema/vega-lite/v4.json",
        width: {{width}},
        height: {{height}},
        data: {
            values: {{data | safe}}
        },
        selection: {
          pts: {type: "single", fields: ["sample_id"]}
        },
        mark: {
            type: "point",
            filled: true,
            size: 40,
            tooltip: {content: "data"}
        },
        encoding: {
          y: {
            field: "growth_rate",
            type: "quantitative",
            scale: {type: "log"},
            axis: {title: "growth rate [1/h]", grid: false}
          },
          x: {
            field: "taxon",
            type: "nominal",
            sort: {op: "median", field: "growth_rate"},
            axis: {title: null}
          },
          color: {
            condition: {
              selection: "pts",
              field: "taxon",
              type: "nominal",
              legend: null
            },
            value: "lightgrey"
          },
          opacity: {
            condition: {
                selection: "pts",
                value: 0.8
            },
            value: 0.2
          }
        }
      };

      // Embed the visualization in the container with id `vis`
      vegaEmbed("#vis", vlSpec, {renderer: "svg"}).then(function(r) {
        svg = d3.select("#vis svg");
        svg.attr("width", "100%").attr("height", "auto");
      });
    </script>
  </section>
  </body>
</html>
