D3 Playground

by Bryson Murray

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://d3js.org/d3.v6.min.js"></script>
<div id ="container">
    <div id ="header">
        <h1>Demo Scatterplot</h1>
    </div>
    <div id ="sidebar">
    </div>
    <div id ="d3_content">
    </div>
    <div id ="footer">
    </div>
</div>

CSS

h1 {
    color: #ffffff;
    font-family:  'Raleway';
    font-weight: normal;
        font-size: 1.75em;
    letter-spacing: .2em;
    line-height: 1.1em;
    margin:0px;
    text-align: center;
    text-transform: uppercase;
}
#container {
    width:800px;
}
#header {
    width:800px;
    height: 50px;
    padding: 5px;
    background: #1abc9c;
}
#sidebar {
    height:400px;
    width:150px;
    background: #1abc9c;
    float:left;
}
#content {
    background-color:#ffffff;
    height:400px;
    width:650px;
    float:left;
}
#footer {
    width:800px;
    height: 50px;
    background: #1abc9c;
    float:left;
}
circle {
    stroke: #1abc9c;
    stroke-width: 2;
    fill: white;
}
.tooltip,
.d3-tip {
     position: absolute;
     font-family:  'Raleway';
     line-height: 1;
     padding: 1px;
     background: transparent;
     color: #000;
     border-radius: 2px;
 }

JavaScript

circle_data = [{"x": 100,
               "y": 100,
               "r": 10},
              {"x": 200,
               "y": 250,
               "r": 10},
              {"x": 300,
               "y": 180,
               "r": 10}];
horror = [{
    "name": "ape man",
        "physicalstrength": 20,
        "fearfactor": 7,
        "killingpower": 12,
        "horrorrating": 4,
        "cluster": 1
}, {
    "name": "godzilla",
        "physicalstrength": 3,
        "fearfactor": 5,
        "killingpower": 4,
        "horrorrating": 8,
        "cluster": 2
}, {
    "name": "the ghoul",
        "physicalstrength": 7,
        "fearfactor": 12,
        "killingpower": 2,
        "horrorrating": 7,
        "cluster": 1
}, {
    "name": "the freak",
        "physicalstrength": 9,
        "fearfactor": 2,
        "killingpower": 1,
        "horrorrating": 17,
        "cluster": 1
}, {
    "name": "dracula",
        "physicalstrength": 4,
        "fearfactor": 17,
        "killingpower": 5,
        "horrorrating": 16,
        "cluster": 2
}, {
    "name": "the hangman",
        "physicalstrength": 2,
        "fearfactor": 4,
        "killingpower": 13,
        "horrorrating": 8,
        "cluster": 2
}, {
    "name": "incredible melting man",
        "physicalstrength": 3,
        "fearfactor": 8,
        "killingpower": 15,
        "horrorrating": 6,
        "cluster": 1
}, {
    "name": "the thing",
        "physicalstrength": 19,
        "fearfactor": 4,
        "killingpower": 11,
        "horrorrating": 7,
        "cluster": 1
}];

// create a tooltip
var Tooltip = d3.select("#d3_content")
  .append("div")
  .style("opacity", 0)
  .attr("class", "tooltip")
  .style("background-color", "orange")
  .style("border", "solid", "gray")
  .style("border-width", "2px")
  .style("border-radius", "5px")
  .style("padding", "5px");
 // Three function that change the tooltip when user hover / move / leave a cell
var mouseover = function(event,d) {
    Tooltip
      .style("opacity",...