sy-visual-map

Visual Map

Control value-based colors, sizes, and the selected range.

sy-visual-map

Connect a continuous color legend or interval filters to a chart.

Choose a dimension supported by the target. This example connects to Heatmap's value.

Base chart tier: Community. Features such as additional renderers and custom branding have separate entitlement requirements.

InputData description
forThe target chart's ID.
dimensionThe data dimension to read.
typecontinuous or piecewise.
minTogether with max, defines the value range.

Complete implementation example

html
<div id="chart-container" style="width: 100%; min-width: 0;"></div>

<script type="module">
  import { defineCustomElement as define0 } from '@syidax/advanced-pro/components/sy-heatmap.js';
  import { defineCustomElement as define1 } from '@syidax/advanced-pro/components/sy-visual-map.js';
  define0();
  define1();

  // Pro: complete registerLicense at app startup using your issued certificate.
  // The website preview certificate is not for use in customer apps.
  const specs = [
    {
      "tag": "sy-heatmap",
      "id": "chart-target",
      "props": {
        "data": [
          {
            "x": 0,
            "y": 0,
            "value": 10
          },
          {
            "x": 1,
            "y": 0,
            "value": 27
          },
          {
            "x": 2,
            "y": 0,
            "value": 44
          },
          {
            "x": 3,
            "y": 0,
            "value": 61
          },
          {
            "x": 4,
            "y": 0,
            "value": 78
          },
          {
            "x": 5,
            "y": 0,
            "value": 95
          },
          {
            "x": 0,
            "y": 1,
            "value": 22
          },
          {
            "x": 1,
            "y": 1,
            "value": 39
          },
          {
            "x": 2,
            "y": 1,
            "value": 56
          },
          {
            "x": 3,
            "y": 1,
            "value": 73
          },
          {
            "x": 4,
            "y": 1,
            "value": 90
          },
          {
            "x": 5,
            "y": 1,
            "value": 17
          },
          {
            "x": 0,
            "y": 2,
            "value": 34
          },
          {
            "x": 1,
            "y": 2,
            "value": 51
          },
          {
            "x": 2,
            "y": 2,
            "value": 68
          },
          {
            "x": 3,
            "y": 2,
            "value": 85
          },
          {
            "x": 4,
            "y": 2,
            "value": 12
          },
          {
            "x": 5,
            "y": 2,
            "value": 29
          },
          {
            "x": 0,
            "y": 3,
            "value": 46
          },
          {
            "x": 1,
            "y": 3,
            "value": 63
          },
          {
            "x": 2,
            "y": 3,
            "value": 80
          },
          {
            "x": 3,
            "y": 3,
            "value": 97
          },
          {
            "x": 4,
            "y": 3,
            "value": 24
          },
          {
            "x": 5,
            "y": 3,
            "value": 41
          },
          {
            "x": 0,
            "y": 4,
            "value": 58
          },
          {
            "x": 1,
            "y": 4,
            "value": 75
          },
          {
            "x": 2,
            "y": 4,
            "value": 92
          },
          {
            "x": 3,
            "y": 4,
            "value": 19
          },
          {
            "x": 4,
            "y": 4,
            "value": 36
          },
          {
            "x": 5,
            "y": 4,
            "value": 53
          }
        ],
        "height": 280,
        "width": 640
      }
    },
    {
      "id": "example-chart",
      "tag": "sy-visual-map",
      "props": {
        "for": "chart-target",
        "type": "continuous",
        "dimension": "value",
        "min": 0,
        "max": 100,
        "calculable": true,
        "color": ["#eee6ff", "#8263d9", "#34265d"],
        "width": 640,
        "height": 64
      }
    }
  ];
  const container = document.querySelector('#chart-container');
  const elements = specs.map(({ tag, id, props }) => {
    const element = document.createElement(tag);
    element.id = id;
    Object.assign(element, props);
    element.setAttribute('aria-label', 'visual-map example chart');
    return element;
  });
  container.replaceChildren(...elements);
  const chart = elements.at(-1);
  const onEvent = event => {
    console.log('rangeChange', event.detail);
  };
  chart.addEventListener('rangeChange', onEvent);
  const observer = new ResizeObserver(([entry]) => {
    const width = Math.max(160, Math.floor(entry.contentRect.width));
    elements.forEach(element => { element.width = width; });
  });
  observer.observe(container);

  // In an SPA, call this function when the view is disposed.
  function disposeChart() {
    observer.disconnect();
    chart.removeEventListener('rangeChange', onEvent);
    container.replaceChildren();
  }
</script>

Properties

type

continuous or piecewise.

ItemValue
JavaScript propertytype
HTML attributetype
TypeVisualMapType
Default'continuous'
Allowed valuescontinuous, piecewise

