123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <div id="year-btns">
    </div>
    <div id="mode-btns">
      <button id="mode-perc">Percentage</button>
      <button id="mode-num">Number</button>
    </div>
    <div id='chart'></div>
  </body>
</html>

            
          
!
            
              var DIAGNOSES = [{"Week":"Jan 7 to 13","year":"2018","number of diagnosed ":"2836","% of total cases observed":"1.99%","Total cases":"142202"},{"Week":"Jan 14 to 20","year":"2018","number of diagnosed ":"3027","% of total cases observed":"2.21%","Total cases":"136736"},{"Week":"jan 21 to 27","year":"2018","number of diagnosed ":"3045","% of total cases observed":"2.19%","Total cases":"139106"},{"Week":"Jan 28 to Feb 3","year":"2018","number of diagnosed ":"2940","% of total cases observed":"2.12%","Total cases":"138578"},{"Week":"Feb 4 to Feb 10","year":"2018","number of diagnosed ":"3012","% of total cases observed":"2.08%","Total cases":"144493"},{"Week":"Feb 11 to Feb 17","year":"2018","number of diagnosed ":"2906","% of total cases observed":"2.01%","Total cases":"144433"},{"Week":"Feb 18 to Feb 24","year":"2018","number of diagnosed ":"2700","% of total cases observed":"1.90%","Total cases":"141833"},{"Week":"Feb 25 to March 3","year":"2018","number of diagnosed ":"2167","% of total cases observed":"1.55%","Total cases":"139566"},{"Week":"March 4 to 10","year":"2018","number of diagnosed ":"1772","% of total cases observed":"1.27%","Total cases":"139251"},{"Week":"March 11 to 17","year":"2018","number of diagnosed ":"1613","% of total cases observed":"1.15%","Total cases":"140083"},{"Week":"March 18 to 24","year":"2018","number of diagnosed ":"1560","% of total cases observed":"1.11%","Total cases":"140429"},{"Week":"March 25 to 31","year":"2018","number of diagnosed ":"1511","% of total cases observed":"1.09%","Total cases":"138145"},{"Week":"April 1 to 7","year":"2018","number of diagnosed ":"1506","% of total cases observed":"1.08%","Total cases":"139853"},{"Week":"April 8 to 14","year":"2018","number of diagnosed ":"1372","% of total cases observed":"0.96%","Total cases":"143036"},{"Week":"April 14 to 21","year":"2018","number of diagnosed ":"1305","% of total cases observed":"0.91%","Total cases":"144189"},{"Week":"April 22 to 28","year":"2018","number of diagnosed ":"1242","% of total cases observed":"0.87%","Total cases":"142447"},{"Week":"April 29 to May 5","year":"2018","number of diagnosed ":"1280","% of total cases observed":"0.88%","Total cases":"144812"},{"Week":"May 6 to May 12","year":"2018","number of diagnosed ":"1285","% of total cases observed":"0.87%","Total cases":"148229"},{"Week":"May 13 to 19","year":"2018","number of diagnosed ":"1240","% of total cases observed":"0.83%","Total cases":"149640"},{"Week":"May 20 to 26","year":"2018","number of diagnosed ":"1159","% of total cases observed":"0.78%","Total cases":"149015"},{"Week":"May 27 to June 2","year":"2018","number of diagnosed ":"1162","% of total cases observed":"0.79%","Total cases":"146988"},{"Week":"June 3 to June 9","year":"2018","number of diagnosed ":"1206","% of total cases observed":"0.81%","Total cases":"149580"},{"Week":"June 10 to 16","year":"2018","number of diagnosed ":"1234","% of total cases observed":"0.83%","Total cases":"149039"},{"Week":"June 17 to 23","year":"2018","number of diagnosed ":"1231","% of total cases observed":"0.82%","Total cases":"150428"},{"Week":"June 24 to 30","year":"2018","number of diagnosed ":"1171","% of total cases observed":"0.79%","Total cases":"148669"},{"Week":"July 1 to 7","year":"2018","number of diagnosed ":"1199","% of total cases observed":"0.80%","Total cases":"149623"},{"Week":"July 8 to 14","year":"2018","number of diagnosed ":"1179","% of total cases observed":"0.79%","Total cases":"150003"},{"Week":"July 15 to 21","year":"2018","number of diagnosed ":"1139","% of total cases observed":"0.76%","Total cases":"149419"},{"Week":"July 22 to 28","year":"2018","number of diagnosed ":"1093","% of total cases observed":"0.74%","Total cases":"148044"},{"Week":"July 29 to Aug 4","year":"2018","number of diagnosed ":"1105","% of total cases observed":"0.75%","Total cases":"146573"},{"Week":"Aug 5 to Aug 11","year":"2018","number of diagnosed ":"1170","% of total cases observed":"0.78%","Total cases":"150752"},{"Week":"Aug 12 to 18","year":"2018","number of diagnosed ":"1174","% of total cases observed":"0.80%","Total cases":"146507"},{"Week":"Aug 19 to 25","year":"2018","number of diagnosed ":"1190","% of total cases observed":"0.80%","Total cases":"148428"},{"Week":"August 26 to Sept 1","year":"2018","number of diagnosed ":"1175","% of total cases observed":"0.78%","Total cases":"150193"},{"Week":"Sept 2 to Sept 8","year":"2018","number of diagnosed ":"1159","% of total cases observed":"0.77%","Total cases":"150107"},{"Week":"Sept 9 to 15","year":"2018","number of diagnosed ":"1252","% of total cases observed":"0.84%","Total cases":"149063"},{"Week":"Sept 16 to 22","year":"2018","number of diagnosed ":"1250","% of total cases observed":"0.82%","Total cases":"151871"},{"Week":"Sept 23 to 29","year":"2018","number of diagnosed ":"1221","% of total cases observed":"0.83%","Total cases":"147251"},{"Week":"Sept 30 to Oct 6","year":"2018","number of diagnosed ":"1260","% of total cases observed":"0.84%","Total cases":"150239"},{"Week":"Oct 7 to 13","year":"2018","number of diagnosed ":"1146","% of total cases observed":"0.77%","Total cases":"147978"},{"Week":"Oct 14 to 20","year":"2018","number of diagnosed ":"1270","% of total cases observed":"0.87%","Total cases":"145583"},{"Week":"Oct 21 to 27","year":"2018","number of diagnosed ":"1277","% of total cases observed":"0.88%","Total cases":"144935"},{"Week":"Oct 28 to Nov 3","year":"2018","number of diagnosed ":"1294","% of total cases observed":"0.89%","Total cases":"145828"},{"Week":"Nov 4 to 10","year":"2018","number of diagnosed ":"1400","% of total cases observed":"0.95%","Total cases":"147042"},{"Week":"Nov 11 to 17","year":"2018","number of diagnosed ":"1273","% of total cases observed":"0.89%","Total cases":"143495"},{"Week":"Nov 18 to 24","year":"2018","number of diagnosed ":"1245","% of total cases observed":"0.91%","Total cases":"136485"},{"Week":"Nov 25 to Dec 1","year":"2018","number of diagnosed ":"1344","% of total cases observed":"0.93%","Total cases":"143804"},{"Week":"Dec 2 to 8","year":"2018","number of diagnosed ":"1368","% of total cases observed":"0.97%","Total cases":"141595"},{"Week":"Dec 9 to 15","year":"2018","number of diagnosed ":"1531","% of total cases observed":"1.05%","Total cases":"145198"},{"Week":"Dec 16 to 22","year":"2018","number of diagnosed ":"1656","% of total cases observed":"1.13%","Total cases":"146851"},{"Week":"December 23 to 29","year":"2018","number of diagnosed ":"1794","% of total cases observed":"1.29%","Total cases":"139319"},{"Week":"Dec 30 to Jan 5","year":"2019","number of diagnosed ":"1720","% of total cases observed":"1.18%","Total cases":"145667"},{"Week":"Jan 6 to 12","year":"2019","number of diagnosed ":"1621","% of total cases observed":"1.12%","Total cases":"144097"},{"Week":"Jan 13 to 19","year":"2019","number of diagnosed ":"1541","% of total cases observed":"1.09%","Total cases":"141407"},{"Week":"Jan 20 to 26","year":"2019","number of diagnosed ":"1584","% of total cases observed":"1.11%","Total cases":"142344"},{"Week":"Jan 27 to Feb 2","year":"2019","number of diagnosed ":"1759","% of total cases observed":"1.22%","Total cases":"143614"},{"Week":"Feb 3 to Feb 9","year":"2019","number of diagnosed ":"2029","% of total cases observed":"1.34%","Total cases":"151364"},{"Week":"Feb 10 to 16","year":"2019","number of diagnosed ":"1994","% of total cases observed":"1.33%","Total cases":"149972"},{"Week":"Feb 17 to 23","year":"2019","number of diagnosed ":"2010","% of total cases observed":"1.36%","Total cases":"147662"},{"Week":"Feb 24 March 2","year":"2019","number of diagnosed ":"1874","% of total cases observed":"1.25%","Total cases":"149951"},{"Week":"March 3 to 9","year":"2019","number of diagnosed ":"1933","% of total cases observed":"1.28%","Total cases":"151327"},{"Week":"March 10 to 16","year":"2019","number of diagnosed ":"1953","% of total cases observed":"1.28%","Total cases":"152131"},{"Week":"March 17 to 23","year":"2019","number of diagnosed ":"1771","% of total cases observed":"1.18%","Total cases":"150579"},{"Week":"March 24 to 30","year":"2019","number of diagnosed ":"1614","% of total cases observed":"1.11%","Total cases":"145346"},{"Week":"","year":"","number of diagnosed ":"","% of total cases observed":"","Total cases":""},{"Week":"10th","year":"","number of diagnosed ":"1159","% of total cases observed":"0.78%","Total cases":"139251"},{"Week":"25th","year":"","number of diagnosed ":"1194.5","% of total cases observed":"0.80%","Total cases":"142017.5"},{"Week":"Mean","year":"","number of diagnosed ":"1542","% of total cases observed":"1.07%","Total cases":"145234.6275"},{"Week":"75th","year":"","number of diagnosed ":"1545.5","% of total cases observed":"1.09%","Total cases":"149027"},{"Week":"90th","year":"","number of diagnosed ":"2836","% of total cases observed":"2.00%","Total cases":"150107"}];

