Skip to content
Analytica > Blogs > Using computed cell formatting to create a color map

Using computed cell formatting to create a color map

In this post, I’m going to highlight some new cell formatting options. This is a new feature I’ve had fun experimenting with, and I look forward to seeing how our user community develops new and creative ways to use this functionality.

When I first learned about Computed cell formats, one of the things I wanted to generate was a color palette. Building this model let me both explore how colors were calculated and gave me a local tool to develop color swatches (for example, to use for color gradients for a chart or map). The model is simple, generating a sequence values for red, green, and blue and using those values to calculate the cell as well as the cell fill color. Here’s the result!

You can download this model directly or via the example models page of the Analytica Wiki. All of this is enabled by a new node attribute available in the Cell Format Expression. You can see this new attribute in the Object window.

The code for the Cell Format Expression is as follows:

CellFormats(
   { Fill color calculation based on red, green, blue input value }
   CellFill(color: (R*2^16 + G*2^8 + B), alpha: alpha1),

   { Font color is black or white to contrast against light or dark fill color }
   IF ( R*0.299 + G*0.587 + B*0.114 ) < Luminance_threshold
   THEN CellFont( color: 'White' )
   ELSE CellFont( color: 'Black' ),

  { Increase cell font size from the default }
  CellFont( size:14 )
  )

First, a note about how colors are characterized and “calculated”. RGB color triplets are usually expressed in one of two ways: with each of the red, green, and blue values between 0 and 255 (R,G,B); or, in hexadecimal notation resulting from the calculation R*2^16 + G*2^8 + B. Hex notation is common in web applications, whereas the base ten RGB triplet is something you see in Photoshop or Microsoft Office products.

In my model, I set up one variable for each of red, green, and blue, and defined each of these as a sequence between 0 and 255 increasing by a Step size variable. This has a User input node so I can adjust how many rows/columns exist in my color map. To make sure I always had the edge cases, I made sure that sequence ended in 255 regardless of step size by concatenating that value to the list if it was not a result of the Sequence function. The hex formula defines the node and the cell fill. There is an additional alpha channel, which controls the Transparency of the color, for which I’ve also added a user input node.

Color map influence diagram.

The text displayed in the cell is simply the result of this calculation, but I’ve set the output to display in hexadecimal number format using the Cell format dialog, new to Analytica 5.0. From the results image above, we see that 135 in base 10 must be 87 in base 16. I wanted to be sure this text could be read regardless of how I set up or view my color map, so, I used another characteristic that can be calculated based on the contributions from each of red, green, and blue: the luminance. The greater the luminance, the less contrast there will be between white text and the cell fill color, a case where we’d prefer a dark (low luminance) font color. Based on the monitor I used to build this model, an acceptable Luminance threshold was 142. You’ll see that I also set the font size to 14 to enhance readability.

I encourage you to play around in the model, and let me know what you think! What are some applications you see for this color map? What cell formatting and computed cell formatting applications are you interested in using in your own models?

Share now 

See also

air conditioner outdoor unit

Building electrification: heat pump technology

Lumina set out to build a useful tool to assess the benefits of heat pumps. Learn more about heat pumps and their impact.
More...

Heat pumps 101

Heat and cool your home while saving energy and reducing emissions by adopting heat pump technology. Learn more about this transition and heat pumps by watching this webinar.
More...
Heatpump

Navigating the heat pump landscape

Fort Collins, Lumina, and Apex Analytics have created a tool to help reduce greenhouse gas emissions by optimizing building electrification programs.
More...

US gas leaks much larger than previously estimated

A new Stanford-led study on natural gas leak rates from oil and gas activity across a large fraction of the US are about 3x more than previous government estimates. The
More...

See also

Building electrification: heat pump technology

Lumina set out to build a useful tool to assess the benefits of heat pumps. Learn more about heat pumps and their impact.

More…

Decision making when there is little historic precedent

Learn how to make decisions and strategic plans in uncertain situations, where historical data is not available. See how to model this in Analytica with clarity and insight.

More…

Does GPT-4 pass the Turing test?

In 1950, Alan Turing proposed “The Imitation Game”, today known as the Turing test, as a hypothetical way of measuring whether a computer can think [1]. It stakes out the...

More…

What is Analytica software?

Analytica is a decision analysis tool that helps you generate clearer and more justified results through modeling.

More…

Download the free edition of Analytica

The free version of Analytica lets you create and edit models with up to 101 variables, which is pretty substantial since each variable can be a multidimensional array. It also lets you run larger modes in ‘browse mode.’ Learn more about the free edition.

While Analytica doesn’t run on macOS, it does work with Parallels or VMWare through Windows.


    Analytica Cubes Pattern

    Download the free edition of Analytica

    The free version of Analytica lets you create and edit models with up to 101 variables, which is pretty substantial since each variable can be a multidimensional array. It also lets you run larger modes in ‘browse mode.’ Learn more about the free edition.

    While Analytica doesn’t run on macOS, it does work with Parallels or VMWare through Windows.


      Analytica Cubes Pattern

      Download the free edition of Analytica

      The free version of Analytica lets you create and edit models with up to 101 variables, which is pretty substantial since each variable can be a multidimensional array. It also lets you run larger modes in ‘browse mode.’ Learn more about the free edition.

      While Analytica doesn’t run on macOS, it does work with Parallels or VMWare through Windows.


        Analytica Cubes Pattern

        Download the free edition of Analytica

        The free version of Analytica lets you create and edit models with up to 101 variables, which is pretty substantial since each variable can be a multidimensional array. It also lets you run larger modes in ‘browse mode.’ Learn more about the free edition.

        While Analytica doesn’t run on macOS, it does work with Parallels or VMWare through Windows.


          Analytica Cubes Pattern

          Download the free edition of Analytica

          The free version of Analytica lets you create and edit models with up to 101 variables, which is pretty substantial since each variable can be a multidimensional array. It also lets you run larger modes in ‘browse mode.’ Learn more about the free edition.

          While Analytica doesn’t run on macOS, it does work with Parallels or VMWare through Windows.


            Analytica Cubes Pattern

            Download the free edition of Analytica

            The free version of Analytica lets you create and edit models with up to 101 variables, which is pretty substantial since each variable can be a multidimensional array. It also lets you run larger modes in ‘browse mode.’ Learn more about the free edition.

            While Analytica doesn’t run on macOS, it does work with Parallels or VMWare through Windows.


              Analytica Cubes Pattern