|
23 | 23 | if d3.select(conf.divSelector).empty() |
24 | 24 | console.warn a.utils.warnings.divWarning() |
25 | 25 |
|
26 | | - # see if data is ok |
| 26 | + # Verify passed in data |
27 | 27 | if not data |
| 28 | + data = |
| 29 | + nodes:[] |
| 30 | + edges:[] |
28 | 31 | a.utils.warnings.dataWarning() |
| 32 | + if not data.edges? then data.edges = [] |
29 | 33 |
|
30 | 34 | # create nodes map and update links |
31 | 35 | a.create.nodes data.nodes |
|
40 | 44 | .attr "xlink", "http://www.w3.org/1999/xlink" |
41 | 45 | .attr "pointer-events", "all" |
42 | 46 | .attr "style", "background:#{conf.backgroundColour};" |
43 | | - .attr "alchInst", Alchemy::instances.length |
| 47 | + .attr "alchInst", (Alchemy::instances.length - 1) |
44 | 48 | .on 'click', a.interactions.deselectAll |
45 | 49 | .call a.interactions.zoom(conf.scaleExtent) |
46 | 50 | .on "dblclick.zoom", null |
|
51 | 55 | a.interactions.zoom().scale conf.initialScale |
52 | 56 | a.interactions.zoom().translate conf.initialTranslate |
53 | 57 |
|
| 58 | + a.index = Alchemy::Index a |
| 59 | +
|
54 | 60 | a.generateLayout() |
55 | 61 | a.controlDash.init() |
56 | 62 |
|
57 | 63 | #enter/exit nodes/edges |
58 | | - d3Edges = _.flatten _.map(a._edges, (edgeArray) -> e._d3 for e in edgeArray) |
59 | | - d3Nodes = _.map a._nodes, (n) -> n._d3 |
| 64 | + d3Edges = a.elements.edges.d3 |
| 65 | + d3Nodes = a.elements.nodes.d3 |
60 | 66 |
|
61 | 67 | # if start |
62 | 68 | a.layout.positionRootNodes() |
63 | 69 | a.force.start() |
64 | | - while a.force.alpha() > 0.005 |
65 | | - a.force.tick() |
| 70 | + if conf.forceLocked |
| 71 | + while a.force.alpha() > 0.005 |
| 72 | + a.force.tick() |
66 | 73 |
|
67 | 74 | a._drawEdges = a.drawing.DrawEdges |
68 | | - a._drawEdges.createEdge d3Edges |
69 | 75 | a._drawNodes = a.drawing.DrawNodes |
| 76 | +
|
| 77 | + a._drawEdges.createEdge d3Edges |
70 | 78 | a._drawNodes.createNode d3Nodes |
71 | 79 |
|
72 | | - initialComputationDone = true |
73 | | - console.log Date() + ' completed initial computation' |
| 80 | + a.index() |
74 | 81 |
|
75 | | - nodes = a.vis.selectAll 'g.node' |
76 | | - .attr 'transform', (id, i) -> "translate(#{id.x}, #{id.y})" |
| 82 | + a.elements.nodes.svg |
| 83 | + .attr "transform", (id,i)-> "translate(#{id.x}, #{id.y})" |
77 | 84 |
|
78 | | - # configuration for forceLocked |
| 85 | + console.log Date() + ' completed initial computation' |
| 86 | + |
79 | 87 | if !conf.forceLocked |
80 | | - a.force |
81 | | - .on "tick", a.layout.tick |
| 88 | + a.force.on "tick", a.layout.tick |
82 | 89 | .start() |
83 | 90 |
|
84 | 91 | # call user-specified functions after load function if specified |
|
89 | 96 | else if typeof conf.afterLoad is 'string' |
90 | 97 | a[conf.afterLoad] = true |
91 | 98 |
|
92 | | - if conf.cluster or conf.directedEdges |
| 99 | + if conf.cluster |
93 | 100 | defs = d3.select("#{a.conf.divSelector} svg").append "svg:defs" |
94 | 101 |
|
95 | | - if conf.directedEdges |
96 | | - arrowSize = conf.edgeArrowSize + (conf.edgeWidth() * 2) |
97 | | - marker = defs.append "svg:marker" |
98 | | - .attr "id", "arrow" |
99 | | - .attr "viewBox", "0 -#{arrowSize * 0.4} #{arrowSize} #{arrowSize}" |
100 | | - .attr 'markerUnits', 'userSpaceOnUse' |
101 | | - .attr "markerWidth", arrowSize |
102 | | - .attr "markerHeight", arrowSize |
103 | | - .attr "orient", "auto" |
104 | | - marker.append "svg:path" |
105 | | - .attr "d", "M #{arrowSize},0 L 0,#{arrowSize * 0.4} L 0,-#{arrowSize * 0.4}" |
106 | | - if conf.curvedEdges |
107 | | - marker.attr "refX", arrowSize + 1 |
108 | | - else |
109 | | - marker.attr 'refX', 1 |
110 | | -
|
111 | 102 | if conf.nodeStats |
112 | 103 | a.stats.nodeStats() |
113 | 104 |
|
|
0 commit comments