.NET, Data Visualization

Exploding Bubbles: Visualising Multi-dimensional Data using Infragistics Silverlight Controls (Part 1)

The Short Version

You can interact with the chart by:

  • Left-clicking on bubbles to explode them
  • Right-clicking on exploded bubbles to implode them

[Run Exploding Bubbles]

UPDATE: Exploding Bubbles was made into a showcase application by Infragistics. It was restyled and renamed to Population Explosion. The restyled version can be found here:

[Run Population Explosion]

The Long Version

In a fascinating video titled Nano-data and Now-Casting: The Analytics Revolution, MIT Sloan Professor Roberto Rigobon says,

“The world has a lot of data, now available [sic]. (But), the world has very little information.”

In a previous post, I touched upon the need for innovative ways to make meaning from the large amount of data that we have access to today and the growing importance of analytics:

“Massive amounts of data – either publicly available, or within enterprises – is a defining feature of computing today, and of growing importance for tomorrow.  In fact it’s given rise to a new discipline: data science. As the amount of data grows, traditional methods and tools for making sense of all this data break down and new innovations are necessary.”

One of the ways to understand data is interactive data visualisations. Multidimensional data is especially tricky to visualise because of the complexities of each data point, but if done properly, can provide real insight from the macro- as well as micro-level. A great example of this is the “exploding bubbles” technique, presented by Hans Rosling in a TED Talk from 2006. Look for exploding bubbles starting from around 9m30s into the video.

Inspired by this, I developed the Exploding Bubbles application using Infragistics Silverlight and Silverlight Data Visualization controls.

Here is a video of Exploding Bubbles in action:

This is what the application looks like when you first run it:

Image001

On the left you will notice a pivot grid showing multidimensional data. On the right is a bubble chart, a visualisation of that data.

The pivot grid shows global “health and wealth” statistics. The data is plotted on the chart in the following way:

  • Population is depicted by bubble size
  • GDP Per Capita is depicted on the X-axis on a logarithmic scale
  • Life Expectancy is depicted on the Y-axis on a linear scale

You can interact with the chart by:

  • Left-clicking on bubbles to explode them
  • Right-clicking on exploded bubbles to implode them

You can also interact with pivot grid by expanding or collapsing rows – the bubble chart is synchronised with the pivot grid’s data.

Image002
Image003

You can download the source code from here: http://dl.dropbox.com/u/15104486/ExplodingBubbles.zip

Have fun!

In following posts, I will talk about the implementation details and cover aspects of the following Infragistics controls/features:

  • Pivot Grid
  • Data Chart
  • Excel
  • Dock Manager
  • Motion Framework
  • Theming

In the meantime, for more details of what you can achieve using these and other Silverlight controls from Infragistics, you can browse through the samples and read the documentation.

Read the rest of the posts in the series:

Part 2: Data Aspects

Part 3: Visualisation Aspects

Part 4: Docking, Theming, Cloud Deployment

Standard
.NET

iOS Development with .NET

Three years ago I blogged about the “iPhone bringing the Internet to your pocket”.  And now we have the iPad, the target device for most innovation in tablet apps.

If, like me, you’re keen to build iOS apps but are primarily a Microsoft developer and are daunted by the learning curve of a whole new platform, then MonoTouch might be for you: http://monotouch.net/

MonoTouch is a bridge between .NET and the native iOS API called CocoaTouch.  It exposes the CocoaTouch as a .NET library so you can write code in C# instead of Objective-C. This gives you access to all the native CocoaTouch GUI widgets and a whole bunch of regular .NET libraries.

Media_httpwwwmonoproj_kjezj
Media_httpwwwmonoproj_krhgf
Image001

This is really neat!  Have a look at the Hello World tutorial to get a better feel of MonoTouch: http://monotouch.net/Tutorials/MonoDevelop_HelloWorld

Standard
.NET

Improving LINQ Except and Intersect by using a lambda expression for custom comparison

I was recently doing some work where I had to use Except and Insersect, but with some custom comparison logic.  Let me illustrate by way of an example.  If I had the following class

public class Widget
{
    public int ID { get; set; }
    public string Name { get; set; }
}

and created two lists like this

List<Widget> first = new List<Widget>()
{
    new Widget() { ID = 1, Name = "Alpha"},
    new Widget() { ID = 2, Name = "Beta"},
    new Widget() { ID = 3, Name = "Gamma"},
}; 

List<Widget> second = new List<Widget>()
{
    new Widget() { ID = 2, Name = "Foo"},
    new Widget() { ID = 3, Name = "Bar"},
    new Widget() { ID = 4, Name = "Baz"},
};

and tried to use Except like this

first.Except(second).ToList().ForEach(x => Console.WriteLine("ID=" + x.ID + ", " + x.Name));

I would get:

ID=1, Alpha
ID=2, Beta
ID=3, Gamma

Since I wanted to do a comparison on the ID property, what I really want is just the first item the list i.e. [ID=1, Alpha].  One way of achieving this to override Equals() on the Widget class, but this may not always be practical or even possible.  Another option is to supply a custom IEqualityComparer<T>.  To do this I would need to a define a class that implements Equals() and GetHashCode(), the two methods on IEqualityComparer<T> and supply an instance of this class as an additional parameter to Equals() or Intersect().  Unfortunately, I found neither of these practical since I had a number of classes that that I wanted to use with Except() or Intersect() and wanted a more elegant solution.

“Why not just use a lambda expression to express the comparison?”, I thought and came up with the following two extensions:

public static class LinqExtensions
{
    public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, Func<TSource, TSource, bool> comparer)
    {
        return first.Where(x => second.Count(y => comparer(x, y)) == 0);
    } 

    public static IEnumerable<TSource> Intersect<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, Func<TSource, TSource, bool> comparer)
    {
        return first.Where(x => second.Count(y => comparer(x, y)) == 1);
    }
}

Now I can compare on the ID by supplying the comparison logic as a lambda expression:

Console.WriteLine("Except");
first.Except(second, (x, y) => x.ID == y.ID).ToList().ForEach(x => Console.WriteLine("ID=" + x.ID + ", " + x.Name));

Console.WriteLine("Intersect");
first.Intersect(second, (x, y) => x.ID == y.ID).ToList().ForEach(x => Console.WriteLine("ID=" + x.ID + ", " + x.Name));

This gives me the results I want:

Except
ID=1, Alpha
Intersect
ID=2, Beta
ID=3, Gamma

Hope you find them useful!

Standard