<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Taxa niche/production overlap</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 src="https://cdn.jsdelivr.net/npm/vega@5.27.0"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-lite@5.17.0"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-embed@6.24.0"></script>

    <style>
    #vis {
        width: 100%;
        margin: 1em;
        display: block;
    }
    </style>
  </head>
  <body>
  <section class="section">
    <div class="container">
      <h1 class="title">
        Taxa niche/production overlap
      </h1>
      <p class="subtitle">
        Each point denotes the reduced {{direction}} fluxes for a single taxon
        in a single sample. If two points are close to each other they consume
        (for direction="import") or produce (for direction="export") the same
        metabolites.<br>
        Hover over each point to see its annotations. You can click a point
        to select only that taxon. Click on an empty part of the plot to
        reset the selection.<br>
        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="#" class="button is-primary" onclick="download_data('reduced')">Download as CSV...</a>

    </div>
    <script>
      // Assign the specification to a local variable vlSpec.
      var vlSpec = {
        $schema: "https://vega.github.io/schema/vega-lite/v5.json",
        width: {{width}},
        height: {{height}},
        data: {
            values: {{data | safe}}
        },
        selection: {"pts": {"type": "single", "fields": ["taxon"]}},
        mark: {
            type: "point",
            filled: true,
            size: 20,
            tooltip: {content: "data"}
        },
        encoding: {
          x: {
            field: "TSNE 1",
            type: "quantitative",
            scale: {zero: false}
          },
          y: {
            field: "TSNE 2",
            type: "quantitative",
            scale: {zero: false}
          },
          color: {
            condition: {
              selection: "pts",
              field: "taxon",
              type: "nominal"
            },
            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 = document.querySelector("#vis svg");
        svg.setAttribute("width", "100%");
        svg.setAttribute("height", "auto");
      });

      {% include "blobify.js" %}
    </script>
  </section>
  </body>
</html>