var MONTHS = [
  {"len": 31, "color": "#8dd3c7", "label": "January", "id": "january"},
  {"len": 28, "color": "#ffffb3", "label": "February", "id": "february"},
  {"len": 31, "color": "#bebada", "label": "March", "id": "march"},
  {"len": 30, "color": "#fb8072", "label": "April", "id": "april"},
  {"len": 31, "color": "#80b1d3", "label": "May", "id": "may"},
  {"len": 30, "color": "#fdb462", "label": "June", "id": "june"},
  {"len": 31, "color": "#b3de69", "label": "July", "id": "july"},
  {"len": 31, "color": "#fccde5", "label": "August", "id": "august"},
  {"len": 30, "color": "#d9d9d9", "label": "September", "id": "september"},
  {"len": 31, "color": "#bc80bd", "label": "October", "id": "october"},
  {"len": 30, "color": "#ccebc5", "label": "November", "id": "november"},
  {"len": 31, "color": "#ffed6f", "label": "December", "id": "december"}
];

var WIDTH = 500;

function drawCircos(mode, diagnoses) {
  document.getElementById("chart").innerHTML = "";

  diagnoses = diagnoses.map(function(d) {
    d["value"] = (mode === "percentage" ?
                  d["diagnosed"]/d["totalCases"] * 100 :
                  d["diagnosed"]);
    d["block_id"] = d["month"];
    return d;
  });

  var circos = new Circos({
    container: '#chart',
    width: WIDTH,
    height: WIDTH
  });

  circos.layout(MONTHS, {
    innerRadius: WIDTH / 2 - 80,
    outerRadius: WIDTH / 2 - 30,
    ticks: {display: false},
    labels: {
      position: "center",
      display: true,
      size: 12,
      color: "#000"
    }
  }).heatmap("diagnoses", diagnoses, {
    innerRadius: 0.6,
    outerRadius: 0.98,
    logScale: true,
    color: "-Spectral",
    tooltipContent: function(datum, index) {
      var value = (mode === "percentage" ?
                   datum.value.toFixed(4) + "%" :
                   datum.diagnosed + "/" + datum.totalCases);
      return datum.dateRange + ": " + value;
    }
  }).render();
}

function splitDateRange(dateRange) {
  function convertMonth(month) {
    month = month.trim().toLowerCase();
    var monthIDs = MONTHS.map(function(m) { return m.id; });

    for (var i = 0; i < monthIDs.length; i++) {
      if (monthIDs[i].startsWith(month)) {
        return monthIDs[i];
      }
    }
  }
  dateRange = dateRange.split(" to ");
  if (dateRange.length !== 2) {
    return;
  }

  var start = dateRange[0].split(" ");
  var end = dateRange[1].split(" ");

  var monthStart = convertMonth(start[0]);
  var monthEnd = convertMonth(end[0]);

  if (end.length === 1 || monthStart === monthEnd) {
    return [
      [convertMonth(start[0]), Number(start[1]) - 1,
       monthEnd ? Number(end[1]) : Number(end[0])]
    ];
  } else {
    var monthDays = MONTHS.filter(function(m) { return m.id === monthStart; })
    .map(function(m) { return m.len; })[0];
    return [
      [monthStart, Number(start[1]) - 1, monthDays],
      [monthEnd, 0, Number(end[1])]
    ];
  }
}

function parseCSV(error, diagnosesCSV) {
  var diagnoses = {};
  diagnosesCSV.forEach(function(row) {
    var split = splitDateRange(row["Week"]);
    if (typeof split === "undefined") {
      return;
    }

    var year = row["year"].trim();
    var diagnosed = Number(row["number of diagnosed "]);
    var totalCases = Number(row["Total cases"]);

    if (diagnosed === 0) {
      return;
    }

    if (typeof diagnoses[year] === "undefined") {
      diagnoses[year] = [];
    }

    split.forEach(function(range) {
      diagnoses[year].push({
        "month": range[0],
        "start": range[1],
        "end": range[2],
        "diagnosed": diagnosed,
        "totalCases": totalCases,
        "dateRange": row["Week"],
        "year": year
      });
    });
  });

  var years = Object.keys(diagnoses).sort();
  var yearBtns = document.getElementById("year-btns");
  yearBtns.innerHTML = "";

  years.forEach(function(year) {
    var button = document.createElement("button");
    button.innerHTML = year;
    button.onclick = function() {
      document.getElementById("mode-perc").onclick = function() {
        drawCircos("percentage", diagnoses[year]);
      };
      document.getElementById("mode-num").onclick = function() {
        drawCircos("number", diagnoses[year]);
      };
      drawCircos("percentage", diagnoses[year]);
    };
    yearBtns.appendChild(button);
  });
  
  document.getElementById("year-btns").firstChild.click();
}

parseCSV(null, DIAGNOSES);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console