Torque CartoCSS Maker
This file contains 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
//node script for generating complex cartoCSS for torque | |
//as value increases, duration of marker gets longer, | |
//radius gets larger, and color moves up the ramp. | |
var breaks = [0,10,50,100] | |
var colors = ['#eff3ff','#bdd7e7','#6baed6','#2171b5']; | |
var data = { | |
"tableName":"#nepaltrends", | |
"valueCondition":0, | |
"numSteps":5, | |
"startMarkerWidth":1, | |
"endMarkerWidth":10, | |
"startOpacity":.9, | |
"endOpacity":.1 | |
}; | |
var d = data; | |
for(var i=0;i<breaks.length;i++){ | |
d.valueCondition=breaks[i]; | |
//d.startMarkerWidth+=5; | |
d.endMarkerWidth+=(3*i); | |
d.numSteps+=6; | |
calc(i); | |
} | |
function calc(i) { | |
var widthDiff = (d.endMarkerWidth-d.startMarkerWidth) / (d.numSteps - 1); | |
var opacityDiff = (d.endOpacity-d.startOpacity) / (d.numSteps - 1); | |
for(var j=0;j<d.numSteps;j++) { | |
//figure out marker width and opacity for this step | |
var l = d.tableName | |
+ '[value>=' + d.valueCondition + ']'; | |
if(j>0) { | |
l+= '[frame-offset=' + j + ']'; | |
} | |
l+= '{\n'; | |
if(j==0) { | |
l+= 'marker-fill:' + colors[i] + ';\n'; | |
} | |
var width = d.startMarkerWidth + (widthDiff * j); | |
l+= ' marker-width: ' + width + ';\n'; | |
var opacity = d.startOpacity + (opacityDiff * j); | |
l+= ' marker-fill-opacity: ' + opacity + ';\n'; | |
l+= '}' | |
console.log(l); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment