Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
huston committed Jun 30, 2014
2 parents 3990208 + ffe65e3 commit 02f1675
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 172 deletions.
7 changes: 1 addition & 6 deletions app/scripts/alchemy/core/controls.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ alchemy.controlDash =
d3.select(".alchemy")
.append("div")
.attr("id", "control-dash-wrapper")
.attr("class", "col-md-4 off-canvas")

d3.select(".alchemy")
.append("div")
.attr("id", "control-dash-background")
.attr("class", "col-md-4")
.attr("class", "col-md-4 initial")

# add the dash toggle button
d3.select("#control-dash-wrapper")
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/alchemy/core/filters.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ alchemy.filters =

for edge in alchemy.edge.filter("[source-target*='#{nodeId}']").data()
edgeType = edge.caption
if edgeType in alchemy.conf.edgeTypes
if alchemy.conf.edgeTypes? and edgeType in alchemy.conf.edgeTypes
#the edge should not show if target of source node is inactive
if d3.select("#li-#{edgeType}").classed("disabled")
alchemy.edge.filter("[source-target*='#{nodeId}']")
Expand Down
12 changes: 8 additions & 4 deletions app/scripts/alchemy/core/interactions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ alchemy.interactions =
return d.id is c.id or alchemy.edges.some (e) ->
return ((e.source.id is c.id and e.target.id is d.id) or
(e.source.id is d.id and e.target.id is c.id)) and
d3.select(".edge[id*='#{d.id}']").classed("active"))
d3.select(".edge[source-target*='#{d.id}']").classed("active"))

if typeof alchemy.conf.nodeClick == 'function'
alchemy.conf.nodeClick(c)
Expand Down Expand Up @@ -138,6 +138,10 @@ alchemy.interactions =

toggleControlDash: () ->
#toggle off-canvas class on click
offCanvas = d3.select("#control-dash-wrapper").classed("off-canvas")
d3.select("#control-dash-wrapper").classed("off-canvas": !offCanvas, "on-canvas": offCanvas)
d3.select("#control-dash-background").classed("off-canvas": !offCanvas, "on-canvas": offCanvas)
offCanvas = d3.select("#control-dash-wrapper").classed("off-canvas") or d3.select("#control-dash-wrapper").classed("initial")
d3.select("#control-dash-wrapper").classed("off-canvas": !offCanvas, "initial": false, "on-canvas": offCanvas)





91 changes: 51 additions & 40 deletions app/scripts/alchemy/core/stats.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ alchemy.stats =

edgeStats: () ->
#general edge stats
edgeData = []
edgeData = null
edgeNum = d3.selectAll(".edge")[0].length
activeEdges = d3.selectAll(".edge.active")[0].length
inactiveEdges = d3.selectAll(".edge.inactive")[0].length
Expand All @@ -82,6 +82,7 @@ alchemy.stats =

#add stats for edge types
if alchemy.conf.edgeTypes
edgeData = []
for e in d3.selectAll(".edge")[0]
currentRelationshipTypes[[e].caption] = true

Expand All @@ -97,13 +98,14 @@ alchemy.stats =

nodeStats: () ->
#general node stats
nodeData = []
nodeData = null
totalNodes = d3.selectAll(".node")[0].length
activeNodes = d3.selectAll(".node.active")[0].length
inactiveNodes = d3.selectAll(".node.inactive")[0].length

#add stats for all node types
if alchemy.conf.nodeTypes
nodeData = []
nodeKey = Object.keys(alchemy.conf.nodeTypes)
for nodeType in alchemy.conf.nodeTypes[nodeKey]
nodeNum = d3.selectAll("g.node.#{nodeType}")[0].length
Expand All @@ -120,44 +122,52 @@ alchemy.stats =
return nodeData

insertSVG: (element, data) ->
width = alchemy.conf.graphWidth() * .25
height = 250
radius = width / 4
color = d3.scale.category20()

arc = d3.svg.arc()
.outerRadius(radius - 10)
.innerRadius(radius/2)

pie = d3.layout.pie()
.sort(null)
.value((d) -> d[1])

svg = d3.select("##{element}-stats-graph")
.append("svg")
.append("g")
.style({"width": width, "height":height})
.attr("transform", "translate(" + width/2 + "," + height/2 + ")")

arcs = svg.selectAll(".arc")
.data(pie(data))
.enter().append("g")
.classed("arc", true)
.on("mouseover", (d,i) -> d3.select("##{data[i][0]}-stat").classed("hidden", false))
.on("mouseout", (d,i) -> d3.select("##{data[i][0]}-stat").classed("hidden", true))

arcs.append("path")
.attr("d", arc)
.attr("stroke", (d, i) -> color(i))
.attr("stroke-width", 2)
.attr("fill-opacity", "0.3")

arcs.append("text")
.attr("transform", (d) -> "translate(" + arc.centroid(d) + ")")
.attr("id", (d, i)-> "#{data[i][0]}-stat")
.attr("dy", ".35em")
.classed("hidden", true)
.text((d, i) -> data[i][0])
console.log data
if data is null
console.log "no data!"
d3.select("##{element}-stats-graph")
.html("<br><h4 class='no-data'>There are no #{element}Types listed in your conf.</h4>")


else
width = alchemy.conf.graphWidth() * .25
height = 250
radius = width / 4
color = d3.scale.category20()

arc = d3.svg.arc()
.outerRadius(radius - 10)
.innerRadius(radius/2)

pie = d3.layout.pie()
.sort(null)
.value((d) -> d[1])

svg = d3.select("##{element}-stats-graph")
.append("svg")
.append("g")
.style({"width": width, "height":height})
.attr("transform", "translate(" + width/2 + "," + height/2 + ")")

arcs = svg.selectAll(".arc")
.data(pie(data))
.enter().append("g")
.classed("arc", true)
.on("mouseover", (d,i) -> d3.select("##{data[i][0]}-stat").classed("hidden", false))
.on("mouseout", (d,i) -> d3.select("##{data[i][0]}-stat").classed("hidden", true))

arcs.append("path")
.attr("d", arc)
.attr("stroke", (d, i) -> color(i))
.attr("stroke-width", 2)
.attr("fill-opacity", "0.3")

arcs.append("text")
.attr("transform", (d) -> "translate(" + arc.centroid(d) + ")")
.attr("id", (d, i)-> "#{data[i][0]}-stat")
.attr("dy", ".35em")
.classed("hidden", true)
.text((d, i) -> data[i][0])



Expand All @@ -166,3 +176,4 @@ alchemy.stats =
alchemy.stats.nodeStats()
if alchemy.conf.edgeStats is true
alchemy.stats.edgeStats()

Loading

0 comments on commit 02f1675

Please sign in to comment.