min

Together with max, defines the value range.

ItemValue
JavaScript propertymin
HTML attributemin
Typenumber
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

max

Set as an HTML attribute or JavaScript property. type: number.

ItemValue
JavaScript propertymax
HTML attributemax
Typenumber
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

for

The target chart's ID.

ItemValue
JavaScript propertyfor
HTML attributefor
Typestring
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

target

the chart element to colour (the script-set alternative to for).

ItemValue
JavaScript propertytarget
HTML attributePass objects, arrays, and callbacks as JavaScript properties
TypeVisualMapTargetElement | null
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

dimension

The data dimension to read.

ItemValue
JavaScript propertydimension
HTML attributePass objects, arrays, and callbacks as JavaScript properties
TypeVisualMapDimension
Defaultundefined
Literals in the typex, y, value, z, index

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

sizeRange

visualMap → size: the mark radius (px) at the low / high end of the map ("4,16" as an attribute); the legend shows size ticks.

ItemValue
JavaScript propertysizeRange
HTML attributePass objects, arrays, and callbacks as JavaScript properties
Typereadonly [number, number] | string
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

sizeDimension

the dimension the size reads (default: dimension).

ItemValue
JavaScript propertysizeDimension
HTML attributePass objects, arrays, and callbacks as JavaScript properties
TypeVisualMapDimension
Defaultundefined
Literals in the typex, y, value, z, index

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

outOfRangeSize

the radius of out-of-range values (default: the low end of sizeRange).

ItemValue
JavaScript propertyoutOfRangeSize
HTML attributeout-of-range-size
Typenumber
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

pieces

Piecewise: explicit pieces ([{ min, max, label, color }] or [{ value }]; a JSON string as an attribute). Wins over categories / splitNumber.

ItemValue
JavaScript propertypieces
HTML attributePass objects, arrays, and callbacks as JavaScript properties
TypeReadonlyArray<VisualMapPieceInput> | string
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

splitNumber

Piecewise: equal intervals over [min, max] when no pieces / categories are given (default 5).

ItemValue
JavaScript propertysplitNumber
HTML attributesplit-number
Typenumber
Default5

categories

Piecewise: discrete values, one piece each (a comma list as an attribute).

ItemValue
JavaScript propertycategories
HTML attributePass objects, arrays, and callbacks as JavaScript properties
TypeReadonlyArray<string | number> | string
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

selectedMode

Piecewise: 'multiple' toggles pieces independently, 'single' keeps one piece selected.

ItemValue
JavaScript propertyselectedMode
HTML attributeselected-mode
TypeVisualMapSelectedMode
Default'multiple'
Allowed valuesmultiple, single

selected

Piecewise: the initial / controlled selection (null = every piece); changing it reports selectionChanged with source 'api'.

ItemValue
JavaScript propertyselected
HTML attributePass objects, arrays, and callbacks as JavaScript properties
TypeReadonlyArray<boolean> | null
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

itemWidth

Piecewise: the swatch size of a piece (ECharts itemWidth / itemHeight).

ItemValue
JavaScript propertyitemWidth
HTML attributeitem-width
Typenumber
Default20

itemHeight

Set as an HTML attribute or JavaScript property. type: number.

ItemValue
JavaScript propertyitemHeight
HTML attributeitem-height
Typenumber
Default14

color

