The first parameter must be the Environment
that this
Heatmap
will render.
The second parameter specifies options, which can include:
from
(string = "white"
) — The color (name, hex value, or RGB) to draw when a cell contains 0
Agent
sto
(string = "black"
) — The color (name, hex value, or RGB) to draw when a cell contains the highest number of Agent
sx
and y
can be either:"x"
/"y"
respectively — The name of Agent
data to measure along the x
/y
axis{ buckets: 10, key: 'x' | 'y', min: 0, max: 1 }
— Include the number of buckets to divide the range min → max
into, along with the name of Agent
datawidth
(number = 500
) — The width, in pixels, of the canvas on which to renderheight
(number = 500
) — The height, in pixels, of the canvas on which to renderscale
(either "relative"
or "fixed"
, defaults to "relative"
)"relative"
— The maximum number of Agent
s in any single cell is automatically used as the highest value in the scale. This updates over time based on Agent
distribution."fixed"
— You supply the number to use as the maximum value (see max
below).max
(optional, number) — If you use scale = "fixed"
, then setting a max
will cause cells with that number (or higher) of Agent
s to be drawn using the to
color.// plots the correlation between age of agents (on the x-axis)
// vs. their wealth (on the y-axis)
const heatmap = new Heatmap(environment, {
x: 'age',
y: 'wealth'
});
Points to the Environment
that this
renderer is tied to. This is automatically set when the
renderer is created.
Mount this renderer to a DOM element. Pass either a string representing a CSS selector matching the element or the element itself.
// mounts the renderer to the element with the ID `container`
renderer.mount('#container');
// mounts the renderer to the element itself
const container = document.getElementById('container');
renderer.mount(container);
Generated using TypeDoc
A
Heatmap
can be used to visualize the distribution ofAgent
s across two metrics. WhileHistogram
s are useful for showing the distribution ofAgent
s along a single metric (or on multiple metrics using the same scale), aHeatmap
can show how two metrics relate to one another — correlation, inverse correlation, in a nonlinear manner, randomly (no correlation), etc.Note above that, although the output appears similar to what a
CanvasRenderer
might output, they
axis is reversed here — low values are at the bottom and high at the top, whereas on aCanvasRenderer
high values are at the bottom and low at the top.0.5.8