Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the VGArrow class.
 /// Clone Constructor. Creates new arrow that is
 /// identical to the given arrow.
 /// </summary>
 /// <param name="arrow">arrow to clone</param>
 private VGArrow(VGArrow arrow)
     : base(
         arrow.ShapeDrawAction,
         arrow.Pen,
         arrow.Brush,
         arrow.Font,
         arrow.FontColor,
         arrow.Bounds,
         arrow.StyleGroup,
         arrow.Name,
         arrow.ElementGroup,
         arrow.Sound)
 {
     this.firstPoint          = arrow.firstPoint;
     this.secondPoint         = arrow.secondPoint;
     this.firstPointWeight    = arrow.firstPointWeight;
     this.secondPointWeight   = arrow.secondPointWeight;
     this.formatString        = arrow.formatString;
     this.weightFont          = arrow.weightFont == null ? null : (Font)arrow.weightFont.Clone();
     this.weightFontColor     = arrow.weightFontColor;
     this.pointsAreSet        = true;
     this.firstPointDistance  = arrow.firstPointDistance;
     this.secondPointDistance = arrow.secondPointDistance;
     this.hideWeights         = arrow.hideWeights;
     this.scaleFactor         = arrow.scaleFactor;
 }
Ejemplo n.º 2
0
    /// <summary>
    /// This method draws the statistic bubbles and transisiton arrows
    ///   of given <see cref="SampleType"/> in given <see cref="VisualizationModes"/>.
    /// </summary>
    /// <param name="mode">
    /// The <see cref="VisualizationModes"/> to be used.
    /// </param>
    /// <param name="sampleType">
    /// The <see cref="SampleType"/> of the data.
    /// </param>
    public void DrawAOIStatistics(VisualizationModes mode, SampleType sampleType)
    {
      // Skip if no data available
      if (this.aoiStatistics == null)
      {
        return;
      }

      // Get all statistical elements
      var statisticalElements = this.Elements.FindAllGroupMembers(VGStyleGroup.AOI_STATISTICS_ARROW);
      statisticalElements.AddRange(this.Elements.FindAllGroupMembers(VGStyleGroup.AOI_STATISTICS_BUBBLE));

      this.Elements.RemoveAll(statisticalElements);

      var distances = new List<int>();

      var aoisWithoutSearchRects = new VGElementCollection();
      foreach (VGElement aoi in this.AoiCollection)
      {
        if (aoi.StyleGroup != VGStyleGroup.AOI_SEARCHRECT)
        {
          aoisWithoutSearchRects.Add(aoi);
        }
      }

      foreach (VGElement aoi in aoisWithoutSearchRects)
      {
        if (!this.aoiStatistics.ContainsKey(aoi.Name))
        {
          continue;
        }

        var aoiStatistic = this.aoiStatistics[aoi.Name];
        if ((mode & VisualizationModes.FixationTime) == VisualizationModes.FixationTime)
        {
          if (aoiStatistic.SumOfTimeOfAllFixations > 0)
          {
            var bounds = this.GetCircleBounds(aoi.Center, aoiStatistic.SumOfTimeOfAllFixations, mode);
            var ellipse = new VGEllipse(
              this.BubbleDrawAction, 
              this.BubblePen, 
              this.BubbleBrush, 
              this.BubbleFont, 
              this.BubbleFontColor, 
              bounds, 
              VGStyleGroup.AOI_STATISTICS_BUBBLE, 
              aoiStatistic.SumOfTimeOfAllFixations + " ms", 
              string.Empty);

            ellipse.TextAlignment = this.BubbleTextAlignment;
            distances.Add((int)(bounds.Width / 2));
            this.Elements.Add(ellipse);
          }
        }

        if ((mode & VisualizationModes.NumberOfFixations) == VisualizationModes.NumberOfFixations)
        {
          if (aoiStatistic.FixationCount > 0)
          {
            var bounds = this.GetCircleBounds(aoi.Center, aoiStatistic.FixationCount, mode);
            var ellipse = new VGEllipse(
              this.BubbleDrawAction, 
              this.BubblePen, 
              this.BubbleBrush, 
              this.BubbleFont, 
              this.BubbleFontColor, 
              bounds, 
              VGStyleGroup.AOI_STATISTICS_BUBBLE, 
              aoiStatistic.FixationCount.ToString(CultureInfo.InvariantCulture), 
              string.Empty);

            ellipse.TextAlignment = this.BubbleTextAlignment;
            distances.Add((int)(bounds.Width / 2));
            this.Elements.Add(ellipse);
          }
        }

        if ((mode & VisualizationModes.AverageFixationDuration) == VisualizationModes.AverageFixationDuration)
        {
          if (aoiStatistic.FixationDurationMean > 0)
          {
            var bounds = this.GetCircleBounds(aoi.Center, aoiStatistic.FixationDurationMean, mode);
            var ellipse = new VGEllipse(
              this.BubbleDrawAction, 
              this.BubblePen, 
              this.BubbleBrush, 
              this.BubbleFont, 
              this.BubbleFontColor, 
              bounds, 
              VGStyleGroup.AOI_STATISTICS_BUBBLE, 
              aoiStatistic.FixationDurationMean.ToString("N0") + " ms", 
              string.Empty);
            ellipse.TextAlignment = this.BubbleTextAlignment;
            distances.Add((int)(bounds.Width / 2));
            this.Elements.Add(ellipse);
          }
        }
      }

      // Check for absolute or relative transition values
      var absolute = (mode & VisualizationModes.AbsoluteTransitions) == VisualizationModes.AbsoluteTransitions;

      if ((mode & VisualizationModes.RelativeTransitions) == VisualizationModes.RelativeTransitions
          || (mode & VisualizationModes.AbsoluteTransitions) == VisualizationModes.AbsoluteTransitions)
      {
        DataView trialsFixations = null;

        // Get filtered fixations data view
        switch (sampleType)
        {
          case SampleType.Gaze:
            trialsFixations = this.GazeFixationsView;
            break;
          case SampleType.Mouse:
            trialsFixations = this.MouseFixationsView;
            break;
        }

        var transitions = Statistics.Statistic.CreateTransitionMatrixForSingleAOIs(
          trialsFixations, 
          aoisWithoutSearchRects);

        float transitionSum = 0;

        // Calculate transition total sum only if relative values are requested.
        if (!absolute)
        {
          for (var i = 0; i <= transitions.GetUpperBound(0); i++)
          {
            // Skip nowhere transitions
            if (i == 0)
            {
              continue;
            }

            for (var j = 0; j <= transitions.GetUpperBound(1); j++)
            {
              // Only take values outside the diagonal
              if (i == j || j == 0)
              {
                continue;
              }

              transitionSum += (int)transitions.GetValue(i, j);
            }
          }
        }

        // Write transitionMatrix to dgv
        for (var i = transitions.GetLowerBound(0); i <= transitions.GetUpperBound(0); i++)
        {
          // Skip nowhere transitions
          if (i == 0)
          {
            continue;
          }

          for (var j = transitions.GetLowerBound(1); j <= transitions.GetUpperBound(1); j++)
          {
            // Only take values above the diagonal
            if (i >= j)
            {
              continue;
            }

            float transAtoB;
            float transBtoA;
            if (absolute)
            {
              transAtoB = (int)transitions.GetValue(i, j);
              transBtoA = (int)transitions.GetValue(j, i);
            }
            else
            {
              transAtoB = (float)Math.Round((int)transitions.GetValue(i, j) / transitionSum * 100, 1);
              transBtoA = (float)Math.Round((int)transitions.GetValue(j, i) / transitionSum * 100, 1);
            }

            if (transAtoB > 0 || transBtoA > 0)
            {
              var showNumbers = false;
              if ((this.ArrowDrawAction & ShapeDrawAction.Name) == ShapeDrawAction.Name)
              {
                this.ArrowDrawAction |= ~ShapeDrawAction.Name;
                showNumbers = true;
              }

              var arrow = new VGArrow(this.ArrowDrawAction, this.ArrowPen);
              arrow.Brush = this.ArrowBrush;
              if (!showNumbers)
              {
                arrow.HideWeights = true;
              }

              var location1 = aoisWithoutSearchRects[i - 1].Center;
              var location2 = aoisWithoutSearchRects[j - 1].Center;
              var distanceFirst = distances.Count >= i ? distances[i - 1] : 15;
              var distanceSecond = distances.Count >= j ? distances[j - 1] : 15;
              if (location1.X <= location2.X)
              {
                arrow.FirstPoint = location1;
                arrow.SecondPoint = location2;
                arrow.FirstPointDistance = distanceFirst;
                arrow.SecondPointDistance = distanceSecond;
                arrow.FirstPointWeight = transBtoA;
                arrow.SecondPointWeight = transAtoB;
              }
              else
              {
                arrow.FirstPoint = location2;
                arrow.SecondPoint = location1;
                arrow.FirstPointDistance = distanceSecond;
                arrow.SecondPointDistance = distanceFirst;
                arrow.FirstPointWeight = transAtoB;
                arrow.SecondPointWeight = transBtoA;
              }

              arrow.FormatString = "N0";
              if (!absolute)
              {
                if (arrow.FirstPointWeight < 1 && arrow.SecondPointWeight < 1)
                {
                  arrow.FormatString = "N1";
                }

                arrow.AddOnString = "%";
              }

              arrow.WeightFont = this.ArrowFont;
              arrow.WeightFontColor = this.ArrowFontColor;
              arrow.ScaleFactor = this.ArrowFactor;
              arrow.StyleGroup = VGStyleGroup.AOI_STATISTICS_ARROW;
              arrow.TextAlignment = this.ArrowTextAlignment;
              this.Elements.Add(arrow);
            }
          }
        }
      }

      this.DrawForeground(true);
    }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the VGArrow class.
 /// Clone Constructor. Creates new arrow that is
 /// identical to the given arrow.
 /// </summary>
 /// <param name="arrow">arrow to clone</param>
 private VGArrow(VGArrow arrow)
   : base(
   arrow.ShapeDrawAction,
   arrow.Pen,
   arrow.Brush,
   arrow.Font,
   arrow.FontColor,
   arrow.Bounds,
   arrow.StyleGroup,
   arrow.Name,
   arrow.ElementGroup,
   arrow.Sound)
 {
   this.firstPoint = arrow.firstPoint;
   this.secondPoint = arrow.secondPoint;
   this.firstPointWeight = arrow.firstPointWeight;
   this.secondPointWeight = arrow.secondPointWeight;
   this.formatString = arrow.formatString;
   this.weightFont = arrow.weightFont == null ? null : (Font)arrow.weightFont.Clone();
   this.weightFontColor = arrow.weightFontColor;
   this.pointsAreSet = true;
   this.firstPointDistance = arrow.firstPointDistance;
   this.secondPointDistance = arrow.secondPointDistance;
   this.hideWeights = arrow.hideWeights;
   this.scaleFactor = arrow.scaleFactor;
 }