Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin prep #519

Merged
3 commits merged into from
Nov 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@

<script src="scripts/alchemy.js"></script>
<script type="text/javascript">
Alchemy.prototype.plugins.trees = function() {
console.log("the trees plugin has been initialized");
};
Alchemy.prototype.plugins.airplanes = function() {
console.log("the airplanes plugin has been initialized");
};
var config = {
dataSource: "sample_data/contrib.json",
plugins: ["trees", "airplanes", "foobar"]
// curvedEdges: true
}

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/alchemy/API/get.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# make js array method called ._state
# @a.set. nest set inside of get

Alchemy::get = (instance)->
Alchemy::get = (instance) ->
a: instance
_el: []
_elType: null
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/alchemy/API/remove.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

class Alchemy::remove
constructor: (instance)->
constructor: (instance) ->
@a = instance

nodes: (nodeMap) ->
Expand Down
13 changes: 7 additions & 6 deletions app/scripts/alchemy/Alchemy.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ title: Anotated Source
@a = @

@version = "#VERSION#"
# give access to default conf
@get = new @get @
@remove = new @remove @
@create = new @create @
Expand Down Expand Up @@ -79,7 +80,7 @@ title: Anotated Source
# The value is an array of edge 'packets', where the length of the array
# is typically 1.
@_edges = {}

# Bind legacy API methods to earlier location
# These will be deprecated on release-1.0
@getNodes = @get.getNodes
Expand All @@ -91,7 +92,8 @@ title: Anotated Source

begin: (userConf) ->
# overide configuration with user inputs
@setConf userConf
conf = @setConf userConf
@plugins.init conf, @a
switch typeof @conf.dataSource
when 'string' then d3.json @a.conf.dataSource, @a.startGraph
when 'object' then @a.startGraph @a.conf.dataSource
Expand All @@ -103,20 +105,20 @@ title: Anotated Source
setConf: (userConf) ->
# apply base themes
if userConf.theme?
userConf = _.merge _.cloneDeep(defaults), @a.themes["#{userConf.theme}"]
userConf = _.merge _.cloneDeep(@defaults), @a.themes["#{userConf.theme}"]

for key, val of userConf
switch key
when "clusterColors" then userConf["clusterColours"] = val
when "backgroundColor" then userConf["backgroundColour"] = val
when "nodeColor" then userConf[nodeColour] = val

@a.conf = _.merge _.cloneDeep(defaults), userConf
@a.conf = _.merge _.cloneDeep(@defaults), userConf

# All alchemy instances in order of creation.
instances: []

getInst: (element)->
getInst: (element) ->
#Edge or Node
if element.a?
element.a
Expand All @@ -129,7 +131,6 @@ title: Anotated Source
else
Alchemy::instances[d3.select(element).attr("alchInst")]


root = exports ? this
root.Alchemy = Alchemy

Expand Down
21 changes: 11 additions & 10 deletions app/scripts/alchemy/core/interactions.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
return "active" if node._state is "selected"
"selected"
node.setStyles()

if typeof a.conf.nodeClick is 'function'
a.conf.nodeClick(n)

Expand Down Expand Up @@ -113,16 +114,16 @@
@._zoomBehavior.scale(scale)
.translate([x,y])

toggleControlDash: () ->
#toggle off-canvas class on click
offCanvas = a.dash.classed("off-canvas") or
a.dash.classed("initial")
a.dash
.classed {
"off-canvas": !offCanvas,
"initial" : false,
"on-canvas" : offCanvas
}
# toggleControlDash: () ->
# #toggle off-canvas class on click
# offCanvas = a.dash.classed("off-canvas") or
# a.dash.classed("initial")
# a.dash
# .classed {
# "off-canvas": !offCanvas,
# "initial" : false,
# "on-canvas" : offCanvas
# }

nodeDragStarted: (d, i) ->
d3.event.preventDefault
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/alchemy/defaultConf.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

defaults =
Alchemy::defaults =

plugins: null
# Renderer
renderer: "svg"

Expand Down
14 changes: 14 additions & 0 deletions app/scripts/alchemy/plugins/plugins.coffee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Initiates all plugins
When an a new instance of Alchemy is invoked, the conf is checked for plugins
and any defined plugins are initialized. For example: `foo = new Alchemy({plugins:
['barPlugin', 'searchPlugin']})` will expect `Alchemy.plugins.barPlugin
()` and `Alchemy.plugins.searchPlugin()` to initialize the respective plugins.

Alchemy::plugins =
init: (conf, instance) ->
if conf.plugins
for p in conf.plugins
if not instance.plugins[p]
console.warn("It looks like the plugin, #{p} you are trying to load, has not been included.")
else
instance.plugins[p](instance)
10 changes: 5 additions & 5 deletions dist/alchemy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/alchemy.min.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/scripts/vendor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/karma.conf.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = (config) ->
"test/spec/models/edge.coffee"
"test/spec/api/get.coffee"
"test/spec/api/remove.coffee"
"test/spec/plugins/plugins.coffee"
"app/sample_data/contrib.json"
]

Expand Down
8 changes: 4 additions & 4 deletions test/spec/configurationTests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ do ->
d3.select('body').append('div').attr('id', 'alchemy')

alchemy = new Alchemy
dataSource : contrib_json,
graphWidth : () -> 200,
graphHeight: () -> 200,
alpha : 0.23,
dataSource : contrib_json
graphWidth : () -> 200
graphHeight: () -> 200
alpha : 0.23
nodeTypes : {"role": ["maintainer", "project"]}

setTimeout done, 1000
Expand Down
23 changes: 23 additions & 0 deletions test/spec/plugins/plugins.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
do ->
describe "alchemy.conf.plugins", ->
before (done) ->
# extend Alchemy with fake plugin callables
Alchemy::plugins.foobar = ->
window.pluginFoobarHasBeenCalled = true
Alchemy::plugins.testplugin = ->
window.pluginTestpluginHasBeenCalled = true
debugger
window.pluginInstance = new Alchemy
dataSource : contrib_json
plugins: ["foobar", "testplugin"]

setTimeout done, 1000

it "should have plugin 'foobar' and 'testplugin' defined for testing", () ->
expect(pluginInstance.conf.plugins).to.include("foobar", "testplugin")

it "should initialize defined plugins automatically", () ->
expect(pluginFoobarHasBeenCalled).to.be.true
expect(pluginTestpluginHasBeenCalled).to.be.true

return