JSFiddle - React, Tailwind, and code Playground

by tobek

HTML

<!DOCTYPE html>
<meta charset="utf-8" />
<head>
  <title>d3 svg test</title>
  <style type="text/css">
    a {
      font: 8pt"Menlo", "Consolas", "Lucida Console", "Courier", monospace;
      padding: 10px;
      border: 1px solid #000;
      z-index: 2;
    }
    a:link {
      text-decoration: none;
      color:#333;
    }
    a:visited {
      text-decoration: none;
      color:#999;
    }
    a:hover {
      text-decoration: none;
      color:#F00;
    }
    a:active {
      text-decoration: none;
      color:#000;
    }
    svg.projects {
      position: absolute;
      left:0;
      top:0;
      z-index: -5;
    }
    svg circle.orbcircle {
      fill: rgba(255, 255, 255, 1);
      stroke: black;
      stroke-width: 5;
    }
    svg rect.box {
      stroke: red;
      fill: none;
      stroke-width: 1;
      shape-rendering: crispEdges;
    }
    svg use.d3 {
      stroke: black;
    }
    svg #redrect {
      fill: red;
    }
    svg text {
      font: 8pt"Menlo", "Consolas", "Lucida Console", "Courier", monospace;
    }
    svg line.leader {
      stroke: black;
      stroke-width: 1.5;
    }
    .x-axis path, .x-axis line, .y-axis path, .y-axis line {
      fill: none;
      stroke: none;
    }
    .realaxes line {
      fill: none;
      stroke: black;
      stroke-width: 1;
      shape-rendering: crispEdges;
    }
    .x-axis text, .y-axis text {
      font: 8pt"Menlo", "Consolas", "Lucida Console", "Courier", monospace;
    }
    .x-label, y-label {
      font-size: 9pt;
    }
  </style>
  <script src="http://d3js.org/d3.v3.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
  <script type="text/javascript" src="toshare.js"></script>
</body>

CSS

svg {
  /* transform: rotateZ(90deg); */
}

JavaScript

var projects = [{
  "name": "first",
  "date": "12/12/12",
  "img": "http://lorempixel.com/60/60/?1",
  "hours": 50
}, {
  "name": "second",
  "date": "1/2/12",
  "img": "http://lorempixel.com/60/60/?2",
  "hours": 2.5
}, {
  "name": "third",
  "date": "8/4/10",
  "img": "http://lorempixel.com/60/60/?3",
  "hours": 0.25
}, {
  "name": "fourth",
  "date": "1/29/08",
  "img": "http://lorempixel.com/60/60/?4",
  "hours": 17
}, {
  "name": "fifth",
  "date": "4/6/07",
  "img": "http://lorempixel.com/60/60/?5",
  "hours": 30
}, {
  "name": "sixth",
  "date": "3/14/11",
  "img": "http://lorempixel.com/60/60/?6",
  "hours": 13
},

];

for (var i = 0; i < 15; i++) {
  projects.push(randgenerator());
}


var w = $(window).width();
var h = $(window).height();

if (w >= h) {
  buffer = h / 8;
} else {
  buffer = w / 8;
}

var x, y, // scales
  r = 30, // circle radius
  s = 2 * r / 150; // scale factor (for icons)




var innerstroke = .75;
innerstroke /= s;



var format = d3.time.format("%m/%d/%y");
var formatDate = function (d) {
  return format.parse(d.date);
}




//                              SCALES




var x = d3.time.scale()
  .domain(d3.extent(projects, function (d) {
  return format.parse(d.date);
}))
  .nice(d3.time.year)
  .range([buffer, w - buffer]);

var y = d3.scale.linear()
  .domain(d3.extent(projects, function (d) {
  return d.hours;
}))
  .range([h - buffer * 1.5, buffer])
  .nice();

var ux = function (x) {
  return (x) / s - 75;
}
var uy = function (y) {
  return (y) / s - 75;
}



//                              MAIN DRAWING



var projectmap = d3.select("body")
  .append("svg")
  .attr("class", "projects")
  .attr("width", "100%")
  .attr("height", "100%");


projects.forEach(function (d, i) { // setup node origins
  d.x = x(formatDate(d));
  d.y = y(d.hours);
  d.x0 = x(formatDate(d));
  d.y0 = y(d.hours);
  d.r = r;
});



var padding = 7;

var force = d3.layout.force()
  .nodes(projects)
  .on("tick", tick)
  .gravity(0)
  .friction(0.95)
 ...