Fusebox XML Flowchart Generator

About a week ago someone posted on the Fusebox mailing list looking for a way to generate flowcharts from his Fusebox XML files.  Adalon was suggested, but it didn't do quite what he was looking for.  So I sunk some of my spare time into building such a tool, and even managed to refrain from using Groovy and kept it all CFML.  All the layout stuff is custom, and the drawing is all via the CF8 image functions.  The imageTranslateDrawingAxis function, in particular, was of great utility, allowing me to do all my drawing in local space, rather than absolute space.  This means that every box starts at (0, 0), regardless of where it eventually ends up on the chart, so the drawing of each element is totally encapsulated on it's own coordinate space.

It's easiest to show with an example, so consider this contrived circuit.xml:

chome<circuit>

  <fuseaction name="home">
    <xfa name="page" value="page" />
    <if condition="structKeyExists(attributes, 'name')">
      <true>
        <loop collection="attributes" item="i">
          <set name="m" value="#i#" />
        </loop>
        <set name="message" value="Hello, strange unknown person!" />
      </true>
      <false>
        <set name="message" value="Hello, #name#!" />
        <relocate />
        <xfa name="exit" />
      </false>
    </if>
    <include template="dsp_home" contentvariable="bodyContent" />
    <do action="lay_default" />
  </fuseaction>

  <fuseaction name="page">
    <include template="dsp_page" contentvariable="bodyContent" />
    <do action="lay_default" />
  </fuseaction>

  <fuseaction name="lay_default">
    <if condition="structKeyExists(attributes, 'showNav')">
      <true>
        <do action="nav" contentvariable="nav" />
      </true>
      <false>
        <loop>
          <set name="message" value="Hello, strange unknown person!" />
          <do action="nav" contentvariable="nav" />
        </loop>
      </false>
    </if>
    <include template="lay_default" />
  </fuseaction>

  <fuseaction name="nav">
    <xfa name="home" value="home" />
    <xfa name="page" value="page" />
    <include template="dsp_nav" />
  </fuseaction>

</circuit>

cnavYes, I understand that it wouldn't actually execute in real life (there are a number of missing attributes), but that's not the point.  The generated flowcharts for the 'home' and 'nav' fuseactions are floating to the right. You can click the 'home' one to view it full size.

The UI is pretty simple, you enter the path to either a single circuit.xml file (as above), or your fusebox.xml file and hit 'Go'.  Then you can pick from the list of available fuseactions to act as your entry point, choose whether you'd like to include global pre/postprocess actions and pre/postfuseaction on the flowchart, and it'll draw it all out for you as a nice little PNG.

If you turn on the implicit fuseactions the charts can get pretty large pretty fast, but even generating some pretty gnarly charts for a sizeable app we have at Mentor didn't take more than a second or two.

If you'd just like to render a single circuit's stuff, you can point it directly at the circuit file, and you'll get an error box for any <do> verbs that point outside the circuit, so you'll still get a full chart, with the external dependencies called out explicitly.

I've made the code available in a zip archive if you'd like to run it yourself (or just poke around).  Just unzip it somewhere, and hit index.cfm in the browser.  The example circuit.xml above is included, so you can regenerate the demo charts I've shown here, or point it at your own Fusebox app and get a look at what you're doing.

The code itself is hardly an example of eloquent design, since this was just a little "screwing around" project.  The drawing stuff is pretty devoid of magic numbers, but I made no attempt to fully/properly decompose my types or to really enforce DRY throughout.  It is what it is: something to keep me from getting bored that I though might be of interest to others.

11 responses to “Fusebox XML Flowchart Generator”

  1. marc esher

    barney, you've done it again. this is incredibly cool!

    but having not loooked at fusebox xml before, I am, um, aghast. it really looks like that? like…, seriously, that is how controllers are done in fusebox? wow.

    One other question: you refrained from doing it in groovy, but I'm wondering: if you were to do it in groovy, would it have been as easy as doing it with CF's image functions?

  2. John Allen

    That is pretty darn sharp.

  3. imageTranslateDrawingAxis is Your Friend at BarneyBlog

    [...] Contact « Fusebox XML Flowchart Generator [...]

  4. Dan O'Keefe

    Barney,

    Very cool tool, especially when you start working with an app you are not familiar with. Whats your thoughts on possibly displaying the condition for the ?

    Dan

  5. Dan O'Keefe

    I see what you mean. Yeah, that sounds pretty hairy to make all of those changes to try and accommodate the condition. Actually, if there was a way to bump it up 1 space, the text outputted would be above the horizontal lines coming off of the decision symbol.

  6. Dan O'Keefe

    This is amazing. I removed the " + getTextHeight()" but in place of that I added " -15″ which lifts it up even higher and makes it more readable.
    Thanks much!

  7. Panos

    Thank you very much!
    Really good work and I really appreciate it! Helped me a lot with my new projects in order to understand the flow

    I have one issue though..
    If i give the fusebox.xml and I check Pre/Post Fuseactions i get the following error
    Element VERBS is undefined in VERB.

    The error occurred in /flowgen/inline.cfc: line 13