Esempio n. 1
0
        internal override async void Drawing()
        {
            if (OwnerChart == null || OwnerChart.ItemsSource == null || OwnerChart.XAxis == null || OwnerChart.YAxis == null)
            {
                return;
            }
            IEnumerable <IList> items = OwnerChart.ItemsSource;
            IAxis xaxis = OwnerChart.XAxis;
            IAxis yaxis = OwnerChart.YAxis;

            if (OwnerChart.X < 0)
            {
                OwnerChart.X = 0;
            }
            int x = OwnerChart.X;

            if (OwnerChart.Y < 0)
            {
                OwnerChart.Y = 1;
            }
            int y = OwnerChart.Y;

            using (var getdatatask = xaxis.GetHistogramViewData(items, x, Count))
            {
                var datas = await getdatatask;

                if (datas.Count() <= 0)
                {
                    var tempdc = DV.RenderOpen();
                    tempdc.DrawLine(new Pen(this.Stroke, 0), new Point(0, 0), new Point(0, 0));
                    tempdc.Close();
                    return;
                }
                var maxy = datas.Max(p => p.Value);
                yaxis.Max = maxy * 1.2;
                yaxis.Min = 0;
                yaxis.Drawing();
                var height = this.ActualHeight;
                Func <double, ValueLocationConvertParam, double> YGetLocation = yaxis.GetValueLocation;
                var yconvert = yaxis.GetConvertParam();
                var task     = Task.Run(() =>
                {
                    var streamGeometry = new StreamGeometry()
                    {
                        FillRule = FillRule.EvenOdd
                    };
                    using (StreamGeometryContext sgc = streamGeometry.Open())
                    {
                        List <Point> points = new List <Point>();
                        foreach (var data in datas)
                        {
                            var yvalue = YGetLocation(data.Value, yconvert);
                            if (double.IsNaN(data.Key[0]) || double.IsInfinity(data.Key[0]) ||
                                double.IsNaN(data.Key[1]) || double.IsInfinity(data.Key[1]) ||
                                double.IsNaN(yvalue) || double.IsInfinity(yvalue))
                            {
                                continue;
                            }
                            points.Add(new Point(data.Key[0], yvalue));
                            points.Add(new Point(data.Key[1], yvalue));
                        }
                        if (points.Count > 0)
                        {
                            points.Add(new Point(points[points.Count - 1].X, height));
                            points.Add(new Point(points[0].X, height));
                            sgc.BeginFigure(new Point(points[0].X, height), true, true);
                            sgc.PolyLineTo(points, false, false);
                        }
                        else
                        {
                            sgc.BeginFigure(new Point(0, 0), true, true);
                            sgc.LineTo(new Point(0, 0), false, false);
                        }
                        sgc.Close();
                    }
                    streamGeometry.Freeze();
                    return(streamGeometry);
                });
                var geometryTemp = await task;
                task.Dispose();
                var dc = DV.RenderOpen();
                base.ClearTransform();
                dc.DrawGeometry(this.Fill, new Pen(this.Stroke, 1), geometryTemp);
                dc.Close();
            }
        }
Esempio n. 2
0
        private Task <List <StreamGeometry> > CreateGeometrys(IEnumerable <IList> items, IAxis xaxis, IAxis yaxis, int x, int y)
        {
            var areaLength = this.PointLength;
            var gradesBase = this.GradesBase;
            var width      = xaxis.ActualWidth;
            var height     = yaxis.ActualHeight;
            Func <double, ValueLocationConvertParam, double> xGetLocation = xaxis.GetValueLocation;
            Func <double, ValueLocationConvertParam, double> yGetLocation = yaxis.GetValueLocation;
            var xParam = xaxis.GetConvertParam();
            var yParam = yaxis.GetConvertParam();
            var maxX   = xaxis.Max;
            var minX   = xaxis.Min;
            var maxY   = yaxis.Max;
            var minY   = yaxis.Min;

            return(Task.Run(() =>
            {
                Dictionary <int, Dictionary <int, long> > datas = new Dictionary <int, Dictionary <int, long> >();
                for (int i = 0; i < width; i += areaLength)
                {
                    datas.Add(i, new Dictionary <int, long>());
                    for (int j = 0; j < height; j += areaLength)
                    {
                        datas[i].Add(j, 0L);
                    }
                }
                foreach (var item in items)
                {
                    var valueX = Convert.ToDouble(item[x]);
                    var valueY = Convert.ToDouble(item[y]);
                    if (valueX > maxX || valueX < minX || valueY > maxY || valueY < minY)
                    {
                        continue;
                    }
                    var xLocation = xGetLocation(valueX, xParam);
                    var yLocation = yGetLocation(valueY, yParam);
                    if (double.IsNaN(xLocation) || double.IsInfinity(xLocation) || double.IsNaN(yLocation) || double.IsInfinity(yLocation))
                    {
                        continue;
                    }
                    var x1 = Math.Abs(xLocation % areaLength) > 0 ? ((Convert.ToInt32(xLocation) / areaLength - 1) * areaLength) : Convert.ToInt32(xLocation);
                    var y1 = Math.Abs(yLocation % areaLength) > 0 ? ((Convert.ToInt32(yLocation) / areaLength - 1) * areaLength) : Convert.ToInt32(yLocation);
                    if (datas.ContainsKey(x1) && datas[x1].ContainsKey(y1))
                    {
                        datas[x1][y1] += 1;
                    }
                }
                var maxCount = datas.Values.Max(p => p.Values.Max(k => k));
                List <StreamGeometry> streams = new List <StreamGeometry>();
                List <StreamGeometryContext> sgcs = new List <StreamGeometryContext>();
                var count = maxCount == 0 ? 0 : Convert.ToInt32(Math.Log(maxCount, gradesBase));
                for (int i = 0; i <= count; i++)
                {
                    var streamGeometry = new StreamGeometry()
                    {
                        FillRule = FillRule.Nonzero
                    };
                    streams.Add(streamGeometry);
                    StreamGeometryContext sgc = streamGeometry.Open();
                    sgcs.Add(sgc);
                }
                foreach (var data in datas)
                {
                    foreach (var temp in data.Value)
                    {
                        if (temp.Value <= 0L)
                        {
                            continue;
                        }
                        var index = Convert.ToInt32(Math.Log(temp.Value, gradesBase));
                        sgcs[index].BeginFigure(new Point(data.Key, temp.Key), true, true);
                        sgcs[index].PolyLineTo(new Point[] { new Point(data.Key + areaLength, temp.Key), new Point(data.Key + areaLength, temp.Key + areaLength), new Point(data.Key, temp.Key + areaLength) }, false, false);
                    }
                }
                foreach (var sgc in sgcs)
                {
                    sgc.Close();
                }
                foreach (var stream in streams)
                {
                    stream.Freeze();
                }
                return streams;
            }));
        }
Esempio n. 3
0
        public override async void Drawing()
        {
            if (OwnerChart == null || OwnerChart.ItemsSource == null || OwnerChart.XAxis == null || OwnerChart.YAxis == null)
            {
                return;
            }
            IEnumerable <IList> items = OwnerChart.ItemsSource;
            IAxis xaxis = OwnerChart.XAxis;
            IAxis yaxis = OwnerChart.YAxis;
            int   x     = OwnerChart.X;
            int   y     = OwnerChart.Y;

            Func <double, ValueLocationConvertParam, double> xGetLocation = xaxis.GetLocation;
            Func <double, ValueLocationConvertParam, double> yGetLocation = yaxis.GetLocation;
            int xIntLength    = Convert.ToInt32(this.ActualWidth);
            int yIntLength    = Convert.ToInt32(this.ActualHeight);
            var xConvertParam = xaxis.GetConvertParam();
            var yConvertParam = yaxis.GetConvertParam();
            Func <long, long, Color> getGradientColor = this.GetGradientColor;

            using var task = Task.Run(() =>
            {
                long maxCount = 1;
                Dictionary <int, Dictionary <int, long> > points = new Dictionary <int, Dictionary <int, long> >();
                foreach (var item in items)
                {
                    var xvalue = xGetLocation(Convert.ToDouble(item[x]), xConvertParam);
                    var yvalue = yGetLocation(Convert.ToDouble(item[y]), yConvertParam);
                    if (double.IsNaN(xvalue) || double.IsInfinity(xvalue) || double.IsNaN(yvalue) || double.IsInfinity(yvalue))
                    {
                        continue;
                    }
                    var xv = Convert.ToInt32(xvalue);
                    var yv = Convert.ToInt32(yvalue);
                    if (xv >= xIntLength || xv < 0 || yv >= yIntLength || yv < 0)
                    {
                        continue;
                    }
                    if (points.ContainsKey(xv))
                    {
                        var temp = points[xv];
                        if (temp.ContainsKey(yv))
                        {
                            temp[yv] += 1;
                        }
                        else
                        {
                            temp[yv] = 1;
                        }
                    }
                    else
                    {
                        points[xv] = new Dictionary <int, long>
                        {
                            [yv] = 1
                        };
                    }
                }
                maxCount = points.Max(p => p.Value.Values.Max());

                var bitmap = new WriteableBitmap(xIntLength, yIntLength, 96, 96, PixelFormats.Bgr32, null);
                #region 背景色
                byte[] backcolor = new byte[xIntLength * 4];
                for (int i = 0; i < xIntLength; i++)
                {
                    BackgroundColor.CopyTo(backcolor, i * 4);
                }
                for (int i = 0; i < yIntLength; i++)
                {
                    Int32Rect rect = new Int32Rect(0, i, xIntLength, 1);
                    bitmap.WritePixels(rect, backcolor, backcolor.Length, 0);
                }
                #endregion

                try
                {
                    bitmap.Lock();
                    foreach (var line in points)
                    {
                        foreach (var point in line.Value)
                        {
                            unsafe
                            {
                                // Get a pointer to the back buffer.
                                IntPtr pBackBuffer = bitmap.BackBuffer;
                                // Find the address of the pixel to draw.
                                pBackBuffer += point.Key * bitmap.BackBufferStride;
                                pBackBuffer += line.Key * 4;
                                // Assign the color data to the pixel.
                                var color           = getGradientColor(point.Value, maxCount);
                                *(int *)pBackBuffer = (color.R << 16) | (color.G << 8) | (color.B);
                            }
                            bitmap.AddDirtyRect(new Int32Rect(line.Key, point.Key, 1, 1));
                        }
                    }
                }
                finally
                {
                    bitmap.Unlock();
                }
                bitmap.Freeze();
                return(bitmap);
            });
            var bitmap = await task;
            using var dc = DV.RenderOpen();
            base.ClearTransform();
            dc.DrawImage(bitmap, new Rect(new Size(xIntLength, yIntLength)));
            dc.Close();
        }
