Q:

How to achieve client side computation of data column?

I would like to have the client compute a color column based on a weight and temperature column present at the server side.
Is this possible using a CustomJSTransform?
Here is the figure and the source:
plot = figure()
source = ColumnDataSource(data={'x': [1,2,3], 'y': [5,5,6], 'weight': [1,4,1], 'temperature': [10, -20, -15]})
plot.circle(x='x', y='y', source=source)

As an example, the color column should be computed with this logic:
def compute_color(data):
    if data['weight'] < 4 and data['color'] < 0:
        return 'blue'
    return 'red'

A:

Yes, although the CustomJSTransform is typically used to transform a single column that it is configured for, there is nothing wrong with taking into account any factors you need it to, such as other columns in the CDS:
from bokeh.io import show
from bokeh.models import ColumnDataSource, CustomJSTransform
from bokeh.transform import transform
from bokeh.plotting import figure

plot = figure()

source = ColumnDataSource(data={'x': [1,2,3], 'y': [5,5,6], 'weight': [1,4,1], 'temperature': [10, -20, -15]})

cmap = CustomJSTransform(args=dict(source=source), v_func="""
    const res = new Array(xs.length)
    const weight = source.data.weight
    const temp = source.data.temperature
    for (let i = 0; i < xs.length; i++) {
        if (weight[i] < 4 && temp[i] < 0) {
            res[i] = "red"
        } else {
            res[i] = "blue"
        }
    }
    return res
""")

plot.circle(x='x', y='y', color=transform('x', cmap), source=source, size=20)

show(plot)

