forked from intersystems-community/DeepSeeWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customWidget.js
80 lines (66 loc) · 2.83 KB
/
customWidget.js
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
(function() {
'use strict';
/**
* Register custom directive for widget
* Name of this directive is used in "directive" property of widget definition object
* Note that angular directives was written in "camelCase",
* whilst actual directive name is "camel-case"
*/
angular.module('app')
// You can inject other DSW services here if needed. Look at /src/services
.directive('customDirective', ['$parse', '$compile', 'Lang', 'Connector', function($parse, $compile, Lang, Connector) {
return {
link: function(scope, element, attrs) {
// Remove attr to avoid infinite creation loop
element.removeAttr('custom-directive');
// Create html5 canvas element
element[0].innerHTML = "<canvas></canvas>";
$compile(element)(scope);
// Get created canvas element
var canvas = element[0].children[0];
// Define render function
scope.drawWidget = function() {
var ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(0, 0, 255, 0.5)";
ctx.arc(canvas.width/2, canvas.height/2, canvas.height/2 - 20, 0, Math.PI*2);
ctx.fill();
};
// Define resize function
scope.resizeWidget = function() {
canvas.style.width = element[0].offsetWidth + 'px';
canvas.style.height = element[0].offsetHeight + 'px';
canvas.width = canvas.offsetWidth;
canvas.height = canvas.offsetHeight;
scope.drawWidget();
};
}
};
}]);
/**
* Factory for custom widget
* @param {objcet} Utils Class with DSW utilities
* @returns {CustomWidget}
* @constructor
*/
function CustomWidgetFact(Utils) {
function CustomWidget($scope) {
var _this = this;
// After data was retrieved - redraw widget
this._retrieveData = function(data) {
console.log('data received');
$scope.drawWidget();
};
// Resize canvas after widget was resized
this.onResize = function() {
$scope.resizeWidget();
};
// Request widget data (execute MDX)
this.requestData();
}
return CustomWidget;
}
// Register angular widget. This name is used in widget definition object as "class" property
angular.module('widgets')
.factory('CustomWidget', ['Utils', CustomWidgetFact]);
})();