Esempio n. 4
0
        private Task <List <StreamGeometry> > CreateGeometrys(IEnumerable <IList> items, IAxis xaxis, IAxis yaxis, int x, int y)
        {
            var pointLength = this.PointLength;
            var areaLength  = this.AreaLength;
            var gradesBase  = this.GradesBase;
            var width       = xaxis.ActualWidth;
            var height      = yaxis.ActualHeight;
            Func <double, ValueLocationConvertParam, double> xGetLocation = xaxis.GetValueLocation;
            Func <double, ValueLocationConvertParam, double> yGetLocation = yaxis.GetValueLocation;
            var xParam = xaxis.GetConvertParam();
            var yParam = yaxis.GetConvertParam();
            var maxX   = xaxis.Max;
            var minX   = xaxis.Min;
            var maxY   = yaxis.Max;
            var minY   = yaxis.Min;

            return(Task.Run(() =>
            {
                Dictionary <int, Dictionary <int, Area> > measureData = new Dictionary <int, Dictionary <int, Area> >();
                for (int i = 0; i < width; i += areaLength)
                {
                    measureData.Add(i, new Dictionary <int, Area>());
                    for (int j = 0; j < height; j += areaLength)
                    {
                        measureData[i].Add(j, new Area(i, j, i + areaLength, j + areaLength));
                    }
                }
                foreach (var item in items)
                {
                    var valueX = Convert.ToDouble(item[x]);
                    var valueY = Convert.ToDouble(item[y]);
                    if (valueX > maxX || valueX < minX || valueY > maxY || valueY < minY)
                    {
                        continue;
                    }
                    var xLocation = xGetLocation(valueX, xParam);
                    var yLocation = yGetLocation(valueY, yParam);
                    if (double.IsNaN(xLocation) || double.IsInfinity(xLocation) || double.IsNaN(yLocation) || double.IsInfinity(yLocation))
                    {
                        continue;
                    }
                    var x1 = Math.Abs(xLocation % areaLength) > 0 ? ((Convert.ToInt32(xLocation) / areaLength - 1) * areaLength) : Convert.ToInt32(xLocation);
                    var y1 = Math.Abs(yLocation % areaLength) > 0 ? ((Convert.ToInt32(yLocation) / areaLength - 1) * areaLength) : Convert.ToInt32(yLocation);
                    if (measureData.ContainsKey(x1) && measureData[x1].ContainsKey(y1))
                    {
                        var temp = measureData[x1][y1];
                        temp.Points.Add(new Point(xLocation, yLocation));
                    }
                }
                var maxCount = measureData.Values.Max(p => p.Values.Max(k => k.PointsCount));
                List <StreamGeometry> streams = new List <StreamGeometry>();
                List <StreamGeometryContext> sgcs = new List <StreamGeometryContext>();
                var count = maxCount == 0 ? 0 : Math.Log(maxCount, gradesBase);// Convert.ToInt32(maxCount / subrange);
                for (int i = 0; i <= count; i++)
                {
                    var streamGeometry = new StreamGeometry()
                    {
                        FillRule = FillRule.Nonzero
                    };
                    streams.Add(streamGeometry);
                    StreamGeometryContext sgc = streamGeometry.Open();
                    sgcs.Add(sgc);
                }
                foreach (var data in measureData)
                {
                    foreach (var temp in data.Value)
                    {
                        DrawingVisual(sgcs, GetNearArea(measureData, temp.Value), gradesBase, temp.Value, pointLength, areaLength);
                    }
                }
                foreach (var sgc in sgcs)
                {
                    sgc.Close();
                }
                foreach (var stream in streams)
                {
                    stream.Freeze();
                }
                return streams;
            }));
        }
