Ejemplo n.º 1
0
        private void CreateTransformationMatrix(double wxmin, double wxmax, double wymin, double wymax, double dxmin, double dxmax, double dymin, double dymax)
        {
            // Make WtoD.
            WtoDMatrix = Matrix.Identity;
            WtoDMatrix.Translate(-wxmin, -wymin);

            double xscale = (dxmax - dxmin) / (wxmax - wxmin);
            double yscale = (dymax - dymin) / (wymax - wymin);

            WtoDMatrix.Scale(xscale, yscale);

            WtoDMatrix.Translate(dxmin, dymin);

            // Make DtoW.
            DtoWMatrix = WtoDMatrix;
            DtoWMatrix.Invert();
        }
Ejemplo n.º 2
0
        private void PrepareTransformations(double minWx, double maxWx, double minWy, double maxWy, double minDx,
                                            double maxDx, double maxDy, double minDy)
        {
            // Make WtoD matrix
            WtoDMatrix = Matrix.Identity;
            WtoDMatrix.Translate(-minWx, -minWy);

            double scaleX = (maxDx - minDx) / (maxWx - minWx);
            double scaleY = (maxDy - minDy) / (maxWy - minWy);

            WtoDMatrix.Scale(scaleX, scaleY);

            WtoDMatrix.Translate(minDx, minDy);

            // Make DtoW matrix
            DtoWMatrix = WtoDMatrix;
            DtoWMatrix.Invert();
        }
Ejemplo n.º 3
0
    public static void PrepareTransformations(
        double wxmin, double wxmax, double wymin, double wymax,
        double dxmin, double dxmax, double dymax, double dymin)
    {
        // Make WtoD.
        WtoDMatrix = Matrix.Identity;
        WtoDMatrix.Translate(-wxmin, -wymin);

        double xscale = (dxmax - dxmin) / (wxmax - wxmin);
        double yscale = (dymax - dymin) / (wymax - wymin);

        WtoDMatrix.Scale(xscale, yscale);

        WtoDMatrix.Translate(dxmin, dymin);

        // Make DtoW.
        DtoWMatrix = WtoDMatrix;
        DtoWMatrix.Invert();
    }
Ejemplo n.º 4
0
 // Prepare values for perform transformations.
 private void PrepareTransformations()
 {
     // Make WtoD.
     WtoDMatrix = Matrix.Identity;
     WtoDMatrix.Translate(-World.Xmin, -World.Ymin);
     try //make sure we don't divide by zero
     {
         double xscale = Device.Xmax / (World.Xmax - World.Xmin);
         double yscale = Device.Ymax / (World.Ymax - World.Ymin);
         WtoDMatrix.Scale(xscale, yscale);
         WtoDMatrix.Translate(Device.Xmin, Device.Ymin);
     }
     catch { }
     // Make DtoW.
     DtoWMatrix = WtoDMatrix;
     try
     {
         DtoWMatrix.Invert();
     }
     catch { }
 }
Ejemplo n.º 5
0
        private void DrawGraph()
        {
            //}
            //txtStartDate.Invalidate();
            int wid = GrphPlace.ClientSize.Width;
            int hgt = GrphPlace.ClientSize.Height;

            GraphBm = new Bitmap(wid, hgt);
            using (Graphics gr = Graphics.FromImage(GraphBm))
            {
                gr.SmoothingMode = SmoothingMode.AntiAlias;
                gr.Clear(Color.White);

                // Scale the data to fit.
                int       num_points = Tmprr.Count;
                float     min_price  = (float)Tmprr.Min(data => data.Price);
                float     max_price  = (float)Tmprr.Max(data => data.Price);
                const int margin     = 10;

                WtoDMatrix = MappingMatrix(
                    0, num_points - 1, min_price, max_price,
                    margin, wid - margin, margin, hgt - margin);
                gr.Transform = WtoDMatrix;

                DtoWMatrix = WtoDMatrix.Clone();
                DtoWMatrix.Invert();

                // Draw the graph.
                using (Pen pen = new Pen(Color.Black, 0))
                {
                    // Draw tic marks.
                    PointF[] pts = { new PointF(10, 10) };
                    DtoWMatrix.TransformVectors(pts);
                    float dy = pts[0].Y;
                    float dx = pts[0].X;

                    for (int x = 0; x < Tmprr.Count; x++)
                    {
                        gr.DrawLine(pen, x, min_price, x, min_price + dy);
                    }
                    for (int y = (int)min_price; y <= (int)max_price; y++)
                    {
                        gr.DrawLine(pen, 0, y, dx, y);
                    }

                    // Get a small distance in world coordinates.
                    dx = Math.Abs(dx / 5);
                    dy = Math.Abs(dy / 5);

                    // Draw the data.
                    PointF[] points = new PointF[num_points];
                    for (int i = 0; i < num_points; i++)
                    {
                        float price = (float)Tmprr[i].Price;
                        points[i] = new PointF(i, price);
                        gr.FillRectangle(Brushes.Red,
                                         i - dx, price - dy, 2 * dx, 2 * dy);
                    }
                    pen.Color = Color.Blue;
                    gr.DrawLines(pen, points);
                }
            }

            // Display the result.
            GrphPlace.Image = GraphBm;
        }