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.

            
              <div id="maind3div"></div>
            
          
!
            
              circle {
    fill:brown;
    fill-opacity: .5;
    stroke: #fff;
    stroke-width: .5px;
}
 circle:hover {
    stroke: black;
    stroke-width: 1px;
}


.axis path,
.axis line {
    fill: none;
    stroke: black;
    shape-rendering: crispEdges;
}

.axis text {
    font-family: sans-serif;
    font-size: 11px;
}
            
          
!
            
              //age educ black hisp married nodeg re74 re75 re78 u74 u75
    //(real earnings) (unemployed)

    //this line basically waits until the page is loaded then loads the datasets and calls the dataready function
    $(document).ready(function() {
        //this function says 'load a csv and send it to this other function (dataready) when ready
       
      d3.csv("https://sri.utah.edu/nhstes/simulatedmhdata.csv", dataready);
      
    });

    var dataset = [];
    var svg;
    var circles;

    function dataready(data) {
        dataset=data;
      
      //this first example is to just see what d3 is really doing
        /*
         d3.select("#maind3div").selectAll("p")
         .data(dataset)
         .enter()
         .append("p")
         .text(function(d) {
          return "Therapist ID "+d.nclients+ "Change OQ: "+d.changeoqy1;

         });
         */
      
         
         

        //lets make our main deal here
      
        
        svg = d3.select("#maind3div")
            .append("svg")
            .attr("width", 1000)   // <-- Canvas Width
            .attr("height", 1000); // <-- Canvas Height
    
     
        makeXScale();
        
      
      makeYScale();
      
      //change the radius to the number of patients
        circles =  svg.selectAll("circle")
            .data(dataset)
            .enter()
            .append("circle")
            .attr("r",function(d){
              return d.nclients;
          }).attr("cx", function(d, i) {
                return xScale(d.changeoqy1);
            });
      
       
      //try changing the radius to changeinoq year 1, year 2 etc
       
     
      
      

 
 
      
      
      
      
      
        //now lets make a y axis  but not for a few seconds
    
        setTimeout(function() { moveToNew(makeYScale());; }, 2000)
        setInterval(function() { moveToNew();; }, 2000);
        setInterval(function() { moveToNew2();; }, 8000);
        setInterval(function() { moveToNew3();; }, 10000);
      
    }

    var yScale;
    var xScale;

    function makeXScale(){
      xScale = d3.scale.linear()
            .domain([10,-40])
            .range([80, 800]);
      var xaxis=d3.svg.axis()
            .scale(xScale)
            .orient("bottom");
        svg.append("g")
            .attr("class", "axis")  //Assign "axis" class
            .attr("transform", "translate(0," + (500) + ")")
            .call(xaxis);
      
      
    }
    function makeYScale(){
        yScale = d3.scale.linear()
            .domain([100,30])
            .range([120, 500]);
        var yaxis=d3.svg.axis()
            .scale(yScale)
            .orient("left");
        svg.append("g")
            .attr("class", "axis")  //Assign "axis" class
            .attr("transform", "translate(80,0)")
            .call(yaxis);
    }
    function moveToNew(){
        //set up a new axis


        svg.selectAll("circle").transition().duration(2000).delay(0)
          .attr("cy",        function(d) {
            return yScale(d.startingoqy1);
        })
      .attr("cx",        function(d) {
            return xScale(d.changeoqy1);
        });
    }

    function moveToNew2(){

        svg.selectAll("circle").transition().duration(2000).delay(0)
          .attr("cy",        function(d) {
            return yScale(d.startingoqy2);

        })
          .attr("cx",        function(d) {
            return xScale(d.changeoqy2);
        });
    }
    function moveToNew3(){
        svg.selectAll("circle").transition().duration(2000).delay(0)
          .attr("cy",        function(d) {
            return yScale(d.startingoqy3)
           })
          .attr("cx",        function(d) {
            return xScale(d.changeoqy3);
        });

       
    }







            
          
!
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