drilling-accross

drilling accross

by azeq

HTML

<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>SquashQL</title>
  </head>

  <body>
    <div id="container" />
  </body>
  <script src="https://unpkg.com/@antv/s2/dist/s2.min.js"></script>

</html>

JavaScript

const squashQLResponse = {
   "cells":[
      {
         "quantity sold":54,
         "quantity returned":5
      },
      {
         "reason":"defective",
         "quantity returned":1
      },
      {
         "reason":"unwanted",
         "quantity returned":4
      },
      {
         "product":"A",
         "quantity sold":15,
         "quantity returned":1
      },
      {
         "reason":"defective",
         "product":"A",
         "quantity returned":1
      },
      {
         "product":"B",
         "quantity sold":23,
         "quantity returned":null
      },
      {
         "product":"C",
         "quantity sold":16,
         "quantity returned":3
      },
      {
         "reason":"unwanted",
         "product":"C",
         "quantity returned":3
      },
      {
         "product":"D",
         "quantity sold":null,
         "quantity returned":1
      },
      {
         "reason":"unwanted",
         "product":"D",
         "quantity returned":1
      }
   ],
   "rows":[
      "product"
   ],
   "columns":[
      "reason"
   ],
   "values":[
      "quantity sold",
      "quantity returned"
   ]
}

function transformData(rawData) {
  return {
    fields: {
      rows: rawData["rows"],
      columns: rawData["columns"],
      values: rawData["values"],
      valueInCols: true,
    },
    data: rawData["cells"]
  }
}

const s2Options = {
  width: 600,
  height: 480,
  showDefaultHeaderActionIcon: false,
  hierarchyType: "tree",
  tooltip: {
    showTooltip: true,
    row: {
      showTooltip: true,
    },
  },
  totals: {
    row: {
      showGrandTotals: true,
      showSubTotals: {
        always: true
      },
      reverseLayout: true,
      reverseSubLayout: true,
      label: "Grand Total",
      subLabel: "Total",
    },
    col: {
      showGrandTotals: true,
      showSubTotals: {
        always: true
      },
      reverseLayout:...