IntensityGrid color palette possible bug

Found a possible bug in LightningChart? Report it here.

IntensityGrid color palette possible bug

Postby ezray3 » Sun Nov 18, 2018 10:10 pm

I have the following code,
It should render a vertical heat map that examples the configured palette.
The code for palette creation is attached too.
THE BUG: You can see in the exported bitmap that there are 2 stripes from top to bottom that rendered with the wrong color!!!
If I set the value of all the chart to that value, all the chart will be red instead of light blue!!
If I use the default palette THERE IS NO ISSUE, but i must use my palette, and I double checked it without finding any problem.

ANOTHER MINOR BUG: There is a small gap above and below the chart that I couldn't remove

The result:
TEST.png
result
TEST.png (1.96 KiB) Viewed 1252 times



The Code:

Code: Select all
using Arction.Wpf.Charting;
using Arction.Wpf.Charting.SeriesXY;
using Arction.Wpf.Charting.Titles;
using System;
using System.Windows.Media;

namespace LCExample
{
    public class Class1
    {
        public Class1()
        {
            int MinY = 0 + (int) TimeSpan.FromHours(1).TotalSeconds;
            int MaxY = 6600 + (int) TimeSpan.FromHours(1).TotalSeconds;
            double MinX = 0.5;
            double MaxX = 63.5;
            int _rows = 662;
            int _columns = 119;

            var _chart = new LightningChartUltimate();
            _chart.BeginUpdate();

            var view = _chart.ViewXY;

            _chart.ChartBackground.Color = Colors.White;
            _chart.ChartBackground.GradientFill = GradientFill.Solid;

            view.GraphBordersOverSeries = false;
            view.GraphBorderColor = Colors.Transparent;
            view.GraphBackground = new Fill
            {
                Style = RectFillStyle.None
            };

            _chart.Title.Visible = false;
            _chart.ChartRenderOptions.HeadlessMode = true;
            _chart.Width = _columns;
            _chart.Height = _rows;

            view.LegendBoxes[0].Visible = false;

            var axisX = view.XAxes[0];
            var axisY = view.YAxes[0];

            axisX.SetRange(MinX, MaxX);
            axisY.SetRange(MinY, MaxY);

            var _heatMap = new IntensityGridSeries(view, axisX, axisY)
            {
                MouseInteraction = false,
                Fill = IntensityFillStyle.Paletted,
                PixelRendering = true,
                WireframeType = SurfaceWireframeType.None,
                ContourLineType = ContourLineTypeXY.None,
                RangeMinX = MinX,
                RangeMaxX = MaxX,
                RangeMinY = MinY,
                RangeMaxY = MaxY,
                SizeX = _columns,
                SizeY = _rows
            };

            _heatMap.ValueRangePalette?.Dispose(); // THOSE TWO LINES CAUSES THE BUG - IF REMOVED, IT WORKS BUT I NEED THOSE COLORS
            _heatMap.ValueRangePalette = CreatePalette(_heatMap);


            view.IntensityGridSeries.Add(_heatMap);

            view.AxisLayout.YAxesLayout = YAxesLayout.Stacked;
            view.AxisLayout.XAxisAutoPlacement = XAxisAutoPlacement.AllTop;

            axisX.Visible = false;
            axisX.Title = new AxisXTitle {Visible = false};
            axisX.ValueType = AxisValueType.Number;
            axisX.MouseInteraction = false;

            axisY.Visible = false;
            axisY.Title = new AxisYTitle {Visible = false};
            axisY.ValueType = AxisValueType.Time;
            axisY.MouseInteraction = false;
            axisY.Reversed = true;

            double[][] data = new double[_columns][];
            var points = new IntensityPoint[_columns, _rows];

            for (int i = 0; i < _columns; i++)
            {
                data[i] = new double[_rows];
                for (int j = 0; j < _rows; j++)
                {
                    points[i, j].Value = (double) i / _columns * 63.5;
                }
            }

            _heatMap.Data = points;

            _chart.EndUpdate();

            Console.WriteLine(_chart.SaveToFile("TEST.png") ? "Saved" : "Error");
        }

