[ Launch: coffee MST graph ] 6563511 by zeffii
[ Launch: coffee_template ] 6527689 by zeffii
[ Launch: coffee_template ] 6448693 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6399870 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6382272 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6382237 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6379220 by zeffii
[ Launch: boomstick_motion_wcolor ] 6376715 by zeffii
[ Launch: boomstick_motion2 ] 6365156 by zeffii
[ Launch: boomstick_motion ] 6364686 by zeffii
[ Launch: boomstick ] 6364584 by zeffii
[ Launch: zeffii default ] 6364028 by zeffii
[ Launch: zeffii default ] 5033869 by zeffii
-
-
Save zeffii/6563511 to your computer and use it in GitHub Desktop.
coffee MST graph min
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
{"description":"coffee MST graph min","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"data2.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"util.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"injet.coffee":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.coffee":{"default":true,"vim":false,"emacs":false,"fontSize":12},"util.coffee":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/4ROHdPI.png"} |
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
# multiple MST in the same graph | |
between = tributary.between | |
#d3.select("body").style "background-color", d3.rgb(25, 25, 25) | |
svg = d3.select("svg") | |
svg.append("rect").attr({width:"100%", height:"100%", fill: d3.rgb(25,25,25) }); | |
group1 = svg.append("g").classed("group1", true) | |
text_style1 = | |
"fill": "#D8D8D8" | |
"font-size": 0.7 + "em" | |
"font-face": "sans-serif" | |
stroke: "none" | |
graph = [ | |
{x: 20, y: 50}, | |
{x: 120, y: 31}, | |
{x: 5, y: 166}, | |
{x: 95, y: 151}, | |
{x: 152, y: 88}, | |
] | |
edges = [ | |
{v1: 1, v2: 2, w: 2}, | |
{v1: 1, v2: 3, w: 2}, | |
{v1: 2, v2: 3, w: 2}, | |
{v1: 3, v2: 4, w: 2}, | |
{v1: 4, v2: 5, w: 4}, | |
{v1: 2, v2: 5, w: 4}, | |
] | |
# must be sparse and the lower of the two must be first. | |
mst1 = [[1,2],[2,3],[3,4],[4,5]] | |
mst2 = [[1,3],[2,3],[3,4],[4,5]] | |
mst3 = [[1,2],[2,3],[3,4],[2,5]] | |
draw_graph = (group, graph, edges, mst, pos) -> | |
path_all_edges = (d) -> | |
'M' + [graph[d.v1-1].x, graph[d.v1-1].y, graph[d.v2-1].x, graph[d.v2-1].y] | |
path_all_MST = (d) -> | |
'M' + [graph[d[0]-1].x, graph[d[0]-1].y, graph[d[1]-1].x, graph[d[1]-1].y] | |
draw_edges = (name, color, path_func, data) -> | |
all_edges = group.append('g').classed(name, true) | |
.attr("transform", "translate(" + pos + ")") | |
.style | |
stroke: color | |
'stroke-width': 5.3824 | |
all_e = all_edges.selectAll('g').data(data).enter() | |
all = all_e.append('g') | |
all.append('path') | |
.attr d: (d) -> path_func(d) | |
draw_edges('All_Edges', "#C55559", path_all_edges, edges) | |
draw_edges('MST_Edges', "#55B3C5", path_all_MST, mst) | |
# Weights | |
weights = group.append('g').classed('Weights', true) | |
.attr("transform", "translate(" + pos + ")") | |
wballs = weights.selectAll('g').data(edges).enter() | |
wball = wballs.append('g') | |
.classed("item_group2", true) | |
.attr | |
transform: (d) -> | |
p1 = graph[d.v1 - 1] | |
p2 = graph[d.v2 - 1] | |
p = between(p1, p2) | |
"translate(" + [p.x, p.y] + ")" | |
wball.append('circle') | |
.attr | |
r: 8 | |
wball.append('text') | |
.text((d) -> d.w) | |
.style(text_style1) | |
.attr | |
transform: "translate(" + [-3, 4] + ")" | |
# Nodes | |
nodes = group.append('g').classed('Nodes', true) | |
.attr("transform", "translate(" + pos + ")") | |
balls = nodes.selectAll('g').data(graph).enter() | |
ball = balls.append('g') | |
.classed("item_group", true) | |
.attr | |
transform: (d) -> "translate(" + [d.x, d.y] + ")" | |
ball.append('circle') | |
.attr | |
r: 11 | |
ball.append('text') | |
.text((d, i ) -> i+1) | |
.style(text_style1) | |
.attr | |
transform: "translate(" + [-4, 4] + ")" | |
pos1 = [62, 36] | |
pos2 = [62, 36+200] | |
pos3 = [62, 36+400] | |
draw_graph(group1, graph, edges, mst1, pos1) | |
draw_graph(group1, graph, edges, mst2, pos2) | |
draw_graph(group1, graph, edges, mst3, pos3) | |
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
.cm-s-elegant.CodeMirror { background: #1e2426; color: #696969; } | |
.cm-s-elegant div.CodeMirror-selected {background: #064968 !important;} /* 33322B*/ | |
.cm-s-elegant span.cm-variable { color:#22EFFF; } | |
.cm-s-elegant span.cm-variable-2 { color: #FFCCB4; } | |
.cm-s-elegant span.cm-variable-3 { color: white; } | |
.cm-s-elegant span.cm-string { color: Chartreuse; } | |
.cm-s-elegant span.cm-string-2 {color: Chartreuse;} | |
.cm-s-elegant span.cm-def {color: #FFCCB4; opacity: 1.0} | |
.cm-s-elegant span.cm-bracket { color: #EBEFE7; } | |
.cm-s-elegant pre { color:#FFF; } | |
.cm-s-elegant span.cm-qualifier { color:#C0C0C0; } | |
.cm-s-elegant span.cm-comment { color: #AFB4B4;} | |
.cm-s-elegant span.cm-property {color: #FDA676;} | |
.cm-s-elegant span.cm-number { color: #FF92EE;} | |
.cm-s-elegant span.cm-keyword { color: #FFFF18; } | |
.cm-s-elegant .CodeMirror-cursor { border-left: 1px solid white !important; } | |
.cm-s-elegant .CodeMirror-gutters {background: #505050;} | |
.cm-s-elegant .CodeMirror-linenumber {color: #D3D3D3;} | |
.Weights { | |
fill: #42424D; | |
stroke: #C55555; | |
stroke-width: 2px; | |
} | |
.Nodes { | |
fill: #42424D; | |
stroke: #aeaeae; | |
stroke-width: 3.7px; | |
} |
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
tributary.between = (p1, p2) -> | |
x: (p1.x + p2.x) * 0.5 | |
y: (p1.y + p2.y) * 0.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment