Tuesday, April 21, 2009

Strange values in chart

Infragistics stacked column chart allows to display both negative and not negative values. However, I was adding some post processing based on values and discovered that one has to be careful with Box.Value.

Among others I had a stacked column with values 0, -50, 0, 50, 0. This is what I obtained (Box[][] rows were collected from SceneGraph by Row and Column):


((NumericDataPoint)rows[3][0].DataPoint)
Value: 0.0
((NumericDataPoint)rows[3][1].DataPoint)
Value: -50.0
((NumericDataPoint)rows[3][2].DataPoint)
Value: 0.0
((NumericDataPoint)rows[3][3].DataPoint)
Value: 50.0
((NumericDataPoint)rows[3][4].DataPoint)
Value: 0.0

rows[3][0].Value
0.0
rows[3][1].Value
-50.0
rows[3][2].Value
-50.0
rows[3][3].Value
50.0
rows[3][4].Value
-50.0


There is a kind of warning in the documentation of Box.Value:

The intent behind any data objects referenced by this property are dependent upon the Layer that added this Primitive to the scene graph.
They tend to use it, though, as I saw on forums.

I spent some time trying to find better way then casting Box.DataPoint to NumericDataPoint, but I failed.

Monday, April 6, 2009

Selecting not nulls?

Having a collection IEnumerable<Nullable<T>> myCollection you can select values that are not null by calling myCollection.OfType<T>(). What is not so obvious is that calling myCollection.OfType<Nullable<T>>() would provide the same result.

This is because Enumerable.OfType<TResult> uses is internally to determine the type of item. It means, you can use Enumerable.OfType<T>() even for reference type T to get items that are not null.

Of course, I would prefer calling Where<T>(item => (item != null)) to calling OfType<T>() because the first call is much better in revealing its intention.