Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
Run digest cycle on graph's zoom and pan events
Browse files Browse the repository at this point in the history
Rationale: we want to add "fit" and "zoom to central object" buttons
that should be visible when graph is not fitted or is not zoomed to
the center respectively. It's simple to write such conditions for
buttons but they need to be recalculated as the graph is zoomed or
panned.
  • Loading branch information
fracz committed Apr 27, 2016
1 parent a46a157 commit 66ebd83
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
13 changes: 10 additions & 3 deletions dist/cytoscape-actionbar.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
angular.module('cytoscape.actionbar', []).directive('cytoscapeActionbar', function() {
angular.module('cytoscape.actionbar', []).directive('cytoscapeActionbar', ["$rootScope", function($rootScope) {
return {
template: "<div ng-class='options.actionbarClass' style=\"position: absolute; z-index: 1000\">\n <span ng-repeat=\"item in options.items\" ng-click='item.action(cy, item)' ng-if='item.condition()'\n ng-class='[options.actionItemClass, icon, item.icon]' data-container='body' bs-tooltip='item.tooltip'></span>\n</div>",
link: function(scope) {
return cytoscape('core', 'actionbar', function(options) {
var defaults;
var defaults, digestEvent, i, len, ref;
defaults = {
items: [],
actionbarClass: 'ui-cytoscape-actionbar',
Expand All @@ -17,8 +17,15 @@ angular.module('cytoscape.actionbar', []).directive('cytoscapeActionbar', functi
};
}
});
ref = ['zoom', 'pan'];
for (i = 0, len = ref.length; i < len; i++) {
digestEvent = ref[i];
this.on(digestEvent, function() {
return $rootScope.$apply();
});
}
return scope.options = options;
});
}
};
});
}]);
2 changes: 1 addition & 1 deletion dist/cytoscape-actionbar.min.js

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

8 changes: 5 additions & 3 deletions src/CytoscapeActionbar.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('cytoscape.actionbar', []).directive 'cytoscapeActionbar', ->
angular.module('cytoscape.actionbar', []).directive 'cytoscapeActionbar', ($rootScope) ->
template: """
<div ng-class='options.actionbarClass' style="position: absolute; z-index: 1000">
<span ng-repeat="item in options.items" ng-click='item.action(cy, item)' ng-if='item.condition()'
Expand All @@ -12,10 +12,12 @@ angular.module('cytoscape.actionbar', []).directive 'cytoscapeActionbar', ->
(options) ->
defaults =
items: []
actionbarClass: 'ui-cytoscape-actionbar' # set a class name for the toolbar to help with styling
actionItemClass: 'action-item' # set a class name for a toolbar item to help with styling
actionbarClass: 'ui-cytoscape-actionbar' # set a class name for the toolbar to help with styling
actionItemClass: 'action-item' # set a class name for a toolbar item to help with styling
angular.extend(defaults, options)
angular.forEach(options.items, (item) ->
if not item.condition then item.condition = -> true)
# run digest cycle on graph's zoom and pan events
@on(digestEvent, -> $rootScope.$apply()) for digestEvent in ['zoom', 'pan']
scope.options = options
)

0 comments on commit 66ebd83

Please sign in to comment.