# test_col_font_01
# column study
# this study is meant to be a programming example, to show 2 ways to change the font color in a column
# in a column, addlabel is used to display text, and plot is used to display a number.
# ----------------------
# halcyonguy
# 21-05-23
# column - test
# display different font colors
# ---------------------
# change the value of a variable, (0 or 1),
# to choose the output method used to change the font color
def use_label = 1;
# set use_label = 1 , to use the addlabel() function to display data,
# with a font color, based on a random number, 1 to 10
#
# set use_label = 0 , to use the plot function to display data,
# with 3 defined colors, and the rest as yellow
# qty of colors
def qty = 9;
# create random numbers, 1 to 10
def c = round((random() * qty) + 1, 0);
# === addlabel =======================
# display test data in a column cell
# a variable in getcolor works with addlabel
addlabel(use_label, c + " font color #" , getcolor(c));
# === plot =======================
plot z = if !use_label then c else double.nan;
# can define several colors, then reference the desired one
z.DefineColor("one", getcolor(4));
z.DefineColor("two", getcolor(5));
z.DefineColor("three", getcolor(6));
z.DefineColor("four", getcolor(7));
z.AssignValueColor(if !use_label and c == 1 then z.color("one")
else if !use_label and c == 2 then z.color("two")
else if !use_label and c == 3 then z.color("three")
else color.yellow);
# make background color black
assignBackgroundColor(Color.black);
# -- code experiments that didn't work
# this causes an error, dynamic value in getcolor, in defineglobalcolor
# DefineGlobalColor ("rnd", getcolor(c));
# plot experiments
# these cause an error, dynamic value in getcolor, in plot commands
# z.setdefaultcolor(getcolor(c));
# z.DefineColor("two", GetColor(c));
#