        private static ValueRangePalette CreatePalette(IntensityGridSeries series)
        {
            ValueRangePalette palette = new ValueRangePalette(series)
            {
                MinValue = 0,
                Type = PaletteType.Uniform
            };

            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 143), 1.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 159), 2.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 175), 3.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 191), 4.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 207), 5.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 223), 6.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 239), 7.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 255), 8.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 15, 255), 9.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 31, 255), 10.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 47, 255), 11.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 63, 255), 12.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 79, 255), 13.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 95, 255), 14.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 111, 255), 15.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 127, 255), 16.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 143, 255), 17.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 159, 255), 18.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 175, 255), 19.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 191, 255), 20.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 207, 255), 21.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 223, 255), 22.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 239, 255), 23.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 255, 255), 24.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(15, 255, 255), 25.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(31, 255, 239), 26.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(47, 255, 223), 27.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(63, 255, 207), 28.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(79, 255, 191), 29.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(95, 255, 175), 30.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(111, 255, 159), 31.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(127, 255, 143), 32.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(143, 255, 127), 33.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(159, 255, 111), 34.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(175, 255, 95), 35.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(191, 255, 79), 36.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(207, 255, 63), 37.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(223, 255, 47), 38.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(239, 255, 31), 39.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 255, 15), 40.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 255, 0), 41.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 239, 0), 42.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 223, 0), 43.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 207, 0), 44.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 191, 0), 45.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 175, 0), 46.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 159, 0), 47.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 143, 0), 48.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 127, 0), 49.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 111, 0), 50.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 95, 0), 51.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 79, 0), 52.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 63, 0), 53.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 47, 0), 54.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 31, 0), 55.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 15, 0), 56.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 0, 0), 57.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(239, 0, 0), 58.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(223, 0, 0), 59.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(207, 0, 0), 60.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(191, 0, 0), 61.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(175, 0, 0), 62.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(159, 0, 0), 63.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(143, 0, 0), 0x7ffe - 1));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 0),
                0x7ffe)); // Above the max

            return palette;
        }
    }
}
ezray3
 
Posts: 9
Joined: Sun Nov 11, 2018 9:41 am

Re: IntensityGrid color palette possible bug

Postby ArctionKestutis » Mon Nov 19, 2018 1:44 pm

Hello,

I believe those NOT the bugs but incorrect usage.

First, then you create new ValueRangePalette object, the default Steps are created (for Winforms and non-bindable WPF). Those steps are:
• Steps[0]: MaxValue:25, Color: Red
• Steps[1]: MaxValue:50, Color: Blue
• Steps[2]: MaxValue:75, Color: Lime
• Steps[3]: MaxValue:100, Color: White

All the Steps max values are reordered before rending. As you may already noticed, Step [0] and [1] from initial palette get into your Palette. That is the reason you got Red and Blue stripes in your chart.
The correct usage not to dispose ValueRangePalette, but clear steps:
Code: Select all
palette.Steps.Clear();


Second, the 'small gap' is actually you Chart's background. You made Graph's Border Color transparent, which now expose the background. The easiest fix is to set Chart's Background color to black-transparent
Code: Select all
 _chart.ChartBackground.Color = Color.FromArgb(0, 0, 0, 0);


Third, I don't see benefit of using Uniform palette with 64 steps instead Gradient palette with few steps. Note: 20 steps are precompiled and load fast. With higher step counts, several seconds delay is to be expected when initializing the chart.
Your palette could recreated with following code and it is loaded much faster:
Code: Select all
            ValueRangePalette palette = new ValueRangePalette(series)
            {
                MinValue = 0,
                Type = PaletteType.Gradient
            };
            palette.Steps.Clear();

            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 143), 0));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 255), 8.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 255, 255), 24.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 255, 0), 41.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(255, 0, 0), 57.5));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(143, 0, 0), 0x7ffe - 1));
            palette.Steps.Add(new PaletteStep(palette, Color.FromRgb(0, 0, 0), 0x7ffe)); // Above the max


All the best.
ArctionKestutis
 
Posts: 363
Joined: Mon Mar 14, 2016 9:22 am

Re: IntensityGrid color palette possible bug

Postby ezray3 » Mon Nov 19, 2018 8:45 pm

Wow, that worked great. I just didn't thought that if I create a new Palette it already have steps in it.

The transparent background worked great too.

about the gradient, I must use those steps exactly because this is the requirement, but I'll check it out.

Thanks!!
ezray3
 
Posts: 9
Joined: Sun Nov 11, 2018 9:41 am


Return to LightningChart Bug Reports

Who is online

Users browsing this forum: No registered users and 1 guest