Skip to content

Commit 84d715c

Browse files
author
hdngr
committed
Merge branch 'release-0.4.1'
2 parents 27c495a + 15f8c1c commit 84d715c

136 files changed

Lines changed: 416 additions & 19328 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gruntfile.coffee

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ module.exports = (grunt) ->
7474
shell:
7575
commitBuild:
7676
command: "git add -A && git commit -am 'commit dist files for #{pkg.version}'"
77-
docs:
78-
command: 'grunt --gruntfile site/Gruntfile.coffee'
7977

8078
# Watches files for changes and runs tasks based on the changed files
8179
watch:
@@ -499,10 +497,6 @@ module.exports = (grunt) ->
499497
cwd: "<%= yeoman.dist %>"
500498
src: "**"
501499

502-
litcoffee:
503-
files:
504-
'site/app/docs/_documentation/Annotated-Source.md':'.tmp/scripts/alchemysrc.coffee.md'
505-
506500
concurrent:
507501
# Run some tasks in parallel to speed up build process
508502
server: ["compass:server", "coffee:dev", "copy:styles"]
@@ -560,7 +554,7 @@ module.exports = (grunt) ->
560554
pullRequest = grunt.option('pr')
561555
travis = grunt.option('travis')
562556
grunt.registerTask "default",
563-
# release alchemy and build docs
557+
# release alchemy
564558
if releaseFlag
565559
["test:dist",
566560
"build",
@@ -572,7 +566,6 @@ module.exports = (grunt) ->
572566
"concat:s3", # squash vendor and alchemy files for cdn
573567
"concat:s3Version", # apply version numbers for cdn
574568
"s3:production" # publish files to s3 for cdn
575-
"shell:docs", # publish docs
576569
]
577570
# Travis-ci on a commit to the main repo branches
578571
else if travis

app/index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<![endif]-->
2727

2828
<div class="alchemy" id="alchemy"></div>
29-
<div class="alchemy" id="chemistry"></div>
3029

3130
<!-- build:js({.tmp,app}) scripts/vendor.js -->
3231
<!-- bower:js -->
@@ -39,9 +38,9 @@
3938

4039
<script src="scripts/alchemy.js"></script>
4140
<script type="text/javascript">
41+
4242
var config = {
43-
dataSource: "sample_data/contrib.json",
44-
// curvedEdges: true
43+
dataSource: "sample_data/contrib.json"
4544
}
4645

4746
var alchemy = new Alchemy(config)

app/scripts/alchemy/API/create.coffee.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# You should have received a copy of the GNU Affero General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17-
class Alchemy::create
17+
class Alchemy::Create
1818
constructor: (instance)->
1919
@a = instance
2020
nodes: (nodeMap, nodeMaps...) ->
@@ -36,11 +36,12 @@
3636
3737
nodeMaps = _.union nodeMaps, nodeMap
3838
# create the results set
39-
results = []
4039
for n in nodeMaps
4140
# check if the node already exists
4241
registerNode n
43-
results
42+
43+
@a.updateGraph() if @a.initial
44+
4445
edges: (edgeMap, edgeMaps...) ->
4546
a = this.a
4647
registerEdge = (edge) ->
@@ -73,8 +74,6 @@
7374
aEdge = new a.models.Edge(edge, 0)
7475
a._edges["#{edge.source}-#{edge.target}"] = [aEdge]
7576
[aEdge]
76-
77-
if edgeMaps.length isnt 0
78-
console.warn "Make sure this function supports multiple arguments"
79-
else
80-
registerEdge edgeMap
77+
allEdges = _.uniq _.flatten arguments
78+
_.each allEdges, (e)-> registerEdge e
79+
@a.updateGraph() if @a.initial

