Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.31 KB | None | 0 0
  1. <div data-ng-app="report2">
  2.     <div  data-ng-controller="MyCtrl" style="width: 1440px; height: 300px">
  3.  
  4.  
  5.         smoothDistance:
  6.         <input type="number" name="quantity" id="smoothDistance">
  7.         <input name="Do Smooth!" value="Do Smooth!" type="button" onclick="smooth();"/>
  8.         <br/>
  9.         dB:
  10.         <input type="number" name="quantity" id="abovedB">
  11.         <input name="Get Seconds" value="Get Seconds above dB" type="button" onclick="getSecondsAbovedB();"/>
  12.         <br/>
  13.         <input type="button" value="Reset data" onclick="reset();"/>
  14.         <br/>
  15.         Custom code goes here:
  16.         <textarea name="codeText" id="codeText"></textarea>
  17.         <input type="button" value="Run" onclick="runScript('codeText');"/>
  18.  
  19.         <select
  20.            ng-model="selectedEvent"
  21.            ng-change="eventSelect.changed()"
  22.            ng-options="event.name + ' - ' + event.startDateTime for event in events">
  23.         </select>
  24.  
  25.  
  26.  
  27.         <graph ng-repeat="graph in graphs" data="graph.data" opts="graph.opts"></graph>
  28.     </div>
  29. </div>
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. <script>
  44. var myApp = angular.module('report2', []);
  45.  
  46. var mainGraph;
  47.  
  48. myApp.controller('MyCtrl', ["$scope", "$http", function($scope, $http) {
  49.  
  50.     $http.get("//" + location.host + "/event/upcomingEvents")
  51.     .success(function(response) {
  52.         $scope.events = response.events;
  53.         $scope.selectedEvent = $scope.events[0];
  54.         createLoadChart2($scope, $http)();
  55.         console.log("Graph data: " + $scope.chart1Data);
  56.  
  57.     });
  58.         $scope.eventSelect = {};
  59.         $scope.eventSelect.changed = createLoadChart2($scope, $http);
  60.  
  61. }]);
  62.  
  63. myApp.directive('graph', function() {
  64.     return {
  65.         restrict: 'E', // Use as element
  66.         scope: { // Isolate scope
  67.             data: '=', // Two-way bind data to local scope
  68.             opts: '=?' // '?' means optional
  69.         },
  70.         template: "<div style='width: 1440px; height: 300px'></div>", // We need a div to attach graph to
  71.         link: function(scope, elem, attrs) {
  72.  
  73.             var graph = new Dygraph(elem.children()[0], scope.data, scope.opts );
  74.  
  75.             mainGraph = graph;
  76.         }
  77.     };
  78. });
  79.  
  80. var chart1Data;
  81.  
  82. function createLoadChart2($scope, $http) {
  83.         return function loadChart() {
  84.             console.log("Loading..");
  85.  
  86.             console.log($http.defaults.headers);
  87.                var config = {headers: {
  88.             'Cache-Control': 'public',
  89.             'Pragma': ''
  90.         }
  91.     };
  92.  
  93.             $http.get("//" + location.host + "/report/eventChunksDatapoints?eventId=" + $scope.selectedEvent.id, config)
  94.             .success(function(response) {
  95.                 console.log("$http.get success, response: " + response.datapoints.length);
  96.                 var sdt = response.event[0].startDateTime;
  97.                 var td = parseInt(response.event[0].totalDuration);
  98.                 chunkDuration = parseInt(response.event[0].chunkDuration);
  99.  
  100.                 var seriesData = []
  101.  
  102.                 var previousChunkId = response.datapoints[0].c;
  103.                 var plotBandStart = Date.UTC(
  104.                         sdt.slice(0,4), sdt.slice(4,6)-1, sdt.slice(6,8),
  105.                         sdt.slice(8,10), sdt.slice(10,12), (parseInt(sdt.slice(12))),
  106.                         (response.datapoints[0].t*1000));
  107.                 var plotBandEnd = plotBandStart;
  108.  
  109.                 var chunkIndex = -1;
  110.                 for (var i=0; i < response.datapoints.length; i++) {
  111.                    var timestamp = Date.UTC(
  112.                        sdt.slice(0,4), sdt.slice(4,6)-1, sdt.slice(6,8),
  113.                        sdt.slice(8,10), sdt.slice(10,12), (parseInt(sdt.slice(12))),
  114.                        (response.datapoints[i].t*1000));
  115.  
  116.                    /*if (response.datapoints[i].c != previousChunkId) {
  117.  
  118.                        console.log("current: " + new Date(plotBandStart) + " - " + new Date(plotBandEnd) +
  119.                            " - " + previousChunkId +
  120.                            ": " + response.chunks[previousChunkId].filename);
  121.                        $scope.highchartsNG.xAxis.plotBands.push({
  122.                            from: plotBandStart,
  123.                            to: plotBandEnd,
  124.                            color: (++chunkIndex % 2 == 0 ? '#F1F1FF' : "#F1FFF1"),
  125.                            id: 'plot-band-' + previousChunkId,
  126.                            events: {
  127.                                mouseover: updatePlayOggFunction(location.host, response.chunks[previousChunkId].filename)
  128.                            }
  129.                        });
  130.                        previousChunkId = response.datapoints[i].c;
  131.                        plotBandStart = plotBandEnd;
  132.                    } else if (i == response.datapoints.length-1) {
  133.                        plotBandEnd = timestamp;
  134.                        var lastChunkId = response.datapoints[i].c;
  135.                        console.log("last: " + new Date(plotBandStart) + " - " + new Date(plotBandEnd) +
  136.                            " - " + lastChunkId +
  137.                            ": " + response.chunks[lastChunkId].filename);
  138.  
  139.                        $scope.highchartsNG.xAxis.plotBands.push({
  140.                            from: plotBandStart,
  141.                            to: plotBandEnd,
  142.                            color: (++chunkIndex % 2 == 0 ? '#F1F1FF' : "#F1FFF1"),
  143.                            id: 'plot-band-' + lastChunkId,
  144.                            events: {
  145.                                mouseover: updatePlayOggFunction(location.host, response.chunks[lastChunkId].filename)
  146.                            }
  147.                        });
  148.                    }*/
  149.  
  150.                    //seriesData.push([timestamp, response.datapoints[i].d]);
  151.                    seriesData.push([i, response.datapoints[i].d]);
  152.                    plotBandEnd = timestamp;
  153.                }
  154.                  chart1Data = seriesData;
  155.  
  156.                          $scope.graphs = [
  157.            {
  158.                //data: [ [1,10], [2,20], [3,50], [4,70] ],
  159.                data: chart1Data,
  160.                opts: { labels: [ "x", "A"], digitsAfterDecimal: 8 }
  161.  
  162.            }
  163.        ];
  164.               // $scope.highchartsNG.options.navigator.series.data = seriesData;
  165.              //  $scope.highchartsNG.loading = false;
  166.            });
  167.        };
  168.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement