Advertisements

GREPgraphing – Beyond 2000

In 2016, I developed a concept of creating bar graphs using GREP styles. Put simply, when a number was typed such as 1423, several different GREP styles would kick in to transform the number into a bar graph. In the above example:

  • if there’s a one for the 1 followed by three digits, make the one character 1000% wide;
  • If there’s a 4 followed by two digits, make the four character 400% wide;
  • If there’s a 2 followed by one digit, make the two character 20% wide;
  • If there’s a 3 as the last character, make the three 3% wide.

To successfully work with any whole number between 1-1999, this technique requires creating 29 different types of GREP styles and character styles. It uses a fixed width font and takes advantage of GREP styles to adjust the width of the numbers to represent them as their appropriate value as a bar graph. I’ve written about this technique in more detail over at InDesignSecrets.

In 2018, I expanded upon this idea and made a script so that anyone wishing to use the technique without typing the 29 character and GREP styles could simply run a script:

Beyond 2000

One catch with this technique is that it stops at 1999 as the character style to represent 2000 can’t be made by creating a 2000% width as the maximum character width is 1000%. However, there is a workaround – create a new character style called 2000, based on the 1000 style, but give it a tracking of 600.

Adjust the GREP graph paragraph style and underneath the 1000% GREPstyle, make a new one using the new 2000% character style that was made and give it the following pattern:

2(?=\d\d\d\b)

To test this, I have two different GREPgraph styles containing the 1000 figure and have put them side by side. In the text frame underneath, if I type 2000 into the text frame with the GREPgraph beyond 2000 style applied to it, it should be the same width, right?

Absolutely. If I make an additional 3000% character style based on the 2000% style but changed its tracking to 1200, and added a GREPstyle to the paragraph style to apply the 3000% character style to the pattern 3(?=\d\d\d\b), this will work too.

From here, a pattern can now be seen: to get to the next 1000 in width, add another 600 to the tracking of that thousand’s character style and add a new GREP style pattern to the GREPgraph style. This will work until the tracking hits its maximum of 10,000.

Doing all this in less GREP steps

As stated earlier, the original technique required 29 GREP styles to create a GREPgraph, but what if I said it was possible to achieve the numbers 1-1999 (actually a few more – 2047) using 12 GREP styles? This can be done too, but requires a technique in Excel, and that is to convert the original base-10 number into a 16-bit binary number. I’d actually described this technique back in 2011, but it was implemented differently and with more complications: this method is far simpler.

First, convert the desired base-10 number to a 16-bit binary number in Excel using the following formula:

=DEC2BIN(A1/256,8)&DEC2BIN(MOD(A1,256),8)

Now that the number is displayed in binary, copy the binary number into InDesign.

The technique basically works the same way as the original GREPgraph technique but has a slightly different implementation. First, the character styles need to be created that will change the widths, but instead of making 1-9, 10-90, 100-900 and 1000, only the character styles 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024 need to be created. For example, the character style 32 will only contain the width of 32%, and this pattern will apply to the other numbers mentioned.

Zero and 1024 are the exceptions. Zero will have a character style featuring a .1pt size, no fill or stroke, and 1% width. 1024 will have a character style of 1000% and a tracking of 14.

This will create a total of 12 character styles.

Now to make the paragraph style. To keep it simple, the appearance of the bar graph will controlled by the paragraph rule (though more advanced methods can be made using combinations of rule above, below, underlines and strikethroughs).

Here is where the magic happens – the GREP styles. Here are the styles and how they are implemented in the GREP style panel of the Paragraph style.

And here is the result:

So what’s happening here?

It’s important to understand how binary numbers are written compared to base-10 numbers. The following site gives a really good explanation, and that’s all that’s happening here – the GREP styles are being applied to the 1s in the binary number, based on their position in the binary number, and applying the appropriate GREP widths.

It can go larger

Just like the regular GREP graph, this too can be expanded to numbers larger than 2000 by creating an additional character style that has an added tracking applied. In this case, to represent the numbers 1-4095, a further character style can be added: 2048.

An advantage of this technique is that instead of creating an additional 9 character/GREP styles for each power of 10 using the base-10 GREP styles, the binary method will require a new style every time the total doubles e.g. 14th GREP style would be 4096, 15th GREP style would be 8192…

The obvious disadvantage with this technique: the numbers to be displayed as bar graphs have to be written out in binary first.

Is this something I would use? Probably not myself, as GREPgraphs are normally enough for my purposes, but I often hear the question “what if you need more than 1999 in a graph” so I felt that it was worth answering the question: It can be done, but it’s a lot of effort to get there.

Advertisements
%d bloggers like this: