protected ChartPrimitiveXY(ChartPrimitiveXY chartPrimitiveXY)
     : base(chartPrimitiveXY)
 {
     // Colors to draw the primitive with
     LineColor = chartPrimitiveXY.LineColor;
     FillColor = chartPrimitiveXY.FillColor;
 }
Beispiel #2
0
        /// <summary>
        /// Takes two lines and creates a polyon between them
        /// </summary>
        /// <param name="baseLine"></param>
        /// <param name="topLine"></param>
        /// <returns></returns>
        public static ChartPrimitiveXY LineDiffToPolygon(ChartControl factory, ChartPrimitiveXY baseLine, ChartPrimitiveXY topLine)
        {
            ChartPrimitiveXY polygon       = factory.CreateXY();
            IList <Point>    topLinePoints = topLine.Points;

            if (baseLine != null)
            {
                for (int pointNo = baseLine.Points.Count - 1; pointNo >= 0; --pointNo)
                {
                    polygon.AddPoint(baseLine.Points[pointNo]);
                }
            }
            else
            {
                polygon.AddPoint(new Point(topLinePoints[topLinePoints.Count - 1].X, 0));
                polygon.AddPoint(new Point(0, 0));
            }

            for (int pointNo = 0; pointNo < topLinePoints.Count; ++pointNo)
            {
                polygon.AddPoint(topLinePoints[pointNo]);
            }

            polygon.FillColor = topLine.LineColor;

            return(polygon);
        }
        public ChartPrimitiveXY AddNewXY()
        {
            ChartPrimitiveXY primitive = CreateXY();

            _primitiveList.Add(primitive);
            return(primitive);
        }
Beispiel #4
0
        /// <summary>
        /// Converts population level to a line and polygon using a ChartPrimitive as the baseline
        /// </summary>
        /// <param name="results"></param>
        /// <param name="color"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        public static LineAndPolygon ConvertResultsToPopulationLineAndPolygon(ChartControl factory, float[] results, Color color, string label, ChartPrimitiveXY baseLine)
        {
            ChartPrimitiveXY populationLine = factory.CreateXY();

            populationLine.LineColor   = color;
            populationLine.Label       = label;
            populationLine.LegendColor = color;
            populationLine.IsHitTest   = true;

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

            ChartPrimitiveXY populationPolygon = ChartUtilities.LineDiffToPolygon(factory, baseLine, populationLine);

            color.A = (byte)(_alpha * color.A);
            populationPolygon.FillColor = color;
            populationPolygon.IsHitTest = false;

            return(new LineAndPolygon(populationLine, populationPolygon));
        }
Beispiel #5
0
        private void LoadBackdrop_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == true)
            {
                xyLineChart.Reset();
                xyLineChart.Oversize = 0.0;

                using (MemoryStream backupStream = new MemoryStream()) {
                    using (FileStream stream = new FileStream(dialog.FileName, FileMode.Open)) {
                        stream.CopyTo(backupStream);
                    }
                }
                xyLineChart.Backdrop = new BitmapImage(new Uri(dialog.FileName));

                _dummyLine = xyLineChart.CreateXY();

                _dummyLine.IsHitTest  = false;
                _dummyLine.ShowPoints = false;
                _dummyLine.AddPoint(0, 1);
                _dummyLine.AddPoint(0, 0);
                _dummyLine.AddPoint(1, 0);
                xyLineChart.AddPrimitive(_dummyLine);

                xyLineChart.RedrawPlotLines();
            }
        }
Beispiel #6
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));
        }
Beispiel #7
0
        }//GetPlotRectangle

        /// <summary>
        /// Converts a ChartLine object to a ChartPolygon object that has
        /// one edge along the bottom Horizontal base line in the plot.
        /// </summary>
        /// <param name="chartLine"></param>
        /// <returns></returns>
        public static ChartPrimitiveXY ChartLineToBaseLinedPolygon(ChartPrimitiveXY chartLine)
        {
            ChartPrimitiveXY chartPolygon = chartLine.Clone();

            Point firstPoint = chartPolygon.Points[0];

            firstPoint.Y = 0;
            Point lastPoint = chartPolygon.Points[chartPolygon.Points.Count - 1];

            lastPoint.Y = 0;

            chartPolygon.InsertPoint(firstPoint, 0);
            chartPolygon.AddPoint(lastPoint);
            chartPolygon.FillColor = chartLine.LineColor;

            return(chartPolygon);
        }
    /// <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);
    }
Beispiel #9
0
        public static ChartPrimitiveXY LineFromPoints(this ChartControl factory, string label, IEnumerable <Point> points, Color color)
        {
            ChartPrimitiveXY line = factory.CreateXY();

            // Label the lines
            line.Label         = label;
            line.IsDashed      = false;
            line.IsHitTest     = true;
            line.LineThickness = 1.5;
            line.ShowPoints    = false;

            line.LineColor   = color;
            line.LegendColor = color;

            foreach (var point in points)
            {
                line.AddPoint(point);
            }
            return(line);
        }
Beispiel #10
0
        /// <summary>
        /// Converts movements to a graphical line and polygon
        /// </summary>
        /// <param name="results"></param>
        /// <param name="color"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        public static LineAndPolygon ConvertResultsToMovementLineAndPolygon(ChartControl factory, float[] results, Color color, string label)
        {
            // Create the Line
            ChartPrimitiveXY chartLine = factory.CreateXY();

            chartLine.LineColor   = color;
            chartLine.Label       = label;
            chartLine.LegendColor = color;
            chartLine.IsHitTest   = true;

            for (int monthNo = 0; monthNo < results.Length; ++monthNo)
            {
                chartLine.AddSmoothHorizontalBar(new Point((float)monthNo + .5f, results[monthNo]));
            }

            // Create the polygon
            ChartPrimitiveXY polygon = ChartUtilities.ChartLineToBaseLinedPolygon(chartLine);

            color.A           = (byte)(_alpha * color.A);
            polygon.FillColor = color;
            polygon.IsHitTest = false;

            return(new LineAndPolygon(chartLine, polygon));
        }
Beispiel #11
0
        public static void AddTestLines(ChartControl xyLineChart)
        {
            ChartControl factory = xyLineChart;

            // Add test Lines to demonstrate the control

            xyLineChart.Reset();

            double limit     = 5;
            double increment = .05;

            // Create 3 normal lines
            ChartPrimitiveXY[] lines = new ChartPrimitiveXY[3];

            for (int lineNo = 0; lineNo < 3; ++lineNo)
            {
                ChartPrimitiveXY line = factory.CreateXY();

                // Label the lines
                line.Label         = "Test Line " + (lineNo + 1).ToString();
                line.IsDashed      = false;
                line.IsHitTest     = true;
                line.LineThickness = 1.5;
                line.ShowPoints    = true;

                line.AddPoint(0, 0);

                // Draw 3 sine curves
                for (double x = 0; x < limit + increment * .5; x += increment)
                {
                    line.AddPoint(x, Math.Cos(x * Math.PI - lineNo * Math.PI / 1.5));
                }
                line.AddPoint(limit, 0);

                // Add the lines to the chart
                xyLineChart.AddPrimitive(line);
                lines[lineNo] = line;
            }

            // Set the line colors to Red, Green, and Blue
            lines[0].FillColor = Color.FromArgb(90, 255, 0, 0);
            lines[1].FillColor = Color.FromArgb(90, 0, 180, 0);
            lines[2].FillColor = Color.FromArgb(90, 0, 0, 255);

            // Set the line colors to Red, Green, and Blue
            lines[0].LineColor = Colors.Red;
            lines[1].LineColor = Colors.Green;
            lines[2].LineColor = Colors.Blue;

            lines[0].LegendColor = Colors.Red;
            lines[1].LegendColor = Colors.Green;
            lines[2].LegendColor = Colors.Blue;


            ChartPrimitiveHBar[] bars = new ChartPrimitiveHBar[3];

            // Set the line colors to Red, Green, and Blue
            Color[] barLineColors = new Color[] {
                Colors.Red,
                Colors.Green,
                Colors.Blue
            };

            Color[] barFillColors = new Color[] {
                Color.FromArgb(90, 255, 0, 0),
                Color.FromArgb(90, 0, 180, 0),
                Color.FromArgb(90, 0, 0, 255)
            };

            int colorIndex = 0;

            GridLineOverride gridLineOverride = new GridLineOverride(Orientation.Horizontal);

            gridLineOverride.Range = new Range <double>(-0.2 * (0 + 1) - 1 + 0.05, -0.2 * (2 + 1) - 1 - 0.05);

            for (int barNo = 0; barNo < 3; ++barNo)
            {
                ChartPrimitiveHBar bar = factory.CreateHBar(-0.2 * (barNo + 1) - 1, 0.05);

                gridLineOverride.AddLabel("Bar " + (barNo + 1).ToString(), -0.2 * (barNo + 1) - 1, Orientation.Horizontal);

                // Label the lines
                bar.IsDashed      = false;
                bar.LineThickness = 1;
                bar.IsHitTest     = true;
                bar.Label         = "Test Bar " + (barNo + 1).ToString();

                colorIndex = barNo;
                for (double x = 0; x < 4 + barNo; x += 0.1 * (4 + barNo))
                {
                    bar.AddSegment(x, x + 0.1 * (4 + barNo), barLineColors[colorIndex], barFillColors[colorIndex]);
                    colorIndex = (colorIndex + 1) % 3;
                }
                // Add the lines to the chart
                xyLineChart.AddPrimitive(bar);
                bars[barNo] = bar;
            }

            xyLineChart.GridLineOverrides.Add(gridLineOverride);

            xyLineChart.Title      = "Test Chart Title";
            xyLineChart.XAxisTitle = "Test Chart X Axis";
            xyLineChart.YAxisTitle = "Test Chart Y Axis";

            xyLineChart.RedrawPlotLines();
        }
    public static void AddTestLines(ChartControl xyLineChart) {
      ChartControl factory = xyLineChart;
      // Add test Lines to demonstrate the control

      xyLineChart.Reset();

      double limit = 5;
      double increment = .05;

      // Create 3 normal lines
      ChartPrimitiveXY[] lines = new ChartPrimitiveXY[3];

      for(int lineNo = 0; lineNo < 3; ++lineNo) {
        ChartPrimitiveXY line = factory.CreateXY();

        // Label the lines
        line.Label = "Test Line " + (lineNo + 1).ToString();
        line.IsDashed = false;
        line.IsHitTest = true;
        line.LineThickness = 1.5;
        line.ShowPoints = true;

        line.AddPoint(0, 0);

        // Draw 3 sine curves
        for(double x = 0; x < limit + increment * .5; x += increment) {
          line.AddPoint(x, Math.Cos(x * Math.PI - lineNo * Math.PI / 1.5));
        }
        line.AddPoint(limit, 0);

        // Add the lines to the chart
        xyLineChart.AddPrimitive(line);
        lines[lineNo] = line;
      }

      // Set the line colors to Red, Green, and Blue
      lines[0].FillColor = Color.FromArgb(90, 255, 0, 0);
      lines[1].FillColor = Color.FromArgb(90, 0, 180, 0);
      lines[2].FillColor = Color.FromArgb(90, 0, 0, 255);

      // Set the line colors to Red, Green, and Blue
      lines[0].LineColor = Colors.Red;
      lines[1].LineColor = Colors.Green;
      lines[2].LineColor = Colors.Blue;

      lines[0].LegendColor = Colors.Red;
      lines[1].LegendColor = Colors.Green;
      lines[2].LegendColor = Colors.Blue;


      ChartPrimitiveHBar[] bars = new ChartPrimitiveHBar[3];

      // Set the line colors to Red, Green, and Blue
      Color[] barLineColors = new Color[]{
        Colors.Red,
        Colors.Green,
        Colors.Blue
      };

      Color[] barFillColors = new Color[]{
        Color.FromArgb(90, 255, 0, 0),
        Color.FromArgb(90, 0, 180, 0),
        Color.FromArgb(90, 0, 0, 255)
      };

      int colorIndex = 0;

      GridLineOverride gridLineOverride = new GridLineOverride(Orientation.Horizontal);
      gridLineOverride.Range = new Range<double>(-0.2 * (0 + 1) - 1 + 0.05, -0.2 * (2 + 1) - 1 - 0.05);

      for(int barNo = 0; barNo < 3; ++barNo) {
        ChartPrimitiveHBar bar = factory.CreateHBar(-0.2 * (barNo + 1) - 1, 0.05);

        gridLineOverride.AddLabel("Bar " + (barNo + 1).ToString(),-0.2 * (barNo + 1) - 1, Orientation.Horizontal);

        // Label the lines
        bar.IsDashed = false;
        bar.LineThickness = 1;
        bar.IsHitTest = true;
        bar.Label = "Test Bar " + (barNo + 1).ToString();

        colorIndex = barNo;
        for(double x = 0; x < 4 + barNo; x += 0.1 * (4 + barNo)) {
          bar.AddSegment(x, x+ 0.1 * (4 + barNo), barLineColors[colorIndex], barFillColors[colorIndex]);
          colorIndex = (colorIndex + 1) % 3;
        }
        // Add the lines to the chart
        xyLineChart.AddPrimitive(bar);
        bars[barNo] = bar;
      }

      xyLineChart.GridLineOverrides.Add(gridLineOverride);

      xyLineChart.Title = "Test Chart Title";
      xyLineChart.XAxisTitle = "Test Chart X Axis";
      xyLineChart.YAxisTitle = "Test Chart Y Axis";

      xyLineChart.RedrawPlotLines();
    }
    /// <summary>
    /// Takes two lines and creates a polyon between them
    /// </summary>
    /// <param name="baseLine"></param>
    /// <param name="topLine"></param>
    /// <returns></returns>
    public static ChartPrimitiveXY LineDiffToPolygon(ChartControl factory, ChartPrimitiveXY baseLine, ChartPrimitiveXY topLine) {
      ChartPrimitiveXY polygon = factory.CreateXY();
      IList<Point> topLinePoints = topLine.Points;

      if(baseLine != null) {
        for(int pointNo = baseLine.Points.Count - 1; pointNo >= 0; --pointNo) {
          polygon.AddPoint(baseLine.Points[pointNo]);
        }
      } else {
        polygon.AddPoint(new Point(topLinePoints[topLinePoints.Count - 1].X, 0));
        polygon.AddPoint(new Point(0, 0));
      }

      for(int pointNo = 0; pointNo < topLinePoints.Count; ++pointNo) {
        polygon.AddPoint(topLinePoints[pointNo]);
      }

      polygon.FillColor = topLine.LineColor;

      return polygon;
    }
    }//GetPlotRectangle

    /// <summary>
    /// Converts a ChartLine object to a ChartPolygon object that has
    /// one edge along the bottom Horizontal base line in the plot.
    /// </summary>
    /// <param name="chartLine"></param>
    /// <returns></returns>
    public static ChartPrimitiveXY ChartLineToBaseLinedPolygon(ChartPrimitiveXY chartLine) {
      ChartPrimitiveXY chartPolygon = chartLine.Clone();

      Point firstPoint = chartPolygon.Points[0];
      firstPoint.Y = 0;
      Point lastPoint = chartPolygon.Points[chartPolygon.Points.Count - 1];
      lastPoint.Y = 0;

      chartPolygon.InsertPoint(firstPoint, 0);
      chartPolygon.AddPoint(lastPoint);
      chartPolygon.FillColor = chartLine.LineColor;

      return chartPolygon;
    }
    /// <summary>
    /// Converts population level to a line and polygon using a ChartPrimitive as the baseline
    /// </summary>
    /// <param name="results"></param>
    /// <param name="color"></param>
    /// <param name="label"></param>
    /// <returns></returns>
    public static LineAndPolygon ConvertResultsToPopulationLineAndPolygon(ChartControl factory, float[] results, Color color, string label, ChartPrimitiveXY baseLine) {
      ChartPrimitiveXY populationLine = factory.CreateXY();
      populationLine.LineColor = color;
      populationLine.Label = label;
      populationLine.LegendColor = color;
      populationLine.IsHitTest = true;

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

      ChartPrimitiveXY populationPolygon = ChartUtilities.LineDiffToPolygon(factory, baseLine, populationLine);
      color.A = (byte)(_alpha * color.A);
      populationPolygon.FillColor = color;
      populationPolygon.IsHitTest = false;

      return new LineAndPolygon(populationLine, populationPolygon);
    }
 protected ChartPrimitiveXY(ChartPrimitiveXY chartPrimitiveXY)
   : base(chartPrimitiveXY) {
   // Colors to draw the primitive with
   LineColor = chartPrimitiveXY.LineColor;
   FillColor = chartPrimitiveXY.FillColor;
 }