microsoft / InteractiveDataDisplay.WPF

Interactive Data Display for WPF is a set of controls for adding interactive visualization of dynamic data to your application. It allows to create line graphs, bubble charts, heat maps and other complex 2D plots which are very common in scientific software. Interactive Data Display for WPF integrates well with Bing Maps control to show data on a geographic map in latitude/longitude coordinates. The controls can also be operated programmatically.
Other
968 stars 266 forks source link

HeatMap crashes when zooming out a lot. #29

Closed YusufMavzer closed 3 years ago

YusufMavzer commented 5 years ago

When zooming out of the heatmap up until it's not visible the library throws an

System.ArgumentException: 'Value does not fall within the expected range.' InnerException: ArgumentException: Value does not fall within the expected range.

Class -> BackgroundBitmapRenderer Method -> OnTaskCompleted(RenderResult r, RenderTaskState state)

line of code that causes the crash WriteableBitmap wr = new WriteableBitmap((int)r.Output.Width, (int)r.Output.Height, 96, 96, PixelFormats.Bgra32, null);

If you could adjust that method by adding an extra if statement that would be great. Then I can just update library through nuget

Solution Class BackgroundBitmapRenderer

private void OnTaskCompleted(RenderResult r, RenderTaskState state)
        {
            if (r != null && !state.IsCanceled)
            {
                if ((int)r.Output.Width >= 1 || (int)r.Output.Height >= 1) {  //-----------This if statement can fix it--------------------
                    WriteableBitmap wr = new WriteableBitmap((int)r.Output.Width, (int)r.Output.Height, 96, 96, PixelFormats.Bgra32, null);
                    // Calculate the number of bytes per pixel. 
                    int bytesPerPixel = (wr.Format.BitsPerPixel + 7) / 8;
                    // Stride is bytes per pixel times the number of pixels.
                    // Stride is the byte width of a single rectangle row.
                    int stride = wr.PixelWidth * bytesPerPixel;
                    wr.WritePixels(new Int32Rect(0, 0, wr.PixelWidth, wr.PixelHeight), r.Image, stride, 0);

                    outputImage.Source = wr;
                    Canvas.SetLeft(outputImage, r.Output.Left);
                    Canvas.SetTop(outputImage, r.Output.Top);
                    imageCartesianRect = r.Visible;
                    imageSize = new Size(r.Output.Width, r.Output.Height);
                    outputImage.RenderTransform = null;
                }             
            }
            RaiseTaskCompletion(state.Id);

            runningTasks.Remove(state);

            while (tasks.Count > 1)
            {
                long id = tasks.Dequeue();
                RaiseTaskCompletion(id);
            }
            if (tasks.Count > 0 && runningTasks.Count < maxTasks)
            {
                EnqueueTask(tasks.Dequeue());
            }

            InvalidateMeasure();
        }
07012220 commented 4 years ago

yes, i found it too