--- description: "ScatterplotLayer renders circles at given coordinates with data-driven radius, fill and stroke." --- # ScatterplotLayer ![webgpu](https://img.shields.io/badge/webgpu-supported-blue.svg?style=flat-square) import {ScatterplotLayerDemo} from '@site/src/doc-demos/layers'; The `ScatterplotLayer` renders circles at given coordinates. import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; ```js import {Deck} from '@deck.gl/core'; import {ScatterplotLayer} from '@deck.gl/layers'; const layer = new ScatterplotLayer({ id: 'ScatterplotLayer', data: 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/bart-stations.json', stroked: true, getPosition: d => d.coordinates, getRadius: d => Math.sqrt(d.exits), getFillColor: [255, 140, 0], getLineColor: [0, 0, 0], getLineWidth: 10, radiusScale: 6, pickable: true }); new Deck({ initialViewState: { longitude: -122.4, latitude: 37.74, zoom: 11 }, controller: true, getTooltip: ({object}) => object && object.name, layers: [layer] }); ``` ```ts import {Deck, PickingInfo} from '@deck.gl/core'; import {ScatterplotLayer} from '@deck.gl/layers'; type BartStation = { name: string; entries: number; exits: number; coordinates: [longitude: number, latitude: number]; }; const layer = new ScatterplotLayer({ id: 'ScatterplotLayer', data: 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/bart-stations.json', stroked: true, getPosition: (d: BartStation) => d.coordinates, getRadius: (d: BartStation) => Math.sqrt(d.exits), getFillColor: [255, 140, 0], getLineColor: [0, 0, 0], getLineWidth: 10, radiusScale: 6, pickable: true }); new Deck({ initialViewState: { longitude: -122.4, latitude: 37.74, zoom: 11 }, controller: true, getTooltip: ({object}: PickingInfo) => object && object.name, layers: [layer] }); ``` ```tsx import React from 'react'; import {DeckGL} from '@deck.gl/react'; import {ScatterplotLayer} from '@deck.gl/layers'; import type {PickingInfo} from '@deck.gl/core'; type BartStation = { name: string; entries: number; exits: number; coordinates: [longitude: number, latitude: number]; }; function App() { const layer = new ScatterplotLayer({ id: 'ScatterplotLayer', data: 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/bart-stations.json', stroked: true, getPosition: (d: BartStation) => d.coordinates, getRadius: (d: BartStation) => Math.sqrt(d.exits), getFillColor: [255, 140, 0], getLineColor: [0, 0, 0], getLineWidth: 10, radiusScale: 6, pickable: true }); return ) => object && object.name} layers={[layer]} />; } ``` ```js import {Field, FixedSizeList, Float32, vectorFromArray} from 'apache-arrow'; import {ScatterplotLayer} from '@deck.gl/layers'; const positionType = new FixedSizeList(2, new Field('value', new Float32())); const positions = vectorFromArray([[-122.4, 37.74]], positionType); const layer = new ScatterplotLayer({ getPosition: positions, getRadius: vectorFromArray([100], new Float32()) }); ``` See [Using with Arrow](../../developer-guide/using-with-arrow.md) for column layouts and mixed inputs. ## Installation To install the dependencies from NPM: ```bash npm install deck.gl # or npm install @deck.gl/core @deck.gl/layers ``` ```ts import {ScatterplotLayer} from '@deck.gl/layers'; import type {ScatterplotLayerProps} from '@deck.gl/layers'; new ScatterplotLayer(...props: ScatterplotLayerProps[]); ``` To use pre-bundled scripts: ```html ``` ```js new deck.ScatterplotLayer({}); ``` ## Properties Inherits from all [Base Layer](../core/layer.md) properties. ### Render Options #### `radiusUnits` (string, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#radiusunits} * Default: `'meters'` The units of the radius, one of `'meters'`, `'common'`, and `'pixels'`. See [unit system](../../developer-guide/coordinate-systems.md#supported-units). #### `radiusScale` (number, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#radiusscale} * Default: `1` A global radius multiplier for all points. #### `lineWidthUnits` (string, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#linewidthunits} * Default: `'meters'` The units of the line width, one of `'meters'`, `'common'`, and `'pixels'`. See [unit system](../../developer-guide/coordinate-systems.md#supported-units). #### `lineWidthScale` (number, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#linewidthscale} * Default: `1` A global line width multiplier for all points. #### `stroked` (boolean, optional) {#stroked} * Default: `false` Draw the outline of points. #### `filled` (boolean, optional) {#filled} * Default: `true` Draw the filled area of points. #### `radiusMinPixels` (number, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#radiusminpixels} * Default: `0` The minimum radius in pixels. This prop can be used to prevent the circle from getting too small when zoomed out. #### `radiusMaxPixels` (number, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#radiusmaxpixels} * Default: `Number.MAX_SAFE_INTEGER` The maximum radius in pixels. This prop can be used to prevent the circle from getting too big when zoomed in. #### `lineWidthMinPixels` (number, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#linewidthminpixels} * Default: `0` The minimum line width in pixels. This prop can be used to prevent the stroke from getting too thin when zoomed out. #### `lineWidthMaxPixels` (number, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#linewidthmaxpixels} * Default: `Number.MAX_SAFE_INTEGER` The maximum line width in pixels. This prop can be used to prevent the path from getting too thick when zoomed in. #### `billboard` (boolean, optional) {#billboard} - Default: `false` If `true`, rendered circles always face the camera. If `false` circles face up (i.e. are parallel with the ground plane). #### `antialiasing` (boolean, optional) {#antialiasing} - Default: `true` If `true`, circles are rendered with smoothed edges. If `false`, circles are rendered with rough edges. Antialiasing can cause artifacts on edges of overlapping circles. Also, antialiasing isn't supported in FirstPersonView. ### Data Accessors Arrow inputs follow the shared [column requirements and limitations](../../developer-guide/using-with-arrow.md#limitations). When extensions are active, Arrow and SQL accessors use the same row-based attribute path as callbacks. If you supply Arrow columns without data rows, the column length supplies the instance count and callbacks can use the row index. #### `getPosition` (constant | Accessor | arrow.Vector, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#getposition} * Default: `object => object.position` Method called to retrieve the position of each object. An Arrow vector supplies one value per object. See [position columns](../../developer-guide/using-with-arrow.md#positions-and-other-vectors) for requirements. #### `getRadius` (constant | Accessor | arrow.Vector, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#getradius} * Default: `1` The radius of each object, in units specified by `radiusUnits` (default meters). * If a number is provided, it is used as the radius for all objects. * If a function is provided, it is called on each object to retrieve its radius. An Arrow vector supplies one value per object. See [scalar columns](../../developer-guide/using-with-arrow.md#scalars) for requirements. #### `getColor` ([Accessor<Color>](../../developer-guide/using-layers.md#accessors), optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#getcolor} * Default: `[0, 0, 0, 255]` The rgba color is in the format of `[r, g, b, [a]]`. Each channel is a number between 0-255 and `a` is 255 if not supplied. * If an array is provided, it is used as the color for all objects. * If a function is provided, it is called on each object to retrieve its color. This prop supplies the fallback for `getLineColor` and `getFillColor`. #### `getFillColor` (constant | Accessor | arrow.Vector, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#getfillcolor} * Default: `[0, 0, 0, 255]` For arrays and callback results, the rgba color is in the format of `[r, g, b, [a]]`. Channels use the 0–255 range by default. See [Deck’s `normalizedColors`](../core/deck.md#normalizedcolors) to use 0–1 plain arrays. * If an array is provided, it is used as the filled color for all objects. * If a function is provided, it is called on each object to retrieve its color. An Arrow vector supplies one value per object. See [color columns](../../developer-guide/using-with-arrow.md#colors) for requirements. The default value comes from `getColor` when supplied. #### `getLineColor` (constant | Accessor | arrow.Vector, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#getlinecolor} * Default: `[0, 0, 0, 255]` For arrays and callback results, the rgba color is in the format of `[r, g, b, [a]]`. Channels use the 0–255 range by default. See [Deck’s `normalizedColors`](../core/deck.md#normalizedcolors) to use 0–1 plain arrays. * If an array is provided, it is used as the outline color for all objects. * If a function is provided, it is called on each object to retrieve its color. An Arrow vector supplies one value per object. See [color columns](../../developer-guide/using-with-arrow.md#colors) for requirements. The default value comes from `getColor` when supplied. #### `getLineWidth` (constant | Accessor | arrow.Vector, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#getlinewidth} * Default: `1` The width of the outline of each object, in units specified by `lineWidthUnits` (default meters). * If a number is provided, it is used as the outline width for all objects. * If a function is provided, it is called on each object to retrieve its outline width. An Arrow vector supplies one value per object. See [scalar columns](../../developer-guide/using-with-arrow.md#scalars) for requirements. The default value comes from `strokeWidth` when supplied. #### `getPixelOffset` ([Accessor<number[2]>](../../developer-guide/using-layers.md#accessors), optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#getpixeloffset} * Default: `[0, 0]` Screen space offset relative to the `coordinates` in pixel unit. * If an array is provided, it is used as the offset for all objects. * If a function is provided, it is called on each object to retrieve its offset. ## GPUVector inputs 🧪 {#gpuvector-inputs-unstable} > GPU buffer layouts are internal to layer implementations and can change in future releases. GPUVector props let applications supply caller-owned GPU buffers to the rendering path. This is particularly useful when applications compute rendering attributes on the GPU. - `positions` – `float32x3` – Positions in XYZ order. - `radii` – `float32` - `fillColors` – `unorm8x4` – Packed RGBA fill colors. - `lineColors` – `unorm8x4` – Packed RGBA outline colors. - `lineWidths` – `float32` Notes: - Supply one value per rendered instance, in instance order. - See [Direct GPUVector inputs](../../developer-guide/using-with-arrow.md#direct-gpuvector-inputs) for ownership, chunk alignment, and preprocessing requirements. ## Source [modules/layers/src/scatterplot-layer](https://github.com/visgl/deck.gl/tree/master/modules/layers/src/scatterplot-layer)