GoJS API
/ to search
    Preparing search index...

    Class HeatMap

    This is an extension and not part of the main GoJS library. Note that the API for this class may change at any time. If you intend to use an extension in production, you should copy the code to your own source directory. See the Extensions intro page for more information.

    A class for drawing a heat map based on the "temperatures" of Parts.

    This class adds a heat map image in the "ViewportForeground" Layer that is dynamically computed as the user scrolls or zooms or when a transaction/undo/redo is finished.

    It also has a method, renderImageData, that renders a heat map for a given area of the document, not just for the viewport, returning an ImageData.

    Index

    Constructors

    • Construct a HeatMap for a Diagram, optionally setting some properties.

      Parameters

      Returns HeatMap

    Accessors

    • get chamferSize(): number

      Gets or sets the size of the chamfer neighborhood used when the metric is HeatMapMetric.Euclidean. A value of 3 sweeps a 3x3 neighborhood, approximating Euclidean distance to within about 8%, so large halos look subtly octagonal. A value of 5 also sweeps the knight's-move neighbors of a 5x5 neighborhood, approximating Euclidean distance to within about 2%, so halos look round, at roughly double the rendering cost. This has no effect when the metric is HeatMapMetric.Manhattan, which is computed exactly.

      The default value is 3.

      Returns number

    • get colors(): number[][]

      Returns number[][]

    • get isInForeground(): boolean

      Gets or sets whether the heat map image is drawn in front of all Parts, in the "ViewportForeground" Layer, or behind them, in the "ViewportBackground" Layer.

      The default value is true.

      Returns boolean

    • get metric(): HeatMapMetric

      Gets or sets the distance metric by which heat spreads outward from each Part. HeatMapMetric.Manhattan produces diamond-shaped halos; HeatMapMetric.Euclidean produces approximately circular ones.

      The default value is HeatMapMetric.Manhattan.

      Returns HeatMapMetric

    • get spreadUnits(): HeatMapSpreadUnits

      Gets or sets the coordinate system in which heat spread distances are measured. HeatMapSpreadUnits.Viewport spreads one canvas pixel per colors entry, so halos keep the same size on screen regardless of zoom. HeatMapSpreadUnits.Document spreads one document unit per colors entry, so halos scale together with Parts as the user zooms.

      The default value is HeatMapSpreadUnits.Viewport.

      Returns HeatMapSpreadUnits

    Methods

    • Override this method to customize the computation of the starting index in the colors Array given the fraction computed by normalizeTemperature. The default behavior is a simple linear interpolation. The value must be a valid index into the colors Array.

      Parameters

      • frac: number

        a number between zero and one, inclusive

      Returns number

      an index into colors

    • Override this method to customize getting the value for how "hot" the given Part is. Typically this is overridden to return some numeric property of the Part.data. By default it returns one, the maximum, assuming the normalizeTemperature method does not scale the value.

      Parameters

      Returns number

      a number indicating the Part's temperature, where smaller values are cooler.

    • Override this method to shift and scale the given temperature to get a fraction between zero and one, inclusive. A value of zero indicates that the given Part not participate in the heat map. Values between zero and one select the starting color from the colors Array -- higher values get more colors. By default it just returns the given value, making sure the value is between zero and one.

      Parameters

      • temp: number

      Returns number

      a fraction between zero and one, inclusive

    • Return an ImageData of the given SIZE in pixels for the given AREA in document coordinates.

      Parameters

      • area: Rect

        a Rect in document coordinates

      • size: Size

        a Size in device-independent-pixel/viewport coordinates

      Returns ImageData | null

      ImageData or null

    • Update the heatMapPart's raster image for the viewport.

      Returns void