Pivot Widget examples

Example heat maps

The following examples, scripted in Groovy, demonstrate the .setColorFormat method and its various implementations.

Each example modifies the same pivot widget created from the StockTrades table:

import com.illumon.iris.console.utils.PivotWidgetBuilder
t=db.t("LearnDeephaven", "StockTrades").where("Date=`2017-08-21`")

Example 1

A = {val -> val < 50000 ? "BLUE" : "GREEN"}

colorFormatA = PivotWidgetBuilder.pivot(t, "USym", "Exchange", "Last")
    .sum().across().down()
    .heatMap().setColorFormat(A)
    .show()

img

Example 2

B = {val -> val < 50000 ? COLOR_BLUE : COLOR_GREEN}
colorFormatB = PivotWidgetBuilder.pivot(t, "USym", "Exchange", "Last")
    .sum().across().down()
.heatMap().setColorFormat(B)
    .show()

img

Example 3

import com.illumon.iris.db.util.DBColorUtil

C = {val -> val < 50000 ? DBColorUtil.VIVID_GREEN : DBColorUtil.VIVID_BLUE}

colorFormatC = PivotWidgetBuilder.pivot(t, "USym", "Exchange", "Last")
    .sum().across().down()
    .heatMap().setColorFormat(C)
    .show()

img

Example 4

import com.illumon.iris.db.util.DBColorUtil

D = {val -> val < 50000 ? DBColorUtil.toLong("BLUE") : DBColorUtil.toLong("GREEN")}

colorFormatD = PivotWidgetBuilder.pivot(t, "USym", "Exchange", "Last")
    .sum().across().down()
    .heatMap().setColorFormat(D)
    .show()

img

Example 5

import com.illumon.iris.db.util.DBColorUtil

a = DBColorUtil.toLong("BLUE")
b = DBColorUtil.toLong("GREEN")

E = {val -> val < 50000 ? a : b}

colorFormatE = PivotWidgetBuilder.pivot(t, "USym", "Exchange", "Last")
    .sum().across().down()
    .heatMap().setColorFormat(E)
    .show()

img

Example 6

import com.illumon.iris.gui.color.Color

F = {val -> val < 50000 ? Color.LAWNGREEN : Color.LIGHTCYAN}

colorFormatF = PivotWidgetBuilder.pivot(t, "USym", "Exchange", "Last")
    .sum().across().down()
    .heatMap().setColorFormat(F)
    .show()

img

Example 7

By default, the minimum and maximum values will apply to all the columns in the Pivot Widget. It is also possible to set the min/max coloring ranges dynamically per column by including multiple setColorFormat arguments within your query.

A = {val -> val < 50000 ? "BLUE" : "GREEN"}
B = {val -> val < 500000 ? "RED" : "YELLOW"}
C = {val -> val < 50000 ? "PINK" : "ORANGE"}

colorFormatG = PivotWidgetBuilder.pivot(t, "USym", "Exchange", "Last")
    .sum().across().down()
    .heatMap().setColorFormat(A)
    .heatMap().setColorFormat(C, "Nyse")
    .heatMap().setColorFormat(B, "Bats","Arca")
    .show()

img

Example 8

To allow heat maps for String data, include the unique() aggregator in your query.

import com.illumon.iris.console.utils.PivotWidgetBuilder
t=db.t("LearnDeephaven", "StockTrades").where("Date=`2017-08-21`")
C = {val -> "INTC".equals(val) ? "BLUE" : "ORANGE"}
D = {val -> !"INTC".equals(val) ? "BLUE" : "ORANGE"}
E = {val -> val.contains('X') ? "RED" : "GREEN"}
colorFormatString = PivotWidgetBuilder.pivot(t.firstBy("USym", "Exchange"), "USym", "Exchange", "Sym")
    .unique()
    .setColorFormat(C)
    .setColorFormat(D, "Nyse", "Nasdaq")
    .setColorFormat(E, "Bats")
    .show()

img