The ramp: a scheme name (viridis, blues, rdbu, …), a comma list (#eff6ff,#1d4ed8), a colour array, or [t, colour] stops.

ItemValue
JavaScript propertycolor
HTML attributePass objects, arrays, and callbacks as JavaScript properties
TypeVisualMapColorInput
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

outOfRangeColor

The colour of values outside the selected range (and of non-finite values).

ItemValue
JavaScript propertyoutOfRangeColor
HTML attributeout-of-range-color
Typestring
Default'#d1d5db'

orientation

'horizontal' runs min → max left to right, 'vertical' bottom to top.

ItemValue
JavaScript propertyorientation
HTML attributeorientation
TypeDataZoomOrientation
Default'horizontal'
Allowed valuesvertical, horizontal

width

Chart width in pixels. If the container width changes, update width from a ResizeObserver.

ItemValue
JavaScript propertywidth
HTML attributewidth
Typenumber
Default320

height

Chart height in pixels. Allow space for axes, titles, and the legend.

ItemValue
JavaScript propertyheight
HTML attributeheight
Typenumber
Default28

calculable

Show the two range handles: the selected range can be dragged, keyed and set from script.

ItemValue
JavaScript propertycalculable
HTML attributecalculable
Typeboolean
Defaultfalse

range

The selected range (null / unset = the whole domain); changing it reports rangeChange with source 'api'.

ItemValue
JavaScript propertyrange
HTML attributePass objects, arrays, and callbacks as JavaScript properties
TypeVisualMapRange | readonly [number, number] | null
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

precision

Fixed decimals for the labels (unset = up to two, trimmed).

ItemValue
JavaScript propertyprecision
HTML attributeprecision
Typenumber
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

format

Label formatter (a property — functions cannot be attributes).

ItemValue
JavaScript propertyformat
HTML attributePass objects, arrays, and callbacks as JavaScript properties
Type(value: number) => string
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

text

End captions instead of the numbers: "High,Low" (max end first — ECharts text).

ItemValue
JavaScript propertytext
HTML attributetext
Typestring
Defaultundefined

undefined means this property was not explicitly set. The effective value may depend on the chart type and other settings.

showLabels

Show the end labels, and the handle labels while a range is selected.

ItemValue
JavaScript propertyshowLabels
HTML attributeshow-labels
Typeboolean
Defaulttrue

stepFraction

Fraction of the selected range one arrow key moves (default 0.1).

ItemValue
JavaScript propertystepFraction
HTML attributestep-fraction
Typenumber
Default0.1

minRangePx

The narrowest selectable range, in track pixels (default 8).

ItemValue
JavaScript propertyminRangePx
HTML attributemin-range-px
Typenumber
Default8

realtime

Report the frames of a drag (live: true); off = only the release reports.

ItemValue
JavaScript propertyrealtime
HTML attributerealtime
Typeboolean
Defaulttrue

disabled

Set as an HTML attribute or JavaScript property. type: boolean.

ItemValue
JavaScript propertydisabled
HTML attributedisabled
Typeboolean
Defaultfalse

Events

rangeChange

Every range the control shows: a handle drag / key ('control', with live frames), setRange or the range prop ('api').

Event name: rangeChange. Names are case-sensitive. Read the payload from detail on CustomEvent<VisualMapRangeChangeEventDetail>.

javascript
chart.addEventListener('rangeChange', event => {
  console.log(event.detail); // VisualMapRangeChangeEventDetail
});

selectionChanged

a piecewise map's selection changed (a piece toggled: 'control'; setSelected / the selected prop: 'api').

Event name: selectionChanged. Names are case-sensitive. Read the payload from detail on CustomEvent<VisualMapSelectionChangeEventDetail>.

javascript
chart.addEventListener('selectionChanged', event => {
  console.log(event.detail); // VisualMapSelectionChangeEventDetail
});

Methods

refresh

Re-read the bound chart's extent (while min / max are unset) and push the binding; the control also does this on the chart's rendered.

typescript
refresh(): Promise<void>

Return type: Promise<void>. Call the method after element registration and await its Promise result.

setRange

Select a range from script (null = the whole domain); reports rangeChange with source 'api' when it changed.

typescript
setRange(range: VisualMapRange | readonly [number, number] | null): Promise<VisualMapRange | null>
ArgumentsTypeRequired
rangeVisualMapRange | readonly [number, number] | nullRequired

Return type: Promise<VisualMapRange | null>. Call the method after element registration and await its Promise result.

getRange

The resolved range.

typescript
getRange(): Promise<VisualMapRange | null>

Return type: Promise<VisualMapRange | null>. Call the method after element registration and await its Promise result.

setSelected

piecewise: select pieces from script (null = every piece); reports selectionChanged with source 'api'.

typescript
setSelected(selected: ReadonlyArray<boolean> | null): Promise<boolean[] | null>
ArgumentsTypeRequired
selectedReadonlyArray<boolean> | nullRequired

Return type: Promise<boolean[] | null>. Call the method after element registration and await its Promise result.

getSelected

piecewise: the per-piece selection (null = every piece).

typescript
getSelected(): Promise<boolean[] | null>

Return type: Promise<boolean[] | null>. Call the method after element registration and await its Promise result.

togglePiece

piecewise: toggle one piece the way a click does (reports source 'api').

typescript
togglePiece(index: number): Promise<boolean[] | null>
ArgumentsTypeRequired
indexnumberRequired

Return type: Promise<boolean[] | null>. Call the method after element registration and await its Promise result.

getSpec

The resolved spec plus the selection: continuous → domain, stops, space, out-of-range colour, calculable, precision + range; piecewise → the pieces + selected.

typescript
getSpec(): Promise<VisualMapSnapshot>

Return type: Promise<VisualMapSnapshot>. Call the method after element registration and await its Promise result.

colorAt

The colour of a value on this map: the ramp / piece colour inside the selection, outOfRangeColor outside it.

typescript
colorAt(value: number | string): Promise<string>
ArgumentsTypeRequired
valuenumber | stringRequired

Return type: Promise<string>. Call the method after element registration and await its Promise result.