Open Source Flex Component: TreeMap updated to version 2.1.0

It seems that I’m on a Flex component development streak lately. A couple days ago, I got some inspiration to give a little attention to my TreeMap Flex component. After initially starting on some minor performance enhancements, I kept finding more and more I could do. Several commits later, I realized I was putting together a very solid new release.

Screenshot of Introduction to TreeMap example

Most interesting of this release’s additions are the performance enhancements. I hadn’t expected to improve the performance much more than what I was able to achieve moving from the 1.x archtecture to the 2.x architecture. However, some extra time spent in the profiler, along with some inspiration from a blog post on Flash Player’s dirty rectangle by Seb Lee-Delisle (the problem he overcame wasn’t directly related to what I optimized, but it made me think about improving the way I use certain display list functions) gave me a noticeable speed increase for larger data sets over 500 items.

Another big improvement is a new implementation of the default “Squarify” layout algorithm. The original version of this algorithm, and the one that most people implement in other open source treemap projects, is recursive. As I discovered, with a large enough data provider (between 1100-1200 items), the algorithm can easily cause a stack overflow in Flash Player. I rewrote the algorithm to run in a simpler while loop, so the number of items in the TreeMap’s data provider won’t be a bottleneck anymore. This change has a positive side effect; by removing so many function calls (which have a certain performance overhead), the algorithm ends up running a bit faster.

Those are the most interesting improvements. Others include the addition of properties for separately specifying branch labels and data tips (for instance, branchLabelField takes precedence over labelField), better (and faster) skins for leaf renderers, proper non-interactive behavior when enabled is set to false (I always forget to test that when I build components), a new branchZoom event on TreeMap, more complete API documentation, and a new example named Introduction to TreeMap (pictured above) that combines, streamlines, and replaces a few of the older examples.

Like what you see? Download flextreemap from the project page. The download includes the component SWC, documentation, compiled examples, and the full source code licensed under a widely-usable MIT license. The TreeMap API documentation is also available livedocs-style online, and you can view the examples there too. and if you find any bugs in the component, the documentation, or the examples, please file a bug report. Feature requests are welcome too.

Important note: TreeMap now requires Flex 3.2.0 at the minimum. The leaf renderer is very similar to a button, and I followed some of the conventions the Flex team are using to implement the Marshall Plan as it relates to mouse events and sandboxing. Some of the APIs involved don’t appear in earlier SDKs, so you must use Flex 3.2 or higher starting with TreeMap 2.1.0.

About Josh Tynjala

Josh Tynjala is a frontend developer, open source contributor, bowler hat enthusiast, and karaoke addict. You might be familiar with his project, Feathers UI, an open source user interface library for Starling Framework that is included in the Adobe Gaming SDK.

Discussion

  1. Pingback: Open Source Flex Component: TreeMap | 达达的Blog

  2. jatorre

    Thank you very much!

    I would like to use it slightly different. Instead of displaying a label and a color background on each box I would like to define an image that will cover the area. So the DataProvider would hold a property called imageSrc or something like this.

    What would you propose? Extending your component, modifying it?

    Thanks

  3. Josh Tynjala

    jatorre, that’s certainly possible. You need to create a custom ITreeMapLeafRenderer. It’s very similar to how you would create a custom item renderer on a List or a Tree.

  4. Pingback: evolutioneer.com/blog » Blog Archive » Start 2009 With Some Links

  5. Pingback: Flex Monkey Patches » Blog Archive » Rubbernecker’s Review - Week 22

  6. Gauthier

    Hi,

    I just want to know if is it possible to display landscape images instead of portrait to keep the isometry.

  7. Josh Tynjala

    Gauthier, you will need to modify the layout algorithm if you want to ensure that leaves are always landscape. The default layout algorithm, called “squarify”, tries to make leaves as close to square (1:1 average ratio width to height) as possible. The fact that your example has a “portrait” orientation is coincidental.

  8. Gauthier

    I have some problem to modify your algorithm …
    The class SquarifyLayout contains the function squarify which is private. So I can’t override it. :/

  9. Gaurav Sarin

    Hi,
    I want to push a fade or zoom effect when an user clicks on the icon to open or close a node.

    Can you please give me some tip on how to do that?

  10. Josh Tynjala

    Gaurav, that’s something I want to make a standard feature of the TreeMap component, but I haven’t put any thought into the implementation yet. You might see how the regular Flex Tree implements branch opening to see how you might implement an effect in a similar way for TreeMap.

  11. Jayashree

    Hi,

    I am not able to access the View the examples of TreeMap API.Can you please help me provide the examples details.