Exemple #1
0
        public void Draw(DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis)
        {
            Pen pen = new Pen(_stroke, _strokeThickness);

            for (int i = 0; i < _xs.Count - 1; ++i)
            {
                double x1 = hAxis.WorldToPhysical(_xs[i], ClippingType.Clip);
                double x2 = hAxis.WorldToPhysical(_xs[i + 1], ClippingType.Clip);
                double y1 = vAxis.WorldToPhysical(_ys[i], ClippingType.Clip);
                double y2 = vAxis.WorldToPhysical(_ys[i + 1], ClippingType.Clip);

                dc.DrawLine(pen, new Point(x1, y1), new Point(x2, y2));
            }
        }
Exemple #2
0
        /// <summary>
        /// Draw method
        /// </summary>
        /// <param name="dc">DrawingContext on which to draw.</param>
        /// <param name="hAxis">horizontal axis to draw against.</param>
        /// <param name="vAxis">vertical axis to draw against.</param>
        public void Draw(DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis)
        {
            Pen minorPen = new Pen(_stroke_minor, _strokeThickness_minor);
            Pen majorPen = new Pen(_stroke_major, _strokeThickness_major);

            if (_visibility_horizontal == Visibility.Visible)
            {
                List <AxisMarking> hTicks = hAxis.GetAxisMarkings();

                for (int i = 0; i < hTicks.Count; ++i)
                {
                    Pen p = minorPen;
                    if (hTicks[i].TickType == TickType.Large)
                    {
                        p = majorPen;
                    }

                    double x = hAxis.WorldToPhysical(hTicks[i].World, ClippingType.Clip);

                    dc.DrawLine(p, new Point(x, vAxis.PhysicalMinY), new Point(x, vAxis.PhysicalMaxY));
                }
            }

            if (_visibility_vertical == Visibility.Visible)
            {
                List <AxisMarking> vTicks = vAxis.GetAxisMarkings();

                for (int i = 0; i < vTicks.Count; ++i)
                {
                    Pen p = minorPen;
                    if (vTicks[i].TickType == TickType.Large)
                    {
                        p = majorPen;
                    }

                    double y = vAxis.WorldToPhysical(vTicks[i].World, ClippingType.Clip);

                    dc.DrawLine(p, new Point((int)hAxis.PhysicalMinX, (int)y), new Point((int)hAxis.PhysicalMaxX, (int)y));
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Draws the contours against a horizontal and vertical axis.
        /// </summary>
        /// <param name="dc">The drawing context on which to draw.</param>
        /// <param name="hAxis">The horizontal physical axis to draw against.</param>
        /// <param name="vAxis">The vertical physical axis to draw against.</param>
        public void Draw(System.Windows.Media.DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis)
        {
            double worldHorizontalRange = hAxis.Axis.WorldMax - hAxis.Axis.WorldMin;
            double worldVerticalRange   = vAxis.Axis.WorldMax - vAxis.Axis.WorldMin;

            for (int i = 0; i < _internalGridSize.Rows; ++i)
            {
                for (int j = 0; j < _internalGridSize.Columns; ++j)
                {
                    double worldY = (double)i / (double)(_internalGridSize.Rows - 1) * worldVerticalRange + vAxis.Axis.WorldMin;
                    double worldX = (double)j / (double)(_internalGridSize.Columns - 1) * worldHorizontalRange + hAxis.Axis.WorldMin;
                    _grid[i, j] = _fieldMethod(worldX, worldY);
                }
            }

            Pair <List <double>, List <List <LineSegment> > > contourGroups = ContourUtils.ContourGenCore.Generate(_grid, _levels);

            double physicalHorizontalRange = hAxis.PhysicalMaxX - hAxis.PhysicalMinX;
            double physicalVerticalRange   = vAxis.PhysicalMaxY - vAxis.PhysicalMinY;

            Pen p = new Pen(_stroke, _strokeThickness);

            for (int i = 0; i < contourGroups.First.Count; ++i)
            {
                List <LineSegment> lineSegments = contourGroups.Second[i];

                // find best index to put label.
                int bestJ = DetermineBestLabelPosition(lineSegments, 0, _internalGridSize.Columns - 1, 0, _internalGridSize.Rows - 1);

                // see if line segment sequence is reasonably long. If so, put a contour label on it.
                bool drawingLabel = false;
                if (_showContourLabels)
                {
                    double sum = 0.0;
                    for (int k = 0; k < lineSegments.Count; ++k)
                    {
                        sum += Math.Abs(lineSegments[k].X1 - lineSegments[k].X2) + Math.Abs(lineSegments[k].Y1 - lineSegments[k].Y2);
                        if (sum > _internalGridSize.Rows / 6.0)
                        {
                            drawingLabel = true;
                            break;
                        }
                    }
                }

                if (drawingLabel)
                {
                    LineSegment ls = lineSegments[bestJ];

                    double x1 = ls.X1 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double x2 = ls.X2 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double y1 = ls.Y1 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;
                    double y2 = ls.Y2 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;

                    FormattedText ft = new FormattedText(contourGroups.First[i].ToString(_contourLabelFormat),
                                                         System.Globalization.CultureInfo.CurrentCulture,
                                                         FlowDirection.LeftToRight, new Typeface("Arial"), 11, _stroke);

                    double angle = Math.Atan2(
                        contourGroups.Second[i][bestJ].Y1 - contourGroups.Second[i][bestJ].Y2,
                        contourGroups.Second[i][bestJ].X2 - contourGroups.Second[i][bestJ].X1) / Math.PI * 180.0;

                    if (angle > 90)
                    {
                        angle -= 180;
                    }
                    if (angle < -90)
                    {
                        angle += 180;
                    }

                    RotateTransform rt = new RotateTransform(angle);

                    dc.PushTransform(new TranslateTransform((x1 + x2) / 2.0, (y1 + y2) / 2.0));
                    dc.PushTransform(rt);
                    dc.DrawText(ft, new Point(-ft.Width / 2.0, -ft.Height / 2.0));
                    dc.Pop();
                    dc.Pop();

                    Rect r1 = new Rect(hAxis.PhysicalMinX, vAxis.PhysicalMaxY, hAxis.PhysicalMaxX - hAxis.PhysicalMinX, vAxis.PhysicalMinY - vAxis.PhysicalMaxY);
                    Rect r2 = new Rect((x1 + x2) / 2.0 - ft.Width * 1.6 / 2.0, (y1 + y2) / 2.0 - ft.Height * 1.6 / 2.0, ft.Width * 1.6, ft.Height * 1.6);

                    DrawingBrush db = new DrawingBrush();
                    db.ViewboxUnits  = BrushMappingMode.Absolute;
                    db.ViewportUnits = BrushMappingMode.Absolute;
                    db.Viewport      = r1;
                    db.Viewbox       = r1;

                    GeometryGroup gg = new GeometryGroup();
                    gg.FillRule = FillRule.Nonzero;

                    if (r2.Left - r1.Left > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r1.Top, r2.Left - r1.Left, r1.Height));
                        gg.Children.Add(rg);
                    }
                    if (r1.Right - r2.Right > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r2.Right, r1.Top, r1.Right - r2.Right, r1.Height));
                        gg.Children.Add(rg);
                    }
                    if (r2.Top - r1.Top > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r1.Top, r1.Width, r2.Top - r1.Top));
                        gg.Children.Add(rg);
                    }
                    if (r1.Bottom - r2.Bottom > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r2.Bottom, r1.Width, r1.Bottom - r2.Bottom));
                        gg.Children.Add(rg);
                    }

                    SolidColorBrush scb = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                    GeometryDrawing gd  = new GeometryDrawing(scb, null, gg);
                    db.Drawing = gd;

                    dc.PushOpacityMask(db);
                }

                for (int j = 0; j < lineSegments.Count; ++j)
                {
                    LineSegment ls = lineSegments[j];

                    double x1 = ls.X1 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double x2 = ls.X2 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double y1 = ls.Y1 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;
                    double y2 = ls.Y2 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;

                    dc.DrawLine(p, new Point(x1, y1), new Point(x2, y2));
                }

                if (drawingLabel)
                {
                    // pop opacity mask.
                    dc.Pop();
                }
            }
        }
