-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-viz.coffee
More file actions
83 lines (58 loc) · 1.5 KB
/
angular-viz.coffee
File metadata and controls
83 lines (58 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require?("angular")
require?("viz")
angular = global?.angular or window?.angular
Viz = global?.Viz or window?.Viz
module = angular.module "atVizJs", []
baseoption =
format: "svg"
engine: "dot"
render = (source_code, option = {})->
option = angular.extend {}, baseoption, option
arg = {}
for k in ["format", "engine"]
arg[k] = option[k]
delete option[k]
Viz source_code, arg.format, arg.engine, option
draw = (source_code, output_element, option = {})->
$elm = angular.element output_element
dot = render source_code, option
$elm.html dot
return
directive_link = (scope, element, attrs)->
draw attrs.dot or element.text(), element, attrs
language_directive_link = -> return
module.provider "vizJs", ()->
@option = (opt)->
baseoption = angular.extend baseoption, opt
@
@enableLanguageDirective = ->
language_directive_link = directive_link
@
@$get = ()->
"render": render
"draw": draw
return
module.directive "dot", ->
{
restrict: "E"
scope: true
transclude: true
replace: true
template: "<div ng-bind-html=\"diagram\" class=\"at-viz-js\"></div>"
controller: ["$scope", "$element", "$attrs", "$transclude", "$sce", ($scope, $element, $attrs, $transclude, $sce)->
diagram = render $attrs.dot or $transclude().text(), $attrs
$scope.diagram = $sce.trustAsHtml diagram
]
}
module.directive "dot", ->
{
restrict: "A"
template: ""
link: directive_link
}
module.directive "languageDot", ->
{
restrict: "C"
template: ""
link: language_directive_link
}