Esempio n. 1
0
 var calculate = function (from, to, target, round) {
   var rawInterval;
   round = round || true;
   from = datemath.parse(from).valueOf();
   to = datemath.parse(to, true).valueOf();
   rawInterval = ((to - from) / target);
   var rounded = roundInterval(rawInterval);
   if (!round) rounded.interval = rawInterval;
   return rounded;
 };
Esempio n. 2
0
 this.times = (times.length) ? times.map(function (d) {
   return {
     'time': datemath.parse(d.time),
     'class': d.class || 'time-marker',
     'color': d.color || '#c80000',
     'opacity': d.opacity || 0.3,
     'width': d.width || 2
   };
 }) : currentTimeArr;
Esempio n. 3
0
 _.each(['from', 'to'], function (time) {
   if (moment.isMoment($scope[time])) {
     display[time] = $scope[time].format(dateFormat);
   } else {
     if ($scope[time] === 'now') {
       display[time] = 'now';
     } else {
       var tryParse = datemath.parse($scope[time], time === 'to' ? true : false);
       display[time] = moment.isMoment(tryParse) ? '~ ' + tryParse.fromNow() : $scope[time];
     }
   }
 });
Esempio n. 4
0
        $scope.setMode = function (thisMode) {
          switch (thisMode) {
          case 'quick':
            break;
          case 'relative':
            var fromParts = $scope.from.toString().split('-');
            var relativeParts = [];

            // Try to parse the relative time, if we can't use moment duration to guestimate
            if ($scope.to.toString() === 'now' && fromParts[0] === 'now' && fromParts[1]) {
              relativeParts = fromParts[1].match(/([0-9]+)([smhdwMy]).*/);
            }
            if (relativeParts[1] && relativeParts[2]) {
              $scope.relative.count = parseInt(relativeParts[1], 10);
              $scope.relative.unit = relativeParts[2];
            } else {
              var duration = moment.duration(moment().diff(datemath.parse($scope.from)));
              var units = _.pluck(_.clone($scope.relativeOptions).reverse(), 'value');
              if ($scope.from.toString().split('/')[1]) $scope.relative.round = true;
              for (var i = 0; i < units.length; i++) {
                var as = duration.as(units[i]);
                if (as > 1) {
                  $scope.relative.count = Math.round(as);
                  $scope.relative.unit = units[i];
                  break;
                }
              }
            }

            if ($scope.from.toString().split('/')[1]) $scope.relative.round = true;

            break;
          case 'absolute':
            $scope.absolute.from = datemath.parse($scope.from || moment().subtract('minutes', 15));
            $scope.absolute.to = datemath.parse($scope.to || moment(), true);
            break;
          }

          $scope.mode = thisMode;
        };
Esempio n. 5
0
        it('constructCountQuery - get time filter', function (done) {
          var dashboardId = 'time-testing-4';
          var joinSetFilter = null;
          var savedSearch = emptySavedSearchWithIndexWithTime;

          var expected = {
            size: 0,
            query: {
              filtered: {
                query: {
                  match_all: {}
                },
                filter: {
                  bool: {
                    must: [
                      {
                        range: {
                          fake_field: {
                            gte: datemath.parse('2005-09-01T12:00:00.000Z').valueOf(), // taken from dashboard time-testing-3
                            lte: datemath.parse('2015-09-05T12:00:00.000Z').valueOf()
                          }
                        }
                      }
                    ],
                    must_not: []
                  }
                }
              }
            }
          };

          countHelper.constructCountQuery(dashboardId, savedSearch, joinSetFilter).then(function (query) {
            expect(query).to.eql(expected);
            done();
          });

          $rootScope.$apply();
        });
Esempio n. 6
0
 $scope.updateTime = function () {
   $scope.timeRange = {
     from: datemath.parse(timefilter.time.from),
     to: datemath.parse(timefilter.time.to, true)
   };
 };
Esempio n. 7
0
 Timefilter.prototype.getBounds = function (timefield) {
   return {
     min: datemath.parse(this.time.from),
     max: datemath.parse(this.time.to, true)
   };
 };
Esempio n. 8
0
 $scope.formatRelative = function () {
   var parsed = datemath.parse(getRelativeString());
   $scope.relative.preview =  parsed ? parsed.format($scope.format) : undefined;
   return parsed;
 };
    function showData (resultsSet) {

        var tasks = [];
        var taskNames = [];
        var colorFields = [];

        resultsSet.forEach(function (elem, idx) {

          var newBlock = {};

          newBlock["startDate"] = new Date(elem.start);
          newBlock["endDate"] = new Date(elem.end);
          newBlock["taskName"] = shrinkName(elem.name);

          $scope.customFields.forEach(function (customFieldName) {
            newBlock[customFieldName] = elem[customFieldName];
          })

          // If breakby field enabled then get field for color.
          if ($scope.vis.params.colorEnabled) {
            newBlock["color"] = elem.color;

            if (colorFields.indexOf(elem.color) == -1) {
              colorFields.push(elem.color);
            }
          }

          // Add the task name to the list
          if (taskNames.indexOf(newBlock["taskName"]) == -1) {
            taskNames.push(newBlock["taskName"]);
          }

          tasks.push(newBlock);
        })

        tasks.sort(function(a, b) {
            return a.endDate - b.endDate;
        });

        tasks.sort(function(a, b) {
            return a.startDate - b.startDate;
        });

        taskNames.sort();

        var startTime = datemath.parse(globalState.time.from);
        var endTime = datemath.parse(globalState.time.to);

        // On quick mode filters from and to structure is abit different.
        if ((globalState.time.mode === 'quick') && (globalState.time.from === globalState.time.to)) {
          // On part of the quick mode filters special manipulation is required(Ex: day before yesterday).
          if (globalState.time.from.indexOf('-') > -1) {

            // Get the relative time to add for the correct time range.
            var fromParts = globalState.time.from.split('-');
            var relativeParts = fromParts[1].match(/([0-9]+)([smhdwMy]).*/);
            endTime.add('1', relativeParts[2]);

          } else { // Filters that does not contain dash just need a fixed endtime.
             endTime = datemath.parse('now');
          }
        }

        var timeDiff = moment.duration(endTime.diff(startTime)).asHours();
        var format;
        var ticks = 10

        // Time format for diffrent scale views
        if ((timeDiff <= 0)){
          format = "%H:%M:%S";
        } else if (timeDiff <= 24) {
          format = "%H:%M";
        } else {
          format = "%y-%m-%d %H:%M:%S";
          ticks = 5;
        }

        var gantt = d3.gantt()
          .taskTypes(taskNames)
          .tickFormat(format)
          .ticks(ticks)
          .timeDomainMode("fixed")
          .timeDomain(new Date(startTime.format()), new Date(endTime.format()))
          .tooltipFields($scope.customFields);

        // If color breakby enabled then use the Kibana color factory as a color function.
        if ($scope.vis.params.colorEnabled) {
          // Trying to parse the alias json
          var colorConf;
          try {
            if ($scope.vis.params.colorAlias) {
              colorConf = JSON.parse($scope.vis.params.colorAlias);
            }
          } catch (ex) {
            // Display?
            //console.log('Failed to parse color configuration');
          }

          gantt.colorFunction(function (colorField) {
            // If current field located in the color configuration
            if (colorConf) {
              if (colorConf[colorField]) { return colorConf[colorField]; }
            }

            return color(colorFields)(colorField);
          });
        }

        // Set tasks and container element.
        gantt(tasks, $element.find( ".gantt-chart-vis" ), timefilter);
    }