Exemple #4
0
 public void Draw(System.Windows.Media.DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Exemple #5
0
        /// <summary>
        /// The main draw function.
        /// </summary>
        /// <param name="dc">DrawingContext to draw on</param>
        /// <param name="hAxis">horizontal axis to draw against.</param>
        /// <param name="vAxis">vertical axis to draw against.</param>
        public void Draw(DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis)
        {
            // check that there are the correct number of fill brushes defined (or none at all).
            if (_fills != null)
            {
                if (_fills.Count != _ys.Count)
                {
                    throw new WChartException("Either the same number of Fills as y bars should be defined, or Fills should be set to null.");
                }
            }

            Pen p = new Pen(_stroke, _strokeThickness);

            for (int i = 0; i < _xs.Count; ++i)
            {
                if (_xs[i] < hAxis.Axis.WorldMin || _xs[i] > hAxis.Axis.WorldMax)
                {
                    continue;
                }

                double x1 = _xs[i] - BarWidth / 2.0;
                double x2 = _xs[i] + BarWidth / 2.0;

                int firstY = (int)vAxis.PhysicalMinY;
                int prevY  = (int)vAxis.PhysicalMinY;
                for (int j = 0; j < _ys.Count; ++j)
                {
                    double y1 = _ys[j][i];

                    double px1      = hAxis.WorldToPhysical(x1, ClippingType.Clip);
                    double px2      = hAxis.WorldToPhysical(x2, ClippingType.Clip);
                    int    currentY = (int)vAxis.WorldToPhysical(y1, ClippingType.NoClip) - firstY + prevY;

                    Brush fill = _defaultFill;
                    if (_fills != null)
                    {
                        fill = _fills[j];
                    }
                    dc.DrawRectangle(fill, p, new Rect((int)px1, currentY, (int)(px2 - px1), prevY - currentY));

                    if (_showValueText && y1 != 0.0)
                    {
                        FormattedText ft = new FormattedText(
                            y1.ToString(_valueTextFormat), CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                            new Typeface("Arial"), 13.0, Brushes.Black);

                        if (ft.Width < prevY - currentY + 2)
                        {
                            Point pp = new Point(-ft.Width / 2.0, -ft.Height / 2.0);
                            dc.PushTransform(new TranslateTransform((int)((px1 + px2) / 2.0),
                                                                    (int)((prevY + currentY) / 2.0)));
                            dc.PushTransform(new RotateTransform(-90));
                            dc.DrawText(ft, pp);
                            dc.Pop();
                            dc.Pop();
                        }
                    }
                    prevY = currentY;
                }
            }
        }
Exemple #6
0
        public void Draw(System.Windows.Media.DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis)
        {
            double worldHorizontalRange    = hAxis.Axis.WorldMax - hAxis.Axis.WorldMin;
            double worldVerticalRange      = vAxis.Axis.WorldMax - vAxis.Axis.WorldMin;
            double physicalHorizontalRange = Math.Abs(hAxis.PhysicalMaxX - hAxis.PhysicalMinX);
            double physicalVerticalRange   = Math.Abs(vAxis.PhysicalMaxY - vAxis.PhysicalMinY);

            double worldBoxWidth     = worldHorizontalRange / _internalGridSize.Columns;
            double worldBoxHeight    = worldVerticalRange / _internalGridSize.Rows;
            double physicalBoxWidth  = physicalHorizontalRange / _internalGridSize.Columns + 1.0;
            double physicalBoxHeight = physicalVerticalRange / _internalGridSize.Rows + 1.0;

            byte[] img = new byte[_internalGridSize.Rows * _internalGridSize.Columns * 4];
            for (int i = 0; i < _internalGridSize.Rows; ++i)
            {
                for (int j = 0; j < _internalGridSize.Columns; ++j)
                {
                    double worldY = (double)i / (double)(_internalGridSize.Rows) * worldVerticalRange + vAxis.Axis.WorldMin + worldBoxHeight / 2.0;
                    double worldX = (double)j / (double)(_internalGridSize.Columns) * worldHorizontalRange + hAxis.Axis.WorldMin + worldBoxWidth / 2.0;
                    double val    = FieldMethod(worldX, worldY);

                    int ind = -1;
                    for (int k = 0; k < _gradientStops.Count; ++k)
                    {
                        if (_gradientStops[k].First > val)
                        {
                            ind = k;
                            break;
                        }
                    }

                    Color c;
                    if (ind == -1)
                    {
                        c = _gradientStops[_gradientStops.Count - 1].Second;
                    }
                    else if (ind == 0)
                    {
                        c = _gradientStops[0].Second;
                    }
                    else
                    {
                        Color  c1  = _gradientStops[ind - 1].Second;
                        double gv1 = _gradientStops[ind - 1].First;
                        Color  c2  = _gradientStops[ind].Second;
                        double gv2 = _gradientStops[ind].First;
                        System.Diagnostics.Debug.Assert(val >= gv1 && val < gv2);
                        double prop = (val - gv1) / (gv2 - gv1);
                        c = Color.FromRgb(
                            (byte)(c1.R * (1.0 - prop) + c2.R * prop),
                            (byte)(c1.G * (1.0 - prop) + c2.G * prop),
                            (byte)(c1.B * (1.0 - prop) + c2.B * prop));
                    }

                    img[(_internalGridSize.Rows - 1 - i) * _internalGridSize.Columns * 4 + j * 4]     = c.R;
                    img[(_internalGridSize.Rows - 1 - i) * _internalGridSize.Columns * 4 + j * 4 + 1] = c.G;
                    img[(_internalGridSize.Rows - 1 - i) * _internalGridSize.Columns * 4 + j * 4 + 2] = c.B;
                }
            }
            BitmapSource bs = BitmapSource.Create(_internalGridSize.Columns, _internalGridSize.Rows, 96, 96, PixelFormats.Bgr32, null, img, _internalGridSize.Columns * 4);

            dc.DrawImage(bs, new Rect(hAxis.PhysicalMinX, vAxis.PhysicalMaxY, physicalHorizontalRange, physicalVerticalRange));

            /*
             * for (int i = 0; i < _internalGridSize.Rows; ++i)
             * {
             *  for (int j = 0; j < _internalGridSize.Columns; ++j)
             *  {
             *      double worldY = (double)i / (double)(_internalGridSize.Rows) * worldVerticalRange + vAxis.Axis.WorldMin + worldBoxHeight / 2.0;
             *      double worldX = (double)j / (double)(_internalGridSize.Columns) * worldHorizontalRange + hAxis.Axis.WorldMin + worldBoxWidth / 2.0;
             *
             *      Color c = Color.FromRgb(0, 0, 0);
             *      for (int k = 0; k < _gradientStops.Count; ++k)
             *      {
             *          if (_gradientStops[k].First > FieldMethod(worldX, worldY))
             *          {
             *              break;
             *          }
             *          c = _gradientStops[k].Second;
             *      }
             *
             *      dc.DrawRectangle(b, null,
             *          new Rect(
             *              hAxis.WorldToPhysical(worldX, ClippingType.Clip) - physicalBoxWidth / 2.0,
             *              vAxis.WorldToPhysical(worldY, ClippingType.Clip) - physicalBoxHeight / 2.0,
             *              physicalBoxWidth, physicalBoxHeight));
             *
             *  }
             * }
             */
        }