2 * Copyright (c) 2014 DataTorrent, Inc. ALL Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 .factory('RandomDataModel', function ($interval, WidgetDataModel) {
21 function RandomDataModel() {
24 RandomDataModel.prototype = Object.create(WidgetDataModel.prototype);
25 RandomDataModel.prototype.constructor = WidgetDataModel;
27 angular.extend(RandomDataModel.prototype, {
29 var dataModelOptions = this.dataModelOptions;
30 this.limit = (dataModelOptions && dataModelOptions.limit) ? dataModelOptions.limit : 100;
32 this.updateScope('-');
36 startInterval: function () {
37 $interval.cancel(this.intervalPromise);
39 this.intervalPromise = $interval(function () {
40 var value = Math.floor(Math.random() * this.limit);
41 this.updateScope(value);
45 updateLimit: function (limit) {
46 this.dataModelOptions = this.dataModelOptions ? this.dataModelOptions : {};
47 this.dataModelOptions.limit = limit;
51 destroy: function () {
52 WidgetDataModel.prototype.destroy.call(this);
53 $interval.cancel(this.intervalPromise);
57 return RandomDataModel;