app/scripts/alchemy/API/get.coffee.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# make js array method called ._state
1919
# @a.set. nest set inside of get
2020
21-
Alchemy::get = (instance)->
21+
Alchemy::Get = (instance) ->
2222
a: instance
2323
_el: []
2424
_elType: null
@@ -60,8 +60,8 @@
6060
elType = @_elType
6161
@_el = do (elType)->
6262
switch elType
63-
when "node" then return _.values a._nodes
64-
when "edge" then return _.flatten _.map a._edges, (e)-> e
63+
when "node" then return a.elements.nodes.val
64+
when "edge" then return a.elements.edges.flat
6565
@_makeChain @_el
6666
6767
elState: (state) ->
@@ -100,14 +100,13 @@
100100
clusterColoursObject
101101
102102
###### ALL METHODS BELOW THIS POINT WILL BE DEPRECATED UPON 1.0 ######
103-
allEdges: ->
104-
_.flatten _.map(@a._edges, (edgeArray) -> e for e in edgeArray)
103+
allEdges: -> @a.elements.nodes.flat
105104
106105
allNodes: (type) ->
107106
if type?
108107
_.filter @a._nodes, (n) -> n if n._nodeType is type
109108
else
110-
_.map @a._nodes, (n) -> n
109+
@a.elements.nodes.val
111110
112111
getNodes: (id, ids...)->
113112
a = @a
@@ -120,4 +119,4 @@
120119
edge_id = "#{id}-#{target}"
121120
@a._edges[edge_id]
122121
else if id? and not target?
123-
@a._nodes[id]._adjacentEdges
122+
@a._nodes[id]._adjacentEdges

app/scripts/alchemy/API/remove.coffee.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# You should have received a copy of the GNU Affero General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17-
class Alchemy::remove
18-
constructor: (instance)->
17+
class Alchemy::Remove
18+
constructor: (instance) ->
1919
@a = instance
2020
2121
nodes: (nodeMap) ->

app/scripts/alchemy/API/set.coffee.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
# You should have received a copy of the GNU Affero General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17-
Alchemy::set =
18-
state: (key, value) -> alchemy.state.key = value
17+
Alchemy::Set = (instance)->
18+
a : instance
19+
state: (key, value) -> @a.state.key = value

app/scripts/alchemy/Alchemy.coffee.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ title: Anotated Source
2929
@a = @
3030
3131
@version = "#VERSION#"
32-
@get = new @get @
33-
@remove = new @remove @
34-
@create = new @create @
32+
# give access to default conf
33+
@get = new @Get @
34+
@remove = new @Remove @
35+
@create = new @Create @
36+
@set = new @Set @
37+
3538
@drawing =
3639
DrawEdge : DrawEdge @
3740
DrawEdges: DrawEdges @
@@ -63,10 +66,12 @@ title: Anotated Source
6366
"layout": "default"
6467
6568
@startGraph = @startGraph @
69+
@updateGraph = @updateGraph @
6670
@generateLayout = @generateLayout @
6771
@svgStyles = @svgStyles @
6872
@interactions = @interactions @
6973
@search = @search @
74+
@plugins = @plugins @
7075
7176
# alchemy._nodes stores a node object as the value with the unique
7277
# id specified in the GraphJSON.
@@ -91,44 +96,35 @@ title: Anotated Source
9196
9297
begin: (userConf) ->
9398
# overide configuration with user inputs
94-
@setConf userConf
99+
conf = @setConf userConf
95100
switch typeof @conf.dataSource
96101
when 'string' then d3.json @a.conf.dataSource, @a.startGraph
97102
when 'object' then @a.startGraph @a.conf.dataSource
98-
103+
104+
@plugins.init()
99105
Alchemy::instances.push @
100106
101107
@
102108
103109
setConf: (userConf) ->
104110
# apply base themes
105111
if userConf.theme?
106-
userConf = _.merge _.cloneDeep(defaults), @a.themes["#{userConf.theme}"]
112+
userConf = _.merge _.cloneDeep(@defaults), @a.themes["#{userConf.theme}"]
107113
108114
for key, val of userConf
109115
switch key
110116
when "clusterColors" then userConf["clusterColours"] = val
111117
when "backgroundColor" then userConf["backgroundColour"] = val
112118
when "nodeColor" then userConf[nodeColour] = val
113119
114-
@a.conf = _.merge _.cloneDeep(defaults), userConf
120+
@a.conf = _.merge _.cloneDeep(@defaults), userConf
115121
116122
# All alchemy instances in order of creation.
117123
instances: []
118124
119-
getInst: (element)->
120-
#Edge or Node
121-
if element.a?
122-
element.a
123-
124-
#_d3 packet
125-
else if element.self?
126-
element.self.a
127-
128-
#SVG element
129-
else
130-
Alchemy::instances[d3.select(element).attr("alchInst")]
131-
125+
getInst: (svg)->
126+
instNumber = parseInt d3.select(svg).attr("alchInst")
127+
Alchemy::instances[instNumber]
132128
133129
root = exports ? this
134130
root.Alchemy = Alchemy

