Updating HeatMapSeries

Dec 19, 2013 at 12:00 PM
Hello,

is there a way to update a PlotModel which contains a HeatMapSeries, without creating a new instance of a PlotModel and overwriting the old one?

I am using the MVVM pattern and WPF here.

I tried using PlotModel.Update(true), PlotModel.RefreshPlot(true) and PlotModel.UpdateAxisTransforms(), but nothing happens.
Coordinator
Jan 7, 2014 at 9:31 PM
The InvalidatePlot/RefreshPlot methods in the PlotModel should update the plot. The Update and UpdateAxisTransforms are not sufficient (these should probably not be public...)

Is this a problem with the HeatMapSeries only? Can you try using some other series (e.g. a LineSeries) just to test that the updating works.
Jan 12, 2014 at 12:00 PM
Thanks for your answer. I tested the LineSeries and it works fine. The problem I have only happens when I change the LinearColorAxis on a HeatMapSeries..


Image

Both plots are created the same way, except for plot 2 I comment out Line 3 and 4:
   HeatMapModel = new PlotModel("Peaks");
   HeatMapModel.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500)  });
   // ((LinearColorAxis)HeatMapModel.Axes[0]).Minimum = 0; // __for the lower plot..__
   //  ((LinearColorAxis)HeatMapModel.Axes[0]).Maximum = 5; 
    var hms = new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData };
   HeatMapModel.Series.Add(hms); 
Now I want to change the Maximum and Minimum of the LinearColorAxis at runtime, by a button click i.e. This only works when I create a new PlotModel!
So this code wont work:
   ((LinearColorAxis)HeatMapModel.Axes[0]).Minimum = 0; 
    ((LinearColorAxis) HeatMapModel.Axes[0]).Maximum = 10;  
    HeatMapModel.RefreshPlot(true);
I have the feeling that this behaviour occurcs, because the HeatMapSeries itself is a PlotModel ( just an assumption..)
Mar 1, 2014 at 10:49 AM
I still have this problem. Any Idea how to solve it? The HeatMapPlot won't react to changes to the ColorAxis till a new PlotModel is created..
Coordinator
Mar 1, 2014 at 1:07 PM
Thanks for the bug report! I have two possible solutions for this:
  1. Create an Invalidate method in the HeatMapSeries that forces the heatmap to be regenerated at next rendering pass. Then call InvalidatePlot/RefreshPlot as you already do.
  2. Let the HeatMapSeries Render method detect when the ColorAxis has changed. It should then call the UpdateImage method. No changes needed to your code.
See the newly checked in code, I think this solves the problem. The hash code calculation used to solve #2 is questionable, I am interested in input on this!
Coordinator
Mar 1, 2014 at 1:10 PM
Note how I wrote the examples to reproduce the problem. Providing examples in the example library makes it much faster to get to the solution. It also makes it easy to verify that it works (also in the online Silverlight example browser).
Mar 1, 2014 at 3:47 PM
Edited Mar 1, 2014 at 4:18 PM
Wow thank you ! I have a huge Overhead in my code because of this issue and now I can finally clean it up :)

Next time I'll try to give a better example for a faster solution!


edit: I just saw your question in the sourcecode, about a faster way to get a HashCode.

It would be a little faster to make a HashCode only from those properties that are responsible for a HeatMapSeries invalidation. For example: Minimum, Maximum and Palette directly change the look of the HeatMapSeries, though changes to properties like TextColor, Titlefont and so on shouldnt invoke a invalidation..
Mar 2, 2014 at 8:30 PM
Edited Mar 2, 2014 at 8:30 PM
I've found another potential Bug. When ColorAxis.RenderAsImage is true, then the mapping of the HighColor of the ColorAxis with the displayed colors in the HeatMap isn't correct.

This can be seen in the LinearColorAxis -> RenderAsImage(vertical reversed) Example..

Image