Esempio n. 1
0
 public void AddPoints(IEnumerable <Point> pointsToAdd, ChartPrimitive primitive)
 {
     foreach (Point point in pointsToAdd)
     {
         _points.Add(new PointAndPrimitive(point, primitive));
     }
 }
 public void AddPrimitive(ChartPrimitive primitive)
 {
     if (!_primitiveList.Contains(primitive))
     {
         _primitiveList.Add(primitive);
     }
 }
    /// <summary>
    /// Copy constructor. Deep copies the ChartPrimitive passed in.
    /// </summary>
    /// <param name="chartPrimitive"></param>
    protected ChartPrimitive(ChartPrimitive chartPrimitive)
      : this() {
      IsHitTest = chartPrimitive.IsHitTest;
      Label = chartPrimitive.Label;
      IsHitTest = chartPrimitive.IsHitTest;
      LineThickness = chartPrimitive.LineThickness;
      IsDashed = chartPrimitive.IsDashed;
      LegendColor = chartPrimitive.LegendColor;

      Points = new ObservableCollection<Point>(chartPrimitive.Points);
      Points.CollectionChanged += Points_CollectionChanged;
    }
        /// <summary>
        /// Handles when the mouse moves in a way that that it can execute on a thread that isn't
        /// the GUI thread.
        /// </summary>
        /// <param name="mousePos"></param>
        /// <param name="minimumBounds"></param>
        /// <returns></returns>
        public Point MouseMoved(Point mousePos, Rect minimumBounds)
        {
            bool newLocked             = false;
            PointAndPrimitive newPoint = new PointAndPrimitive(mousePos, null);

            lock (_points) {
                if (_points.Count > 0)
                {
                    double nearestDistanceSquared;
                    newPoint  = GetEllipseScaledNearestPoint(_points, mousePos, (Vector)(minimumBounds.Size), out nearestDistanceSquared);
                    newLocked = nearestDistanceSquared <= 1;
                }
            }

            bool lockedChanged = newLocked != _locked;
            bool pointChanged  = newPoint.Point != _closestPoint.Point;

            if (_closestPoint.Primitive != null && _closestPoint.Primitive.LegendLabel != null)
            {
                _closestPoint.Primitive.LegendLabel.IsHighlighted = false;
            }

            _locked       = newLocked;
            _closestPoint = newPoint;

            Action updateGui = () => {
                if (_closestPoint.Primitive != null)
                {
                    ChartPrimitive primitive = _closestPoint.Primitive;

                    if (primitive.LegendColor != Colors.Transparent && primitive.LegendLabel != null && _locked)
                    {
                        primitive.LegendLabel.IsHighlighted = true;
                    }
                }
                if ((pointChanged && _locked) || lockedChanged)
                {
                    OnClosestPointChanged();
                }
            };

            if (_dispatcher.Thread != Thread.CurrentThread)
            {
                _dispatcher.Invoke(updateGui);
            }
            else
            {
                updateGui();
            }

            return(_locked ? _closestPoint.Point : mousePos);
        }
Esempio n. 5
0
        /// <summary>
        /// Copy constructor. Deep copies the ChartPrimitive passed in.
        /// </summary>
        /// <param name="chartPrimitive"></param>
        protected ChartPrimitive(ChartPrimitive chartPrimitive)
            : this()
        {
            IsHitTest     = chartPrimitive.IsHitTest;
            Label         = chartPrimitive.Label;
            IsHitTest     = chartPrimitive.IsHitTest;
            LineThickness = chartPrimitive.LineThickness;
            IsDashed      = chartPrimitive.IsDashed;
            LegendColor   = chartPrimitive.LegendColor;

            Points = new ObservableCollection <Point>(chartPrimitive.Points);
            Points.CollectionChanged += Points_CollectionChanged;
        }
    /// <summary>
    /// Gets ChartLines and ChartPolygons for the population line, and
    /// the target line using a baseline.
    /// </summary>
    public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartControl factory, ChartPrimitive populationLine, float[] results, Color color, string label, ChartPrimitiveXY baseLine) {

      // Calculate Target Primitives
      ChartPrimitiveXY targetLine = factory.CreateXY();
      targetLine.LineColor = color;
      targetLine.IsDashed = true;
      targetLine.Label = label + " Target";
      targetLine.IsHitTest = true;

      if(populationLine.Points.Count == results.Length) {
        if(baseLine == null) {
          for(int monthNo = 0; monthNo < results.Length; monthNo += 2) {
            targetLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo]));
            targetLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1]));
          }
        } else {
          for(int monthNo = 0; monthNo < results.Length; monthNo += 2) {
            targetLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo] + baseLine.Points[monthNo].Y));
            targetLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1] + baseLine.Points[monthNo + 1].Y));
          }
        }
      } else {
        if(baseLine == null) {
          for(int monthNo = 0; monthNo < results.Length; ++monthNo) {
            targetLine.AddPoint(new Point((float)monthNo, results[monthNo]));
            targetLine.AddPoint(new Point((float)monthNo + 1f, results[monthNo]));
          }
        } else {
          for(int monthNo = 0; monthNo < results.Length; ++monthNo) {
            targetLine.AddPoint(new Point((float)monthNo, results[monthNo] + baseLine.Points[monthNo].Y));
            targetLine.AddPoint(new Point((float)monthNo + 1f, results[monthNo] + baseLine.Points[monthNo + 1].Y));
          }
        }
      }

      ChartPrimitiveXY targetPolygon = ChartUtilities.LineDiffToPolygon(factory, baseLine, targetLine);
      color.A = (byte)(_alpha * color.A);
      targetPolygon.FillColor = color;
      targetPolygon.IsDashed = true;
      targetLine.IsHitTest = false;

      return new LineAndPolygon(targetLine, targetPolygon);
    }
 public LineAndPolygon(ChartPrimitive line, ChartPrimitive polygon)
 {
     Line    = line;
     Polygon = polygon;
 }
 public PointAndPrimitive(Point point, ChartPrimitive primitive)
 {
     Point     = point;
     Primitive = primitive;
 }
 public PointAndPrimitive(Point point, ChartPrimitive primitive){
   Point = point;
   Primitive = primitive;
 }
 public void AddPoints(IEnumerable<Point> pointsToAdd, ChartPrimitive primitive) {
   foreach(Point point in pointsToAdd) {
     _points.Add(new PointAndPrimitive(point, primitive));
   }
 }