app/scripts/alchemy/clustering/clustering.coffee.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
gravity: (k) -> _gravity(k)
5353
5454
identifyClusters: (a)->
55-
nodes = a.get.allNodes()
56-
clusters = _.uniq _.map(_.values(nodes), (node)-> node.getProperties()[a.conf.clusterKey])
55+
nodes = a.elements.nodes.val
56+
clusters = _.uniq _.map(nodes, (node)-> node.getProperties()[a.conf.clusterKey])
5757
@clusterMap = _.zipObject clusters, [0..clusters.length]
5858
5959
getClusterColour: (clusterValue) ->
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
Alchemy::Index = (instance, all)->
3+
a = instance
4+
5+
# Index maintains an index of common mappings/selections of
6+
# nodes and edges to reduce iteration during non-creative/destructive
7+
# operation of alchemy.
8+
9+
# a.elements is set with base iterations that other iterations are made
10+
# from. These are seperated out so that other indexes can use them
11+
# during creation instead of recreating them during index.
12+
13+
# ORDERING IS IMPORTANT!
14+
# Before reordering or adding a new index, see if you can
15+
# use a previous index in it's creation.
16+
17+
elements =
18+
nodes:
19+
val: do -> _.values a._nodes
20+
edges:
21+
val: do -> _.values a._edges
22+
23+
nodes = elements.nodes
24+
edges = elements.edges
25+
26+
elements.edges.flat = do -> _.flatten edges.val
27+
28+
elements.nodes.d3 = do -> _.map nodes.val, (n)-> n._d3
29+
elements.edges.d3 = do -> _.map edges.flat, (e)-> e._d3
30+
31+
a.elements = elements
32+
33+
() ->
34+
35+
# Auxiliary indexes.
36+
a.elements.nodes.svg = do -> a.vis.selectAll 'g.node'
37+
38+
a.elements.edges.svg = do -> a.vis.selectAll 'g.edge'

app/scripts/alchemy/core/interactions.coffee.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@
1818
a = instance
1919
2020
edgeClick: (d) ->
21-
a = d.self.a
22-
21+
# Don't consider drag a click
22+
return if d3.event.defaultPrevented
23+
# Don't tell alchemy about the click
2324
d3.event.stopPropagation()
25+
# Convert d3.edge to alchemy.edge
2426
edge = d.self
27+
28+
if typeof a.conf.edgeClick is 'function'
29+
a.conf.edgeClick(edge)
2530
if edge._state != "hidden"
2631
edge._state = do ->
2732
return "active" if edge._state is "selected"
2833
"selected"
2934
edge.setStyles()
30-
if typeof a.conf.edgeClick? is 'function'
31-
a.conf.edgeClick()
3235
3336
edgeMouseOver: (d) ->
3437
edge = d.self
@@ -70,17 +73,19 @@
7073
nodeClick: (n) ->
7174
# Don't consider drag a click
7275
return if d3.event.defaultPrevented
73-
76+
# Don't tell alchemy about the click
7477
d3.event.stopPropagation()
78+
# Convert d3.node to alchemy.node
7579
node = n.self
7680
81+
if typeof a.conf.nodeClick is 'function'
82+
a.conf.nodeClick(node)
83+
7784
if node._state != "hidden"
7885
node._state = do ->
7986
return "active" if node._state is "selected"
8087
"selected"
8188
node.setStyles()
82-
if typeof a.conf.nodeClick is 'function'
83-
a.conf.nodeClick(n)
8489
8590
zoom: (extent) ->
8691
if not @_zoomBehavior?
@@ -113,16 +118,16 @@
113118
@._zoomBehavior.scale(scale)
114119
.translate([x,y])
115120
116-
toggleControlDash: () ->
117-
#toggle off-canvas class on click
118-
offCanvas = a.dash.classed("off-canvas") or
119-
a.dash.classed("initial")
120-
a.dash
121-
.classed {
122-
"off-canvas": !offCanvas,
123-
"initial" : false,
124-
"on-canvas" : offCanvas
125-
}
121+
# toggleControlDash: () ->
122+
# #toggle off-canvas class on click
123+
# offCanvas = a.dash.classed("off-canvas") or
124+
# a.dash.classed("initial")
125+
# a.dash
126+
# .classed {
127+
# "off-canvas": !offCanvas,
128+
# "initial" : false,
129+
# "on-canvas" : offCanvas
130+
# }
126131
127132
nodeDragStarted: (d, i) ->
128133
d3.event.preventDefault

0 commit comments

Comments
 (0)