Last active
February 17, 2017 07:47
-
-
Save isaacmg/ed0f046254781baf04832874674bc572 to your computer and use it in GitHub Desktop.
Updating D3js with SocketIO
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
//update function | |
function update(message1, caller,flowInfo) { | |
if(caller==0){ | |
var message1 = JSON.parse(message1.value) | |
} | |
var tx = message1.some_text; | |
var colorS = color(message1.height); | |
svg.append("circle") | |
.attr("cx", function(d) { | |
return projection([message1.value.timeSeries[0].sourceInfo.geoLocation.geogLocation.longitude, message1.value.timeSeries[0].sourceInfo.geoLocation.geogLocation.latitude])[0]; }) | |
.attr("cy", function(d) { | |
return projection([message1.value.timeSeries[0].sourceInfo.geoLocation.geogLocation.longitude, message1.value.timeSeries[0].sourceInfo.geoLocation.geogLocation.latitude])[1]; | |
}) | |
.attr("r", 4) // circle radius | |
.attr("id", "dot" + "wwd") | |
.style("fill", colorS) | |
.on("mouseover", function(d) { | |
div.transition() | |
.duration(200) | |
.style("opacity", .9); | |
div.html(tx) | |
.style("left", (d3.event.pageX) + "px") | |
.style("top", (d3.event.pageY - 28) + "px"); | |
}) | |
.on("mouseout", function(d) { | |
div.transition() | |
.duration(1000) | |
.style("opacity", 0); | |
}); | |
} | |
//init socket | |
var socket = io(); | |
//on message call update | |
socket.on('chat message', function(msg){ | |
update(msg,0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment