Showing posts with label diagrams. Show all posts
Showing posts with label diagrams. Show all posts

Monday, August 24, 2009

Image scaling and GCD (greatest common divisor)

Whilst embedding an image in a wiki page I found it was too big (wide) and therefore caused lots of layout issues. The obvious solution to this was to scale the image (by editing the HTML and adding a style attribute style="width:80%;") unfortunately this caused the image (a diagram) to be unreadable - due to image artefacts.

After looking at the image properties, I saw the cause of problem - its dimensions (865 x 596). As there is no common divisor of these two numbers there is now way to scale it down without one of the dimensions being rounded - for example at a scale of ½ the dimensions become (432.5 x 298). And you can't have half a pixel...

So I suspect (intuitively rather than by proof) that images scale best if they have a GCD (greatest common divisor), a quick port of the binary GCD from wikipedia in C#:

        static uint gcd(uint u, uint v)
        {
            int shift;

            /* GCD(0,x) := x */
            if (u == 0 || v == 0)
                return u | v;

            /* Let shift := lg K, where K is the greatest power of 2
               dividing both u and v. */
            for (shift = 0; ((u | v) & 1) == 0; ++shift)
            {
                u >>= 1;
                v >>= 1;
            }

            while ((u & 1) == 0)
                u >>= 1;

            /* From here on, u is always odd. */
            do
            {
                while ((v & 1) == 0)  /* Loop X */
                    v >>= 1;

                /* Now u and v are both odd, so diff(u, v) is even.
                   Let u = min(u, v), v = diff(u, v)/2. */
                if (u < v)
                {
                    v -= u;
                }
                else
                {
                    uint diff = u - v;
                    u = v;
                    v = diff;
                }
                v >>= 1;
            } while (v != 0);

            return u << shift;
        }
Port of code from wikipedia

Tuesday, June 30, 2009

Gregor-grams and Chappell-grams

I've been doing a lot of work with an Enterprise Services Bus (ESB), and found Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions a very useful book - especially the diagram techniques "Gregor-grams".


These are useful for diagramming any message based system - I'm very keen on UML but it does not really address MOM systems in the large. Below is a Gregor-gram showing how a Sales Order Process might integrate SFdC, Zuora (Z-Billing) and Oracle Financials (a pattern that most businesses will need):

This diagram allows us to show how message move through the system and are transformed. There's also another good book is Chappell's Enterprise Service Bus which is focused on the ESB implementation of MOM (no surprise given the name!).

It has another diagramming techique, which at the moment I'm using for creating a static view of the ESB:
This is closer to a static UML view (deployment maybe), but it also allows you to express how the components connecting to an ESB exchange messages (HTTP/WCF etc). I feel that Gregor-grams are better for the dynamic view. The book never names these diagrams, so 've taken to calling them "Chappell-grams" given that they are meant to be an evolution of Gregor-grams.

Using Gregor-grams and Chappell-grams together allows us to document how a system works from both a dynamic and static view.