JSFiddle - React, Tailwind, and code Playground
HTML
<div id = "container">
<div class = "svg"></div>
<div id = "tag"></div>
</div>
<body>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<body>
</body>
CSS
* {
margin: 0;
padding: 0;
}
body {
background: #fff;
font-family: 'Open-Sans',sans-serif;
}
#container{
margin: 0 auto;
position: relative;
width:800px;
overflow: visible;
}
.svg {
width:800px;
height:400px;
overflow: visible;
position:absolute;
}
.grid .tick {
stroke: lightgrey;
opacity: 0.3;
shape-rendering: crispEdges;
}
.grid path {
stroke-width: 0;
}
#tag {
color: white;
background: #FA283D;
width: 150px;
position: absolute;
display: none;
padding:3px 6px;
margin-left: -80px;
font-size: 11px;
}
#tag:before {
border: solid transparent;
content: ' ';
height: 0;
left: 50%;
margin-left: -5px;
position: absolute;
width: 0;
border-width: 10px;
border-bottom-color: #FA283D;
top: -20px;
}
JavaScript
var w = 800;
var h = 400;
var svg = d3.selectAll(".svg")
//.selectAll("svg")
.append("svg")
.attr("width", w)
.attr("height", h)
.attr("class", "svg");
var taskArray =[
{
task: "",
type: "Kick-Off",
startTime: "2019-1-28", //year/month/day
endTime: "2019-2-1",
details: "This actually didn't take any conceptualization"
},
{
task: "",
type:"Mobilization",
startTime: "2019-2-1",
endTime: "2019-2-6",
details: "No sketching either, really"
},
{
task: "",
type: "Design",
startTime: "2019-2-6",
endTime: "2019-2-9"
},
{
task: "",
type: "Development",
startTime: "2019-2-2",
endTime: "2019-2-6",
details: "all three lines of it"
},
{
task: "",
type: "IT",
startTime: "2019-2-6",
endTime: "2019-2-9"
},
{
task: "",
type: "PT",
startTime: "2019-2-9",
endTime: "2019-2-12",
details: "This counts, right?"
},
{
task: "",
type: "UAT",
startTime: "2019-2-12",
endTime: "2019-2-14"
},
{
task: "",
type: "RT",
startTime: "2019-2-8",
endTime: "2019-2-13",
details: "All the things"
},
{
task: "",
type: "Have Final Eval By",
startTime: "2019-2-13",
endTime: "2019-2-16"
},
];
var dateFormat = d3.time.format("%Y-%m-%d");
var timeScale = d3.time.scale()
.domain([d3.min(taskArray, function(d) {return dateFormat.parse(d.startTime);}),
d3.max(taskArray, function(d) {return dateFormat.parse(d.endTime);})])
.range([0,w-150]);
var categories = new Array();
for (var i = 0; i < taskArray.length; i++){
categories.push(taskArray[i].type);
}
var catsUnfiltered = categories; //for vert labels
categories = checkUnique(categories);
makeGant(taskArray, w, h);
var title = svg.append("text")
.text("Gantt Chart Process")
.attr("x", w/2)
.attr("y", 25)
.attr("text-anchor", "middle")
.attr("font-size", 18)
...