Esempio n. 5
0
        internal override async void Drawing()
        {
            if (OwnerChart == null || OwnerChart.ItemsSource == null || OwnerChart.XAxis == null || OwnerChart.YAxis == null)
            {
                return;
            }
            IEnumerable <IList> items = OwnerChart.ItemsSource;
            IAxis xaxis = OwnerChart.XAxis;
            IAxis yaxis = OwnerChart.YAxis;

            if (OwnerChart.X < 0)
            {
                OwnerChart.X = 0;
            }
            int x = OwnerChart.X;

            if (OwnerChart.Y < 0)
            {
                OwnerChart.Y = 1;
            }
            int y           = OwnerChart.Y;
            var pointLength = PointLength;
            Func <double, ValueLocationConvertParam, double> XGetLocation = xaxis.GetValueLocation;
            Func <double, ValueLocationConvertParam, double> YGetLocation = yaxis.GetValueLocation;
            var xconvert = xaxis.GetConvertParam();
            var yconvert = yaxis.GetConvertParam();
            var maxX     = OwnerChart.XAxis.Max;
            var minX     = OwnerChart.XAxis.Min;
            var maxY     = OwnerChart.YAxis.Max;
            var minY     = OwnerChart.YAxis.Min;
            var task     = Task.Run(() =>
            {
                Dictionary <int, List <int> > existed = new Dictionary <int, List <int> >();
                var streamGeometry = new StreamGeometry()
                {
                    FillRule = FillRule.Nonzero
                };
                using (StreamGeometryContext sgc = streamGeometry.Open())
                {
                    //Size size = new Size(pointLength, pointLength);
                    foreach (var item in items)
                    {
                        var valueX = Convert.ToDouble(item[x]);
                        var valueY = Convert.ToDouble(item[y]);
                        if (valueX > maxX || valueX < minX || valueY > maxY || valueY < minY)
                        {
                            continue;
                        }
                        var xvalue = XGetLocation(valueX, xconvert);
                        var yvalue = YGetLocation(valueY, yconvert);
                        if (double.IsNaN(xvalue) || double.IsInfinity(xvalue) || double.IsNaN(yvalue) || double.IsInfinity(yvalue))
                        {
                            continue;
                        }
                        var xtemp = Convert.ToInt32(xvalue);
                        var ytemp = Convert.ToInt32(yvalue);
                        var point = new Point(xtemp, ytemp);
                        if (existed.ContainsKey(xtemp) && existed[xtemp].Contains(ytemp))
                        {
                            continue;
                        }
                        if (existed.ContainsKey(xtemp))
                        {
                            existed[xtemp].Add(ytemp);
                        }
                        else
                        {
                            existed[xtemp] = new List <int>()
                            {
                                ytemp
                            }
                        };
                        sgc.BeginFigure(point, true, true);
                        sgc.PolyLineTo(new Point[] { new Point(xtemp + pointLength, ytemp), new Point(xtemp + pointLength, ytemp + pointLength), new Point(xtemp, ytemp + pointLength) }, false, false);
                        //圆形点位,速度较慢
                        //sgc.ArcTo(new Point(xvalue, yvalue + pointLength), size, 0, true, SweepDirection.Clockwise, false, false);
                        //sgc.ArcTo(point, size, 0, true, SweepDirection.Clockwise, false, false);
                    }
                    sgc.Close();
                }
                streamGeometry.Freeze();
                return(streamGeometry);
            });
            var geometryTemp = await task;

            using (var dc = DV.RenderOpen())
            {
                base.ClearTransform();
                dc.DrawGeometry(this.Fill, new Pen(this.Stroke, 0), geometryTemp);
                dc.Close();
            }
        }