Skip to content
Open
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
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-plotly",
"version": "0.1.3",
"version": "0.1.4",
"description": "An AngularJS directive for plotly.js",
"main": [
"src/angular-plotly.js"
Expand All @@ -22,7 +22,7 @@
},
"dependencies": {
"angular": "^1.x",
"plotly.js":"^1.10.2"
"plotly.js": "^1.40.1"
},
"ignore": [
"**/.*",
Expand Down
27 changes: 13 additions & 14 deletions src/angular-plotly.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(function() {
(function () {
'use strict';
angular.module('plotly', []).directive('plotly', [
'$window',
function($window) {
function ($window) {
return {
restrict: 'E',
template: '<div></div>',
Expand All @@ -13,12 +13,12 @@
plotlyEvents: '=',
plotlyManualDataUpdate: '='
},
link: function(scope, element) {
link: function (scope, element) {
var graph = element[0].children[0];
var initialized = false;

function subscribeToEvents(graph) {
scope.plotlyEvents(graph);
scope.plotlyEvents(graph);
}

function onUpdate() {
Expand All @@ -34,14 +34,13 @@
if (!initialized) {
initialized = true;
Plotly.newPlot(graph, scope.plotlyData, scope.plotlyLayout, scope.plotlyOptions);
if (scope.plotlyEvents){
subscribeToEvents(graph);
if (scope.plotlyEvents) {
subscribeToEvents(graph);
}
}
graph.layout = scope.plotlyLayout;
graph.data = scope.plotlyData;
Plotly.redraw(graph);
Plotly.Plots.resize(graph);
Plotly.update(graph);
}

function onResize() {
Expand All @@ -50,20 +49,20 @@
}

scope.$watch(
function(scope) {
function (scope) {
return scope.plotlyLayout;
},
function(newValue, oldValue) {
function (newValue, oldValue) {
if (angular.equals(newValue, oldValue) && initialized) return;
onUpdate();
}, true);

if (!scope.plotlyManualDataUpdate) {
scope.$watch(
function(scope) {
function (scope) {
return scope.plotlyData;
},
function(newValue, oldValue) {
function (newValue, oldValue) {
if (angular.equals(newValue, oldValue) && initialized) return;
onUpdate();
}, true);
Expand All @@ -76,12 +75,12 @@
onUpdate();
});

scope.$watch(function() {
scope.$watch(function () {
return {
'h': element[0].offsetHeight,
'w': element[0].offsetWidth
};
}, function(newValue, oldValue) {
}, function (newValue, oldValue) {
if (angular.equals(newValue, oldValue)) return;
onResize();
}, true);
Expand Down