http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/app/scripts/controllers/twitter.js ---------------------------------------------------------------------- diff --git a/web/demos/app/scripts/controllers/twitter.js b/web/demos/app/scripts/controllers/twitter.js deleted file mode 100644 index f9e8ffd..0000000 --- a/web/demos/app/scripts/controllers/twitter.js +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/*global settings, angular, jQuery, _*/ -(function () { -'use strict'; - -angular.module('twitter') - .controller('TwitterUrlsController', ['$scope', 'rest', function ($scope, rest) { - rest.getApp(settings.twitterUrls.appName).then(function (app) { - $scope.app = app; - $scope.appURL = settings.appsURL + app.id; - }); - - $scope.topic = settings.twitterUrls.topic; - $scope.pageTitle = 'Twitter Top URLs'; - $scope.entity = 'URLs'; - $scope.gridTitle = 'Twitter Top URLs'; - $scope.chartTitle = 'Top 10 URLs Chart'; - $scope.colName = 'URL'; - $scope.formatter = function(url) { - return '<a class="svg-link" xlink:href="' + url + '">' + url + '</a>'; - }; - }]) - .controller('TwitterHashtagsController', ['$scope', 'rest', function ($scope, rest) { - rest.getApp(settings.twitterHashtags.appName).then(function (app) { - $scope.app = app; - $scope.appURL = settings.appsURL + app.id; - }); - - $scope.topic = settings.twitterHashtags.topic; - $scope.pageTitle = 'Twitter Top Hashtags'; - $scope.entity = 'hashtags'; - $scope.gridTitle = 'Twitter Top Hashtags'; - $scope.chartTitle = 'Top 10 Hashtags Chart'; - $scope.colName = 'Hashtag'; - $scope.formatter = function(Hashtag) { - return '<a class="svg-link" xlink:href="https://twitter.com/search?q=%23' + encodeURIComponent(Hashtag) + '">' + Hashtag + '</a>'; - }; - }]) - .controller('TwitterGridControlller', ['$scope', 'socket', function ($scope, socket) { - socket.subscribe($scope.topic, function(data) { - var list = []; - jQuery.each(data.data, function(key, value) { - list.push( { name: key, value: parseInt(value, 10) } ); - }); - list = _.sortBy(list, function(item) { - return -item.value; - }); - $scope.topTen = list; - $scope.$apply(); - }, $scope); - - $scope.gridOptions = { - data: 'topTen', - enableColumnResize: true, - columnDefs: [ - { field: "name", displayName: $scope.colName, width: '75%', sortable: false }, - { field: "value", displayName: 'Count', width: '25%', sortable: false } - ] - }; - }]) - .controller('TwitterBarChartController', ['$scope', 'socket', function($scope, socket) { - socket.subscribe($scope.topic, function(data) { - var list = []; - jQuery.each(data.data, function(key, value) { - list.push( { name: key, value: parseInt(value, 10) } ); - }); - list = _.sortBy(list, function(item) { - return -item.value; - }); - //var max = _.max(list, function(item) {item.value}); - var max = list[0].value; - _.each(list, function(item) { - if ($scope.formatter) { - item.name = $scope.formatter(item.name); - } - item.name += ' - ' + item.value; - item.score = item.value / max * 100; - }); - - $scope.twitterBarChartData = list; - $scope.$apply(); - }, $scope); - $scope.twitterBarChartData = []; - }]); - -})();
http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/app/scripts/directives/barChart.js ---------------------------------------------------------------------- diff --git a/web/demos/app/scripts/directives/barChart.js b/web/demos/app/scripts/directives/barChart.js deleted file mode 100644 index dad2b4c..0000000 --- a/web/demos/app/scripts/directives/barChart.js +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/*global angular, d3*/ -(function () { -'use strict'; - -angular.module('widgets') - .directive('widgetsBarChart', function () { - return { - restrict: 'A', - scope: { - data: "=", - label: "@", - onClick: "&" - }, - link: function(scope, iElement, iAttrs) { - var svg = d3.select(iElement[0]) - .append("svg") - .attr("width", "100%"); - - // on window resize, re-render d3 canvas - window.onresize = function() { - return scope.$apply(); - }; - scope.$watch(function(){ - return angular.element(window)[0].innerWidth; - }, function(){ - return scope.render(scope.data); - } - ); - - // watch for data changes and re-render - scope.$watch('data', function(newVals, oldVals) { - return scope.render(newVals); - }, true); - - // define render function - scope.render = function(data){ - // remove all previous items before render - svg.selectAll("*").remove(); - - // setup variables - var width, height, max; - width = d3.select(iElement[0])[0][0].offsetWidth - 20; - // 20 is for margins and can be changed - height = scope.data.length * 35; - // 35 = 30(bar height) + 5(margin between bars) - max = 98; - // this can also be found dynamically when the data is not static - // max = Math.max.apply(Math, _.map(data, ((val)-> val.count))) - - // set the height based on the calculations above - svg.attr('height', height); - - //create the rectangles for the bar chart - svg.selectAll("rect") - .data(data) - .enter() - .append("rect") - .on("click", function(d, i){return scope.onClick({item: d});}) - .attr("height", 30) // height of each bar - .attr("width", 0) // initial width of 0 for transition - .attr("x", 10) // half of the 20 side margin specified above - .attr("y", function(d, i){ - return i * 35; - }) // height + margin between bars - //.transition() - //.duration(1000) - .attr("width", function(d){ - var w = d.score/(max/width); // width based on scale - return w > 10 ? w : 10; - }); - - svg.selectAll("text") - .data(data) - .enter() - .append("text") - .attr("fill", "#fff") - .attr("y", function(d, i){return i * 35 + 22;}) - .attr("x", 15) - .html(function(d){return d[scope.label];}); - - }; - } - }; - }); - -})(); http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/app/scripts/directives/gauge.js ---------------------------------------------------------------------- diff --git a/web/demos/app/scripts/directives/gauge.js b/web/demos/app/scripts/directives/gauge.js deleted file mode 100644 index f3bc06f..0000000 --- a/web/demos/app/scripts/directives/gauge.js +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * Modified copy of https://github.com/lithiumtech/angular_and_d3/blob/master/step5/custom/gauges.js - */ - -/*global Gauge, angular, d3*/ -(function () { -'use strict'; - - angular.module('widgets').directive( 'gauge', function () { - return { - restrict: 'A', - replace: true, - scope: { - label: "@", - min: "=", - max: "=", - value: "=" - }, - link: function (scope, element, attrs) { - var config = { - size: 280, - label: attrs.label, - min: undefined !== scope.min ? scope.min : 0, - max: undefined !== scope.max ? scope.max : 100, - minorTicks: 5 - }; - - var range = config.max - config.min; - config.yellowZones = [ { from: config.min + range*0.75, to: config.min + range*0.9 } ]; - config.redZones = [ { from: config.min + range*0.9, to: config.max } ]; - - scope.gauge = new Gauge( element[0], config ); - scope.gauge.render(); - scope.gauge.redraw( scope.value ); - - scope.$watch('value', function() { - if (scope.gauge) { - scope.gauge.redraw( scope.value ); - } - }); - } - }; - }); - -})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/app/scripts/directives/lineChart.js ---------------------------------------------------------------------- diff --git a/web/demos/app/scripts/directives/lineChart.js b/web/demos/app/scripts/directives/lineChart.js deleted file mode 100644 index 5ff3310..0000000 --- a/web/demos/app/scripts/directives/lineChart.js +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/*global angular, google*/ -(function () { -'use strict'; - -angular.module('widgets') - .directive('lineChart', function () { - return { - template: '<div></div>', - scope: { - chart: '=' - }, - restrict: 'E', - replace: true, - link: function postLink(scope, element, attrs) { - var lineChart = new google.visualization.LineChart(element[0]); - - function draw(chart) { - var data = chart.data; - - if (!data) { - data = []; - } - - var table = new google.visualization.DataTable(); - table.addColumn('datetime'); - table.addColumn('number'); - table.addRows(data.length); - - var view = new google.visualization.DataView(table); - - for (var i = 0; i < data.length; i++) { - var item = data[i]; - table.setCell(i, 0, new Date(item.timestamp)); - var value = parseFloat(item.value); - table.setCell(i, 1, value); - } - - var options; - if (data.length === 0 && chart.emptyChartOptions) { - options = chart.emptyChartOptions(); - } else { - options = chart.options; - } - - lineChart.draw(view, options); - } - - scope.$watch('chart', function (chart) { - if (chart) { - draw(chart); - } - }); - } - }; - }); - -})(); http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/app/scripts/directives/stat.js ---------------------------------------------------------------------- diff --git a/web/demos/app/scripts/directives/stat.js b/web/demos/app/scripts/directives/stat.js deleted file mode 100644 index c0b6dc4..0000000 --- a/web/demos/app/scripts/directives/stat.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/*global BigInteger, angular, _*/ -(function () { -'use strict'; - -angular.module('widgets') - .directive('widgetsStat', ['$timeout', 'socket', function ($timeout, socket) { - return { - restrict: 'A', - templateUrl: 'views/stat.html', - scope: { - app: "=", - label: "@", - onClick: "&" - }, - link: function($scope, iElement, iAttrs) { - $scope.totalEmitted = 0; - $scope.totalProcessed = 0; - $scope.elapsed = 0; - - var initialElapsedTime; - var startTime; - - function updatedElapsedTime() { - $scope.elapsed = initialElapsedTime + (Date.now() - startTime); - $timeout(updatedElapsedTime, 1000); - } - - $scope.$watch('app', function (app) { - if (app) { - initialElapsedTime = parseInt(app.elapsedTime); - startTime = Date.now(); - updatedElapsedTime(); - - var topic = 'applications.' + app.id; - - socket.subscribe(topic, function (message) { - var appData = message.data; - $scope.totalEmitted = appData.tuplesEmittedPSMA; - $scope.totalProcessed = appData.totalTuplesProcessed; - $scope.$apply(); - }, $scope); - } - }); - } - }; - }]); - -})(); http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/app/scripts/filters/elapsed.js ---------------------------------------------------------------------- diff --git a/web/demos/app/scripts/filters/elapsed.js b/web/demos/app/scripts/filters/elapsed.js deleted file mode 100644 index f52c97e..0000000 --- a/web/demos/app/scripts/filters/elapsed.js +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/*global angular, _*/ -(function () { -'use strict'; - -angular.module('widgets').filter('elapsed', function() { - return function(timeStamp) { - var options = { timeChunk: timeStamp * 1, unixUptime: true }; - - _.defaults(options, { - compareDate: +new Date(), - timeChunk: undefined, - maxUnit: "year", - unixUptime: false, - max_levels: 3, - timeStamp: timeStamp || 0 - }); - var remaining = (options.timeChunk !== undefined) ? options.timeChunk : options.compareDate - options.timeStamp; - var string = ""; - var separator = ", "; - var level = 0; - var max_levels = options.max_levels; - var milli_per_second = 1000; - var milli_per_minute = milli_per_second * 60; - var milli_per_hour = milli_per_minute * 60; - var milli_per_day = milli_per_hour * 24; - var milli_per_week = milli_per_day * 7; - var milli_per_month = milli_per_week * 4; - var milli_per_year = milli_per_day * 365; - - if (options.unixUptime) { - var days = Math.floor(remaining / milli_per_day); - remaining -= days*milli_per_day; - var hours = Math.floor(remaining / milli_per_hour); - remaining -= hours*milli_per_hour; - var minutes = Math.round(remaining / milli_per_minute); - - if (days === 0) { - minutes = Math.floor(remaining / milli_per_minute); - remaining -= minutes*milli_per_minute; - var seconds = Math.round(remaining / 1000); - string = (hours < 10 ? "0" : "")+hours+':'+(minutes < 10 ? "0" : "")+minutes+':'+(seconds < 10 ? "0" : "")+seconds; - } - else { - string = days + " days, " + hours.toString() + ":" + (minutes < 10 ? "0" : "") + minutes.toString(); - } - - } else { - var levels = [ - { plural: "years", singular: "year", ms: milli_per_year }, - { plural: "months", singular: "month", ms: milli_per_month }, - { plural: "weeks", singular: "week", ms: milli_per_week }, - { plural: "days", singular: "day", ms: milli_per_day }, - { plural: "hours", singular: "hour", ms: milli_per_hour }, - { plural: "minutes", singular: "minute", ms: milli_per_minute }, - { plural: "seconds", singular: "second", ms: milli_per_second } - ]; - - var crossedThreshold = false; - for (var i=0; i < levels.length; i++) { - if ( options.maxUnit === levels[i].singular ) { - crossedThreshold = true; - } - if ( remaining < levels[i].ms || !crossedThreshold ) { - continue; - } - level++; - var num = Math.floor( remaining / levels[i].ms ); - var label = num === 1 ? levels[i].singular : levels[i].plural ; - string += num + " " + label + separator; - remaining %= levels[i].ms; - if ( level >= max_levels ) { - break; - } - } - string = string.substring(0, string.length - separator.length); - } - - - return string; - }; -}); - -})(); - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/app/scripts/services/rest.js ---------------------------------------------------------------------- diff --git a/web/demos/app/scripts/services/rest.js b/web/demos/app/scripts/services/rest.js deleted file mode 100644 index 7e1ef01..0000000 --- a/web/demos/app/scripts/services/rest.js +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/*global angular, jQuery, _*/ -(function () { -'use strict'; - -angular.module('rest', ['ng', 'restangular']) - .factory('rest', ['$q', 'Restangular', function($q, Restangular) { - return { - getApp: function (appName) { - var deferred = $q.defer(); - Restangular.oneUrl('applications', 'ws/v2/applications').get().then(function (response) { - var errorMessage = null; - if (response && response.apps && response.apps.length > 0) { - var apps = _.where(response.apps, { name: appName, state: 'RUNNING' }); - if (apps.length > 0) { - apps = _.sortBy(apps, function (app) { return parseInt(app.elapsedTime, 10); }); - var app = apps[0]; - deferred.resolve(app); - } else { - errorMessage = appName + ' is not found. Please make sure application is running.'; - } - } else { - errorMessage = 'No applications available.'; - } - - if (errorMessage) { - deferred.reject(errorMessage); - jQuery.pnotify({ - title: 'Error', - text: errorMessage, - type: 'error', - icon: false, - hide: false - }); - } - }); - - return deferred.promise; - }, - - getMachineData: function (query) { - var promise = Restangular.one('machine').get(query); - - promise.then(null, function (response) { - jQuery.pnotify({ - title: 'Error', - text: 'Error getting data from server. Status Code: ' + response.status, - type: 'error', - icon: false, - hide: false - }); - }); - - return promise; - }, - - getDimensionsData: function (query) { - var promise = Restangular.one('dimensions').get(query); - - promise.then(null, function (response) { - jQuery.pnotify({ - title: 'Error', - text: 'Error getting data from server. Status Code: ' + response.status, - type: 'error', - icon: false, - hide: false - }); - }); - - return promise; - } - }; - }]) - .run(function(Restangular) { - //Restangular.setBaseUrl('/ws/v1'); - //Restangular.setBaseUrl('/stram/v1'); - }); -})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/app/scripts/services/socket.js ---------------------------------------------------------------------- diff --git a/web/demos/app/scripts/services/socket.js b/web/demos/app/scripts/services/socket.js deleted file mode 100644 index 1dc16a0..0000000 --- a/web/demos/app/scripts/services/socket.js +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/*global settings, console, angular, jQuery, _*/ -(function () { - 'use strict'; - - angular.module('socket', []) - .factory('visibly', function ($window) { - return $window.visibly; - }) - .provider('socket', function () { - - var webSocketURL; - var webSocketObject; // for testing only - - return { - $get: function ($q, $rootScope, $timeout, visibly) { - if (!webSocketURL && !webSocketObject) { - throw 'WebSocket URL is not defined'; - } - - var socket = !webSocketObject ? new WebSocket(webSocketURL) : webSocketObject; - - var deferred = $q.defer(); - - socket.onopen = function () { - deferred.resolve(); - $rootScope.$apply(); - - jQuery.pnotify({ - title: 'WebSocket', - text: 'WebSocket connection established.', - type: 'success', - delay: 2000, - icon: false, - history: false - }); - }; - - var webSocketError = false; - - socket.onclose = function () { - if (!webSocketError) { - jQuery.pnotify({ - title: 'WebSocket Closed', - text: 'WebSocket connection has been closed. Try refreshing the page.', - type: 'error', - icon: false, - hide: false, - history: false - }); - } - }; - - //TODO - socket.onerror = function () { - webSocketError = true; - jQuery.pnotify({ - title: 'WebSocket Error', - text: 'WebSocket error. Try refreshing the page.', - type: 'error', - icon: false, - hide: false, - history: false - }); - }; - - var topicMap = {}; // topic -> [callbacks] mapping - - var stopUpdates = false; - - socket.onmessage = function (event) { - if (stopUpdates) { // stop updates if page is inactive - return; - } - - var message = JSON.parse(event.data); - - var topic = message.topic; - - if (topicMap.hasOwnProperty(topic)) { - topicMap[topic].fire(message); - } - }; - - var timeoutPromise; - - visibly.onHidden(function () { - timeoutPromise = $timeout(function () { - stopUpdates = true; - timeoutPromise = null; - }, 60000); - }); - - visibly.onVisible(function () { - /* - if (stopUpdates && !webSocketError) { - jQuery.pnotify({ - title: 'Warning', - text: 'Page has not been visible for more than 60 seconds. WebSocket real-time updates have been suspended to conserve system resources. ' + - 'Refreshing the page is recommended.', - type: 'warning', - icon: false, - hide: false, - history: false - }); - } - */ - - stopUpdates = false; - - if (timeoutPromise) { - $timeout.cancel(timeoutPromise); - } - }); - - return { - send: function (message) { - var msg = JSON.stringify(message); - - deferred.promise.then(function () { - console.log('send ' + msg); - socket.send(msg); - }); - }, - - publish: function(topic, data) { - var message = { "type": "publish", "topic": topic, "data": data }; - this.send(message); - }, - - subscribe: function (topic, callback, $scope) { - var callbacks = topicMap[topic]; - - if (!callbacks) { - var message = { type: 'subscribe', topic: topic }; // subscribe message - this.send(message); - - callbacks = jQuery.Callbacks(); - topicMap[topic] = callbacks; - } - - callbacks.add(callback); - - if ($scope) { - $scope.$on('$destroy', function () { - this.unsubscribe(topic, callback); - }.bind(this)); - } - }, - - unsubscribe: function (topic, callback) { - if (topicMap.hasOwnProperty(topic)) { - var callbacks = topicMap[topic]; - callbacks.remove(callback); //TODO remove topic from topicMap if callbacks is empty - } - } - }; - }, - - setWebSocketURL: function (wsURL) { - webSocketURL = wsURL; - }, - - setWebSocketObject: function (wsObject) { - webSocketObject = wsObject; - } - }; - }); - -})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/app/scripts/vendor/angular-google-maps.js ---------------------------------------------------------------------- diff --git a/web/demos/app/scripts/vendor/angular-google-maps.js b/web/demos/app/scripts/vendor/angular-google-maps.js deleted file mode 100644 index e74ba38..0000000 --- a/web/demos/app/scripts/vendor/angular-google-maps.js +++ /dev/null @@ -1,584 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * Modified copy (using MarkerWithLabel instead of google.maps.Marker). - */ - -/**! - * The MIT License - * - * Copyright (c) 2010-2012 Google, Inc. http://angularjs.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * angular-google-maps - * https://github.com/nlaplante/angular-google-maps - * - * @author Nicolas Laplante https://plus.google.com/108189012221374960701 - */ - -(function () { - - "use strict"; - - /* - * Utility functions - */ - - /** - * Check if 2 floating point numbers are equal - * - * @see http://stackoverflow.com/a/588014 - */ - function floatEqual (f1, f2) { - return (Math.abs(f1 - f2) < 0.000001); - } - - /* - * Create the model in a self-contained class where map-specific logic is - * done. This model will be used in the directive. - */ - - var MapModel = (function () { - - var _defaults = { - zoom: 8, - draggable: false, - container: null - }; - - /** - * - */ - function PrivateMapModel(opts) { - - var _instance = null, - _markers = [], // caches the instances of google.maps.Marker - _handlers = [], // event handlers - _windows = [], // InfoWindow objects - o = angular.extend({}, _defaults, opts), - that = this, - currentInfoWindow = null; - - this.center = opts.center; - this.zoom = o.zoom; - this.draggable = o.draggable; - this.dragging = false; - this.selector = o.container; - this.markers = []; - this.options = o.options; - - this.draw = function () { - - if (that.center == null) { - // TODO log error - return; - } - - if (_instance == null) { - - // Create a new map instance - - _instance = new google.maps.Map(that.selector, angular.extend(that.options, { - center: that.center, - zoom: that.zoom, - draggable: that.draggable, - mapTypeId : google.maps.MapTypeId.ROADMAP - })); - - google.maps.event.addListener(_instance, "dragstart", - - function () { - that.dragging = true; - } - ); - - google.maps.event.addListener(_instance, "idle", - - function () { - that.dragging = false; - } - ); - - google.maps.event.addListener(_instance, "drag", - - function () { - that.dragging = true; - } - ); - - google.maps.event.addListener(_instance, "zoom_changed", - - function () { - that.zoom = _instance.getZoom(); - that.center = _instance.getCenter(); - } - ); - - google.maps.event.addListener(_instance, "center_changed", - - function () { - that.center = _instance.getCenter(); - } - ); - - // Attach additional event listeners if needed - if (_handlers.length) { - - angular.forEach(_handlers, function (h, i) { - - google.maps.event.addListener(_instance, - h.on, h.handler); - }); - } - } - else { - - // Refresh the existing instance - google.maps.event.trigger(_instance, "resize"); - - var instanceCenter = _instance.getCenter(); - - if (!floatEqual(instanceCenter.lat(), that.center.lat()) - || !floatEqual(instanceCenter.lng(), that.center.lng())) { - _instance.setCenter(that.center); - } - - if (_instance.getZoom() != that.zoom) { - _instance.setZoom(that.zoom); - } - } - }; - - this.fit = function () { - if (_instance && _markers.length) { - - var bounds = new google.maps.LatLngBounds(); - - angular.forEach(_markers, function (m, i) { - bounds.extend(m.getPosition()); - }); - - _instance.fitBounds(bounds); - } - }; - - this.on = function(event, handler) { - _handlers.push({ - "on": event, - "handler": handler - }); - }; - - this.addMarker = function (lat, lng, icon, infoWindowContent, label, url, - thumbnail) { - - if (that.findMarker(lat, lng) != null) { - return; - } - - var marker = new MarkerWithLabel({ - position: new google.maps.LatLng(lat, lng), - draggable: false, - raiseOnDrag: true, - map: _instance, - labelContent: label, - labelAnchor: new google.maps.Point(25, 0), - labelClass: "marker-label", // the CSS class for the label - labelStyle: {opacity: 1.0} - }); - - /* - var marker = new google.maps.Marker({ - position: new google.maps.LatLng(lat, lng), - map: _instance, - icon: icon - }); - */ - - if (label) { - - } - - if (url) { - - } - - if (infoWindowContent != null) { - var infoWindow = new google.maps.InfoWindow({ - content: infoWindowContent - }); - - google.maps.event.addListener(marker, 'click', function() { - if (currentInfoWindow != null) { - currentInfoWindow.close(); - } - infoWindow.open(_instance, marker); - currentInfoWindow = infoWindow; - }); - } - - // Cache marker - _markers.unshift(marker); - - // Cache instance of our marker for scope purposes - that.markers.unshift({ - "lat": lat, - "lng": lng, - "draggable": false, - "icon": icon, - "infoWindowContent": infoWindowContent, - "label": label, - "url": url, - "thumbnail": thumbnail - }); - - // Return marker instance - return marker; - }; - - this.findMarker = function (lat, lng) { - for (var i = 0; i < _markers.length; i++) { - var pos = _markers[i].getPosition(); - - if (floatEqual(pos.lat(), lat) && floatEqual(pos.lng(), lng)) { - return _markers[i]; - } - } - - return null; - }; - - this.findMarkerIndex = function (lat, lng) { - for (var i = 0; i < _markers.length; i++) { - var pos = _markers[i].getPosition(); - - if (floatEqual(pos.lat(), lat) && floatEqual(pos.lng(), lng)) { - return i; - } - } - - return -1; - }; - - this.addInfoWindow = function (lat, lng, html) { - var win = new google.maps.InfoWindow({ - content: html, - position: new google.maps.LatLng(lat, lng) - }); - - _windows.push(win); - - return win; - }; - - this.hasMarker = function (lat, lng) { - return that.findMarker(lat, lng) !== null; - }; - - this.getMarkerInstances = function () { - return _markers; - }; - - this.removeMarkers = function (markerInstances) { - - var s = this; - - angular.forEach(markerInstances, function (v, i) { - var pos = v.getPosition(), - lat = pos.lat(), - lng = pos.lng(), - index = s.findMarkerIndex(lat, lng); - - // Remove from local arrays - _markers.splice(index, 1); - s.markers.splice(index, 1); - - // Remove from map - v.setMap(null); - }); - }; - } - - // Done - return PrivateMapModel; - }()); - - // End model - - // Start Angular directive - - var googleMapsModule = angular.module("google-maps", []); - - /** - * Map directive - */ - googleMapsModule.directive("googleMap", ["$log", "$timeout", "$filter", function ($log, $timeout, - $filter) { - - var controller = function ($scope, $element) { - - var _m = $scope.map; - - self.addInfoWindow = function (lat, lng, content) { - _m.addInfoWindow(lat, lng, content); - }; - }; - - controller.$inject = ['$scope', '$element']; - - return { - restrict: "ECA", - priority: 100, - transclude: true, - template: "<div class='angular-google-map' ng-transclude></div>", - replace: false, - scope: { - center: "=center", // required - markers: "=markers", // optional - latitude: "=latitude", // required - longitude: "=longitude", // required - zoom: "=zoom", // required - refresh: "&refresh", // optional - windows: "=windows", // optional - events: "=events" - }, - controller: controller, - link: function (scope, element, attrs, ctrl) { - - // Center property must be specified and provide lat & - // lng properties - if (!angular.isDefined(scope.center) || - (!angular.isDefined(scope.center.latitude) || - !angular.isDefined(scope.center.longitude))) { - - $log.error("angular-google-maps: could not find a valid center property"); - return; - } - - if (!angular.isDefined(scope.zoom)) { - $log.error("angular-google-maps: map zoom property not set"); - return; - } - - angular.element(element).addClass("angular-google-map"); - - // Parse options - var opts = {options: {}}; - if (attrs.options) { - opts.options = angular.fromJson(attrs.options); - } - - // Create our model - var _m = new MapModel(angular.extend(opts, { - container: element[0], - center: new google.maps.LatLng(scope.center.latitude, scope.center.longitude), - draggable: attrs.draggable == "true", - zoom: scope.zoom - })); - - _m.on("drag", function () { - - var c = _m.center; - - $timeout(function () { - - scope.$apply(function (s) { - scope.center.latitude = c.lat(); - scope.center.longitude = c.lng(); - }); - }); - }); - - _m.on("zoom_changed", function () { - - if (scope.zoom != _m.zoom) { - - $timeout(function () { - - scope.$apply(function (s) { - scope.zoom = _m.zoom; - }); - }); - } - }); - - _m.on("center_changed", function () { - var c = _m.center; - - $timeout(function () { - - scope.$apply(function (s) { - - if (!_m.dragging) { - scope.center.latitude = c.lat(); - scope.center.longitude = c.lng(); - } - }); - }); - }); - - if (angular.isDefined(scope.events)) { - for (var eventName in scope.events) { - if (scope.events.hasOwnProperty(eventName) && angular.isFunction(scope.events[eventName])) { - _m.on(eventName, function () { - scope.events[eventName].apply(scope, [_m, eventName, arguments]); - }); - } - } - } - - if (attrs.markClick == "true") { - (function () { - var cm = null; - - _m.on("click", function (e) { - if (cm == null) { - - cm = { - latitude: e.latLng.lat(), - longitude: e.latLng.lng() - }; - - scope.markers.push(cm); - } - else { - cm.latitude = e.latLng.lat(); - cm.longitude = e.latLng.lng(); - } - - - $timeout(function () { - scope.latitude = cm.latitude; - scope.longitude = cm.longitude; - scope.$apply(); - }); - }); - }()); - } - - // Put the map into the scope - scope.map = _m; - - // Check if we need to refresh the map - if (angular.isUndefined(scope.refresh())) { - // No refresh property given; draw the map immediately - _m.draw(); - } - else { - scope.$watch("refresh()", function (newValue, oldValue) { - if (newValue && !oldValue) { - _m.draw(); - } - }); - } - - // Markers - scope.$watch("markers", function (newValue, oldValue) { - - $timeout(function () { - - angular.forEach(newValue, function (v, i) { - if (!_m.hasMarker(v.latitude, v.longitude)) { - _m.addMarker(v.latitude, v.longitude, v.icon, v.infoWindow, v.label); - } - }); - - // Clear orphaned markers - var orphaned = []; - - angular.forEach(_m.getMarkerInstances(), function (v, i) { - // Check our scope if a marker with equal latitude and longitude. - // If not found, then that marker has been removed form the scope. - - var pos = v.getPosition(), - lat = pos.lat(), - lng = pos.lng(), - found = false; - - // Test against each marker in the scope - for (var si = 0; si < scope.markers.length; si++) { - - var sm = scope.markers[si]; - - if (floatEqual(sm.latitude, lat) && floatEqual(sm.longitude, lng)) { - // Map marker is present in scope too, don't remove - found = true; - } - } - - // Marker in map has not been found in scope. Remove. - if (!found) { - orphaned.push(v); - } - }); - - orphaned.length && _m.removeMarkers(orphaned); - - // Fit map when there are more than one marker. - // This will change the map center coordinates - if (attrs.fit == "true" && newValue && newValue.length > 1) { - _m.fit(); - } - }); - - }, true); - - - // Update map when center coordinates change - scope.$watch("center", function (newValue, oldValue) { - if (newValue === oldValue) { - return; - } - - if (!_m.dragging) { - _m.center = new google.maps.LatLng(newValue.latitude, - newValue.longitude); - _m.draw(); - } - }, true); - - scope.$watch("zoom", function (newValue, oldValue) { - if (newValue === oldValue) { - return; - } - - _m.zoom = newValue; - _m.draw(); - }); - } - }; - }]); -}()); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/app/scripts/vendor/gauge.js ---------------------------------------------------------------------- diff --git a/web/demos/app/scripts/vendor/gauge.js b/web/demos/app/scripts/vendor/gauge.js deleted file mode 100644 index edf6d9b..0000000 --- a/web/demos/app/scripts/vendor/gauge.js +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * Copied from https://github.com/lithiumtech/angular_and_d3 - */ - -function Gauge(element, configuration) -{ - this.element = element; - - var self = this; // for internal d3 functions - - this.configure = function(configuration) - { - this.config = configuration; - - this.config.size = this.config.size * 0.9; - - this.config.raduis = this.config.size * 0.97 / 2; - this.config.cx = this.config.size / 2; - this.config.cy = this.config.size / 2; - - this.config.min = undefined != configuration.min ? configuration.min : 0; - this.config.max = undefined != configuration.max ? configuration.max : 100; - this.config.range = this.config.max - this.config.min; - - this.config.majorTicks = configuration.majorTicks || 5; - this.config.minorTicks = configuration.minorTicks || 2; - - this.config.greenColor = configuration.greenColor || "#109618"; - this.config.yellowColor = configuration.yellowColor || "#FF9900"; - this.config.redColor = configuration.redColor || "#DC3912"; - - this.config.transitionDuration = configuration.transitionDuration || 500; - } - - this.render = function() - { - this.body = d3.select( this.element ) - .append("svg:svg") - .attr("class", "gauge") - .attr("width", this.config.size) - .attr("height", this.config.size); - - this.body.append("svg:circle") - .attr("cx", this.config.cx) - .attr("cy", this.config.cy) - .attr("r", this.config.raduis) - .style("fill", "#ccc") - .style("stroke", "#000") - .style("stroke-width", "0.5px"); - - this.body.append("svg:circle") - .attr("cx", this.config.cx) - .attr("cy", this.config.cy) - .attr("r", 0.9 * this.config.raduis) - .style("fill", "#fff") - .style("stroke", "#e0e0e0") - .style("stroke-width", "2px"); - - for (var index in this.config.greenZones) - { - this.drawBand(this.config.greenZones[index].from, this.config.greenZones[index].to, self.config.greenColor); - } - - for (var index in this.config.yellowZones) - { - this.drawBand(this.config.yellowZones[index].from, this.config.yellowZones[index].to, self.config.yellowColor); - } - - for (var index in this.config.redZones) - { - this.drawBand(this.config.redZones[index].from, this.config.redZones[index].to, self.config.redColor); - } - - if (undefined != this.config.label) - { - var fontSize = Math.round(this.config.size / 9); - this.body.append("svg:text") - .attr("x", this.config.cx) - .attr("y", this.config.cy / 2 + fontSize / 2) - .attr("dy", fontSize / 2) - .attr("text-anchor", "middle") - .text(this.config.label) - .style("font-size", fontSize + "px") - .style("fill", "#333") - .style("stroke-width", "0px"); - } - - var fontSize = Math.round(this.config.size / 16); - var majorDelta = this.config.range / (this.config.majorTicks - 1); - for (var major = this.config.min; major <= this.config.max; major += majorDelta) - { - var minorDelta = majorDelta / this.config.minorTicks; - for (var minor = major + minorDelta; minor < Math.min(major + majorDelta, this.config.max); minor += minorDelta) - { - var point1 = this.valueToPoint(minor, 0.75); - var point2 = this.valueToPoint(minor, 0.85); - - this.body.append("svg:line") - .attr("x1", point1.x) - .attr("y1", point1.y) - .attr("x2", point2.x) - .attr("y2", point2.y) - .style("stroke", "#666") - .style("stroke-width", "1px"); - } - - var point1 = this.valueToPoint(major, 0.7); - var point2 = this.valueToPoint(major, 0.85); - - this.body.append("svg:line") - .attr("x1", point1.x) - .attr("y1", point1.y) - .attr("x2", point2.x) - .attr("y2", point2.y) - .style("stroke", "#333") - .style("stroke-width", "2px"); - - if (major == this.config.min || major == this.config.max) - { - var point = this.valueToPoint(major, 0.63); - - this.body.append("svg:text") - .attr("x", point.x) - .attr("y", point.y) - .attr("dy", fontSize / 3) - .attr("text-anchor", major == this.config.min ? "start" : "end") - .text(major) - .style("font-size", fontSize + "px") - .style("fill", "#333") - .style("stroke-width", "0px"); - } - } - - var pointerContainer = this.body.append("svg:g").attr("class", "pointerContainer"); - - var midValue = (this.config.min + this.config.max) / 2; - - var pointerPath = this.buildPointerPath(midValue); - - var pointerLine = d3.svg.line() - .x(function(d) { return d.x }) - .y(function(d) { return d.y }) - .interpolate("basis"); - - pointerContainer.selectAll("path") - .data([pointerPath]) - .enter() - .append("svg:path") - .attr("d", pointerLine) - .style("fill", "#dc3912") - .style("stroke", "#c63310") - .style("fill-opacity", 0.7) - - pointerContainer.append("svg:circle") - .attr("cx", this.config.cx) - .attr("cy", this.config.cy) - .attr("r", 0.12 * this.config.raduis) - .style("fill", "#4684EE") - .style("stroke", "#666") - .style("opacity", 1); - - var fontSize = Math.round(this.config.size / 10); - pointerContainer.selectAll("text") - .data([midValue]) - .enter() - .append("svg:text") - .attr("x", this.config.cx) - .attr("y", this.config.size - this.config.cy / 4 - fontSize) - .attr("dy", fontSize / 2) - .attr("text-anchor", "middle") - .style("font-size", fontSize + "px") - .style("fill", "#000") - .style("stroke-width", "0px"); - - this.redraw(this.config.min, 0); - } - - this.buildPointerPath = function(value) - { - var delta = this.config.range / 13; - - var head = valueToPoint(value, 0.85); - var head1 = valueToPoint(value - delta, 0.12); - var head2 = valueToPoint(value + delta, 0.12); - - var tailValue = value - (this.config.range * (1/(270/360)) / 2); - var tail = valueToPoint(tailValue, 0.28); - var tail1 = valueToPoint(tailValue - delta, 0.12); - var tail2 = valueToPoint(tailValue + delta, 0.12); - - return [head, head1, tail2, tail, tail1, head2, head]; - - function valueToPoint(value, factor) - { - var point = self.valueToPoint(value, factor); - point.x -= self.config.cx; - point.y -= self.config.cy; - return point; - } - } - - this.drawBand = function(start, end, color) - { - if (0 >= end - start) return; - - this.body.append("svg:path") - .style("fill", color) - .attr("d", d3.svg.arc() - .startAngle(this.valueToRadians(start)) - .endAngle(this.valueToRadians(end)) - .innerRadius(0.65 * this.config.raduis) - .outerRadius(0.85 * this.config.raduis)) - .attr("transform", function() { return "translate(" + self.config.cx + ", " + self.config.cy + ") rotate(270)" }); - } - - this.redraw = function(value, transitionDuration) - { - var pointerContainer = this.body.select(".pointerContainer"); - - pointerContainer.selectAll("text").text(Math.round(value)); - - var pointer = pointerContainer.selectAll("path"); - pointer.transition() - .duration(undefined != transitionDuration ? transitionDuration : this.config.transitionDuration) - //.delay(0) - //.ease("linear") - //.attr("transform", function(d) - .attrTween("transform", function() - { - var pointerValue = value; - if (value > self.config.max) pointerValue = self.config.max + 0.02*self.config.range; - else if (value < self.config.min) pointerValue = self.config.min - 0.02*self.config.range; - var targetRotation = (self.valueToDegrees(pointerValue) - 90); - var currentRotation = self._currentRotation || targetRotation; - self._currentRotation = targetRotation; - - return function(step) - { - var rotation = currentRotation + (targetRotation-currentRotation)*step; - return "translate(" + self.config.cx + ", " + self.config.cy + ") rotate(" + rotation + ")"; - } - }); - } - - this.valueToDegrees = function(value) - { - // thanks @closealert - //return value / this.config.range * 270 - 45; - return value / this.config.range * 270 - (this.config.min / this.config.range * 270 + 45); - } - - this.valueToRadians = function(value) - { - return this.valueToDegrees(value) * Math.PI / 180; - } - - this.valueToPoint = function(value, factor) - { - return { x: this.config.cx - this.config.raduis * factor * Math.cos(this.valueToRadians(value)), - y: this.config.cy - this.config.raduis * factor * Math.sin(this.valueToRadians(value)) }; - } - - // initialization - this.configure(configuration); -} \ No newline at end of file
