Flocc
    Preparing search index...

    Class Heatmap

    A Heatmap can be used to visualize the distribution of Agents across two metrics. While Histograms are useful for showing the distribution of Agents along a single metric (or on multiple metrics using the same scale), a Heatmap 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, the y axis is reversed here — low values are at the bottom and high at the top, whereas on a CanvasRenderer high values are at the bottom and low at the top.

    0.5.8

    Hierarchy

    • AbstractRenderer
      • Heatmap
    Index

    Constructors

    Properties

    Methods

    Constructors

    • 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 Agents
      • to (string = "black") — The color (name, hex value, or RGB) to draw when a cell contains the highest number of Agents
      • x and y can be either:
        • string = "x"/"y" respectively — The name of Agent data to measure along the x/y axis
        • { buckets: number; key: string; min: number; max: number } = { 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 data
      • width (number = 500) — The width, in pixels, of the canvas on which to render
      • height (number = 500) — The height, in pixels, of the canvas on which to render
      • scale (either "relative" or "fixed", defaults to "relative")
        • "relative" — The maximum number of Agents 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 Agents 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'
      });

      Parameters

      Returns Heatmap

    Properties

    environment: Environment

    Points to the Environment that this renderer is tied to. This is automatically set when the renderer is created.

    height: number
    width: number

    Methods

    • 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);

      Parameters

      • el: string | HTMLElement

      Returns void