JSFiddle - React, Tailwind, and code Playground

by ckissi

HTML

<script src="https://data-analytics.github.io/javascripts/jquery.min.js"></script>
<script src="https://data-analytics.github.io/javascripts/d3.v3.min.js"></script>
<div class="container">
      <section id="main_content" class="inner">
            <div id="chart"></div>
      </section>
    </div>

JavaScript

var margin = { top: 40, right: 20, bottom: 50, left: 20 },
    width = 960 - margin.left - margin.right,
    height = 420 - margin.top - margin.bottom,
    gridSize = Math.floor(width / 24),
    legendElementWidth = gridSize*2,
    buckets = 9,
    colors = ['#ccffcc','#99ff99','#66ff66','#33ff33','#00ff00','#00cc00','#009900','#006600','#003300'] 
    days = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
    times = ["1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12a", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p", "12p"];

      d3.json("https://bl.ocks.org/officeofjane/raw/11b54880abcb6b844637cb1d7a120cd5/test.json",
        function(d) {
          return {
            day: +d.day,
            hour: +d.hour,
            value: +d.value
          };
        },
        function(error, data) {
          var colorScale = d3.scale.quantile()
              .domain([0, buckets - 1, d3.max(data, function (d) { return d.value; })])
              .range(colors);

          var svg = d3.select("#chart").append("svg")
              .attr("width", width + margin.left + margin.right)
              .attr("height", height + margin.top + margin.bottom)
              .append("g")
              .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

          var dayLabels = svg.selectAll(".dayLabel")
              .data(days)
              .enter().append("text")
                .text(function (d) { return d; })
                .attr("x", 0)
                .attr("y", function (d, i) { return i * gridSize; })
                .style("text-anchor", "end")
                .attr("transform", "translate(-6," + gridSize / 1.5 + ")")
                .attr("class", function (d, i) { return ((i >= 0 && i <= 4) ? "dayLabel mono axis axis-workweek" : "dayLabel mono axis"); });

          var timeLabels = svg.selectAll(".timeLabel")
              .data(times)
              .enter().append("text")
                .text(function(d) {...