Updating HeatMapSeries

Oystein Bjorke 6 years ago 0
This discussion was imported from CodePlex

guevara123 wrote at 2013-12-19 12:00:


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.

objo wrote at 2014-01-07 21:31:

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.

guevara123 wrote at 2014-01-12 12:00:

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..


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 };
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;  
I have the feeling that this behaviour occurcs, because the HeatMapSeries itself is a PlotModel ( just an assumption..)

guevara123 wrote at 2014-03-01 10:49:

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..

objo wrote at 2014-03-01 13:07:

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!

objo wrote at 2014-03-01 13:10:

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).

guevara123 wrote at 2014-03-01 15:47:

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..

guevara123 wrote at 2014-03-02 20:30:

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..