Created
March 9, 2014 22:50
-
-
Save ABrouwer/9456178 to your computer and use it in GitHub Desktop.
Assignment 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // append validation plugin | |
| $(".content").append('<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>'); | |
| function update (data) { | |
| //Creating an SVG element | |
| var w = 500; | |
| var h = 200; | |
| var barPadding = 1; | |
| var svg = d3.select("body") | |
| .append("svg") | |
| .attr("width", w) | |
| .attr("height", h); | |
| svg.selectAll("rect") | |
| .data(dataset) | |
| .enter() | |
| .append("rect") | |
| .attr("x", 0) | |
| .attr("y", 0) | |
| .attr("width", 20) | |
| .attr("height", 100) | |
| .attr("x", function(d,i) { | |
| return i * (w / dataset.length); | |
| }) | |
| .attr ("y", function (d){ | |
| return h - (d * 4); | |
| }) | |
| .attr ("width", w / dataset.length - barPadding) | |
| .attr ("height", function(d) { | |
| return d * 4; | |
| }) | |
| .attr ("fill", function(d) { | |
| return "rgb(20, 240, " + (d * 10) + ")"; | |
| }); | |
| svg.selectAll("text") | |
| .data(dataset) | |
| .enter() | |
| .append("text") | |
| .text(function(d){ | |
| return d; | |
| }) | |
| .attr("x", function(d, i) { | |
| return i * (w /dataset.length) + 5; | |
| }) | |
| .attr("y", function(d) { | |
| return h - (d * 4) + 15; | |
| }) | |
| .attr("font-family", "sans-serif") | |
| .attr("font-size", "11px") | |
| .attr("fill", "white"); | |
| }; | |
| //defining dataset | |
| var dataset = []; | |
| d3.json('https://negativepostdata.firebaseio.com/', function(data) { | |
| vibData = data; | |
| }); | |
| //refer to new firebase | |
| myDataRef = new Firebase('https://negativepostdata.firebaseio.com/'); | |
| //new Form | |
| $("body").append('<input type="checkbox" name="post" id="LikesOnPost" value="LikesOnPost"> <label for="LikesOnPost">Likes on post</label><input type="checkbox" name="post" id="LikesOnComments" value="LikesOnComments"> <label for="LikesOnComments">Likes on comments</label><input type="checkbox" name="post" id="PositiveComment" value="PositiveComment" > <label for="PositiveComment" >Positive comment</label><input type="checkbox" name="post" id="NegativeComments" value="NegativeComments" > <label for="NegativeComments" >Negative comment</label>'); | |
| //click event | |
| $("#LikesOnPost").on("checked", function(d){ | |
| data=d.val()* 4 | |
| return (d) | |
| }); | |
| $("#LikesOnComments").on("checked", function(d){ | |
| data=d.val()* 4 | |
| return (d) | |
| }); | |
| $("#PositiveComment").on("checked", function(d){ | |
| data=d.val()* 4 | |
| return (d) | |
| }); | |
| $("#NegativeComments").on("checked", function(d){ | |
| data=d.val()* 4 | |
| return (d) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment