Misbehaviour of the Heatmap series

May 21, 2013 at 9:58 PM
Hi,
First of all a big bravo for the project. You have done an amazing job.
I experienced an interesting misbehavior of the heatmap series. When you are adding a symmetric matrix, the heatmap series generated is not completely correct since it is slightly shifted.

Image

Here is the code that I used to generate the above image.
public static PlotModel SymmetricHeatmap()
        {
            double x0 = 0;
            double x1 = 16;
            double y0 = 0;
            double y1 = 16;

            var random = new Random();
            var data   = new double[17,17];

            for (var i = 0; i < 17; i++)
            {
                data[i, i] = 0.0;
            }
           
            for (var i = 1; i < 17; i++)
            {
                for (var j = 0; j < i; j++)
                {
                    var num = random.NextDouble();
                    data[i, j] = num;
                    data[j, i] = num;
                }
            }
            
            var model = new PlotModel("Peaks");
            model.Axes.Add( new ColorAxis 
                                { 
                                    Position    = AxisPosition.Right, 
                                    Palette     = OxyPalettes.Hot(500), 
                                    HighColor   = OxyColors.Gray, 
                                    LowColor    = OxyColors.Black 
                                });

            model.Series.Add(new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = data });
            return model;
        }
Also I had to change the Render override of the HeatmapSeries in order to get the colors to align correctly according to the axis.
public override void Render(IRenderContext rc, PlotModel model)
        {
            if (this.Data == null)
            {
                this.image = null;
                return;
            }

            var left        = this.X0;
            var right      = this.X1;
            var bottom  = this.Y0;
            var top        = this.Y1;

            var s00 = this.Transform(left, bottom);
            var s11 = this.Transform(right, top);
            var rect = OxyRect.Create(s00, s11);

            if (this.image == null || this.Data.GetHashCode() != this.dataHash)
            {
                this.UpdateImage();
                this.dataHash = this.Data.GetHashCode();
            }

            if (this.image != null)
            {
                var clip = this.GetClippingRect();

                rc.DrawClippedImage(clip, this.image, rect.Left, rect.Top, rect.Width, rect.Height, 1, true);
            }
        }