Esempio n. 11
0
 public LineAndPolygon(ChartPrimitive line, ChartPrimitive polygon) {
   Line = line;
   Polygon = polygon;
 }
Esempio n. 12
0
 public void AddPrimitive(ChartPrimitive primitive) {
   if(!_primitiveList.Contains(primitive)) {
     _primitiveList.Add(primitive);
   }
 }
 /// <summary>
 /// Gets ChartLines and ChartPolygons for the population line, and
 /// the target line.
 /// </summary>
 public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartControl factory, ChartPrimitive populationLine, float[] results, Color color, string label) {
   return ConvertResultsToTargetLineAndPolygon(factory, populationLine, results, color, label, null);
 }
Esempio n. 14
0
        /// <summary>
        /// Gets ChartLines and ChartPolygons for the population line, and
        /// the target line using a baseline.
        /// </summary>
        public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartControl factory, ChartPrimitive populationLine, float[] results, Color color, string label, ChartPrimitiveXY baseLine)
        {
            // Calculate Target Primitives
            ChartPrimitiveXY targetLine = factory.CreateXY();

            targetLine.LineColor = color;
            targetLine.IsDashed  = true;
            targetLine.Label     = label + " Target";
            targetLine.IsHitTest = true;

            if (populationLine.Points.Count == results.Length)
            {
                if (baseLine == null)
                {
                    for (int monthNo = 0; monthNo < results.Length; monthNo += 2)
                    {
                        targetLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo]));
                        targetLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1]));
                    }
                }
                else
                {
                    for (int monthNo = 0; monthNo < results.Length; monthNo += 2)
                    {
                        targetLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo] + baseLine.Points[monthNo].Y));
                        targetLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1] + baseLine.Points[monthNo + 1].Y));
                    }
                }
            }
            else
            {
                if (baseLine == null)
                {
                    for (int monthNo = 0; monthNo < results.Length; ++monthNo)
                    {
                        targetLine.AddPoint(new Point((float)monthNo, results[monthNo]));
                        targetLine.AddPoint(new Point((float)monthNo + 1f, results[monthNo]));
                    }
                }
                else
                {
                    for (int monthNo = 0; monthNo < results.Length; ++monthNo)
                    {
                        targetLine.AddPoint(new Point((float)monthNo, results[monthNo] + baseLine.Points[monthNo].Y));
                        targetLine.AddPoint(new Point((float)monthNo + 1f, results[monthNo] + baseLine.Points[monthNo + 1].Y));
                    }
                }
            }

            ChartPrimitiveXY targetPolygon = ChartUtilities.LineDiffToPolygon(factory, baseLine, targetLine);

            color.A = (byte)(_alpha * color.A);
            targetPolygon.FillColor = color;
            targetPolygon.IsDashed  = true;
            targetLine.IsHitTest    = false;

            return(new LineAndPolygon(targetLine, targetPolygon));
        }
Esempio n. 15
0
 /// <summary>
 /// Gets ChartLines and ChartPolygons for the population line, and
 /// the target line.
 /// </summary>
 public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartControl factory, ChartPrimitive populationLine, float[] results, Color color, string label)
 {
     return(ConvertResultsToTargetLineAndPolygon(factory, populationLine, results, color, label, null));
 }
Esempio n. 16
0
 public void RemovePrimitive(ChartPrimitive primitive)
 {
     _primitiveList.Remove(primitive);
 }