transforms#
Represent transformations of data to happen on the client (browser) side.
- class CustomJSTransform(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Apply a custom defined transform to data.
Warning
The explicit purpose of this Bokeh Model is to embed raw JavaScript code for a browser to execute. If any part of the code is derived from untrusted user inputs, then you must take appropriate care to sanitize the user input prior to passing to Bokeh.
- args#
A mapping of names to Python objects. In particular those can be bokeh’s models. These objects are made available to the transform’ code snippet as the values of named parameters to the callback.
- func#
A snippet of JavaScript code to transform a single value. The variable
xwill contain the untransformed value and can be expected to be present in the function namespace at render time. The snippet will be into the body of a function and therefore requires a return statement.Example
func = ''' return Math.floor(x) + 0.5 '''
- v_func#
A snippet of JavaScript code to transform an array of values. The variable
xswill contain the untransformed array and can be expected to be present in the function namespace at render time. The snippet will be into the body of a function and therefore requires a return statement.Example
v_func = ''' const new_xs = new Array(xs.length) for(let i = 0; i < xs.length; i++) { new_xs[i] = xs[i] + 0.5 } return new_xs '''
Warning
The vectorized function,
v_func, must return an array of the same length as the inputxsarray.
- class Dodge(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Apply either fixed dodge amount to data.
- range#
When applying
Dodgeto categorical data values, the correspondingFactorRangemust be supplied as therangeproperty.
- value#
The amount to dodge the input data.
- class Interpolator(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Base class for interpolator transforms.
Interpolators return the value of a function which has been evaluated between specified (x, y) pairs of data. As an example, if two control point pairs were provided to the interpolator, a linear interpolaction at a specific value of ‘x’ would result in the value of ‘y’ which existed on the line connecting the two control points.
The control point pairs for the interpolators can be specified through either
A literal sequence of values:
interp = Interpolator(x=[1, 2, 3, 4, 5], y=[2, 5, 10, 12, 16])
or a pair of columns defined in a
ColumnDataSourceobject:
interp = Interpolator(x="year", y="earnings", data=jewlery_prices))
This is the base class and is not intended to end use. Please see the documentation for the final derived classes (
Jitter,LineraInterpolator,StepInterpolator) for more information on their specific methods of interpolation.Note
This is an abstract base class used to help organize the hierarchy of Bokeh model types. It is not useful to instantiate on its own.
- clip#
Determine if the interpolation should clip the result to include only values inside its predefined range. If this is set to False, it will return the most value of the closest point.
- data#
Data which defines the source for the named columns if a string is passed to either the
xoryparameters.
- x#
Independent coordinate denoting the location of a point.
- y#
Dependent coordinate denoting the value of a point at a location.
- class Jitter(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Apply either a uniform or normally sampled random jitter to data.
- distribution#
The random distribution upon which to pull the random scatter
- mean#
The central value for the random sample
- range#
When applying Jitter to Categorical data values, the corresponding
FactorRangemust be supplied as therangeproperty.
- width#
The width (absolute for uniform distribution and sigma for the normal distribution) of the random sample.
- class LinearInterpolator(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Compute a linear interpolation between the control points provided through the
x,y, anddataparameters.
- class StepInterpolator(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Compute a step-wise interpolation between the points provided through the
x,y, anddataparameters.- mode#
Adjust the behavior of the returned value in relation to the control points. The parameter can assume one of three values:
after(default): Assume the y-value associated with the nearest x-value which is less than or equal to the point to transform.before: Assume the y-value associated with the nearest x-value which is greater than the point to transform.center: Assume the y-value associated with the nearest x-value to the point to transform.
- class Transform(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
- Base class for
Transformmodels that represent a computation to be carried out on the client-side.
JavaScript implementations should implement the following methods:
compute(x: number): number { // compute and return the transform of a single value } v_compute(xs: Arrayable<number>): Arrayable<number> { // compute and return the transform of an array of values }
Note
This is an abstract base class used to help organize the hierarchy of Bokeh model types. It is not useful to instantiate on its own.
- Base class for