1.2.20 • Published 8 months ago

regl-map-animation v1.2.20

Weekly downloads
4
License
EUPL
Repository
github
Last release
8 months ago

regl-map-animation

npm bundle size npm license

Animate x/y point data using regl and categorize them into a bar chart. Point data should be defined as an array of objects {x,y,value} - with "value" being the numerical indicator with which the points will be categorized.

Examples

Population grid of Europe | code

Different animation patterns

Phyllotaxis | Random | Sine | Spiral | Rollout

Installation & Usage

The project is built using UMD so it works both in browsers and in node.js

Node.js

Within a node.js project simply run the following command:

npm i regl-map-animation --save

Then import:

import { animation } from "regl-map-animation";

  ReglMapAnimation.animation()
    .container(container) // div element
    .pointData(pointData) // array of {x,y,value} objects
    .width(width)
    .height(height)
    .duration(500)
    .delayAtEnd(500)
    .binLabels(true)
    .legend(true)
    .legendTitle("Population per 5 km²")
    .animate();
});

Browsers

As a standalone script use:

<script src="https://unpkg.com/regl-map-animation/build/reglmapanimation.js"></script>

Then:

  ReglMapAnimation.animation()
    .container(container)
    .pointData(pointData)
    .width(width)
    .height(height)
    .duration(500)
    .delayAtEnd(500)
    .binLabels(true)
    .legend(true)
    .legendTitle("Population per 5 km²")
    .animate();
});

Methods

NameDescriptionTypeRequiredDefault
pointDataAn array of objects with the following format: {x,y,value} - where value is the indicator used for categorization and colouring{x: number, y: number, value: number}True
logoDataAn array of objects with the following format: {x,y,color?} - Can be used to display the points initially as a logo (or whatever other coordinates you wish){x: number, y: number, color: string}False
logoColorWhen the logoData does not have a color property specified, this color will be used for all pointsstringFalse'red'
centerLogoWhether or not the logo should be centered in the container, if true it uses logoWidth() and logoHeight(), if false it uses the raw logo coordinatesBooleanFalsefalse
logoWidthSets the width of the logo in pixels when using logoData and centerLogo is set to trueNumberFalse300
logoHeightSets the height of the logo in pixels when using logoData and centerLogo is set to trueNumberFalse100
containercontainer div on which regl will append its canvasHTML elementFalsedocument.body
numPointsnumber of points to displaynumberFalsepointData.length
pointMarginMargin applied to the bars in the bar chartnumberFalse1
pointWidthwebgl point widthnumberFalse1
durationThe duration of each transition animation in millisecondsnumberFalse5000
delayAtEndHow long to stay at a final frame before animating again (in milliseconds). Can also be specified as an array with one number for each transition e.g. logo > map > chart could be 500, 1000, 6000Number or ArrayFalse0
widthWidth of the animation container (pixels)numberFalsewindow.innerWidth
heightHeight of the animation container (pixels)numberFalsewindow.innerHeight
thresholdsThresholds used for categorizing points by their "value" attributearraynumberFalse
colorsAn array of Hex values corresponding with the number of defined thresholdsarrayhexStringFalse
projectionFunctiond3-geo projection functionstringFalsegenerates x and y scales based on the extents of the x/y data
mapPaddingAdd padding (in pixels) to the map animationnumberFalse
backgroundColorSets the container's background colour (WebGL RGBA array of values from 0 to 1)number,number,number,numberFalse1,1,1,1
legendShow legendBooleanFalseTrue
legendTitleTitle of legendStringFalsenull
xAxisTitleTitle text for x axisStringFalsenull
yAxisTitleTitle text for y axisStringFalsenull
chartOffsetXX offset in pixels of the chart position in the containerNumberFalse100
chartOffsetYY offset in pixels of the chart position in the containerNumberFalse-150
binlabelsShow labels for each bar chart 'bin' (bar)BooleanFalseTrue
binLabelOffsetXX offset in pixels of each bin labelNumberFalse40
binLabelOffsetYY offset in pixels of each bin labelNumberFalse-30
binLabelYFunctionFunction used to define bin Y labelFunctionFalse(bin) => Math.round(bin.binCount)
binLabelXFunctionFunction used to define bin X labelFunctionFalseReturns threhold labels in the form of: threshold "to" nextThreshold
initialAnimationDefine the type of transition used to load the initial points. Accepted values: "random", "phyllotaxis", "sine", "spiral", "rollout"StringFalsenull (uses x & y from pointData)

Notes

Inspired by Peter Beshai and adapted from his excellent tutorial on regl.

Node.js v16.

1.2.18

10 months ago

1.2.19

8 months ago

1.2.20

8 months ago

1.2.17

11 months ago

1.2.9

1 year ago

1.2.12

1 year ago

1.2.13

1 year ago

1.2.10

1 year ago

1.2.11

1 year ago

1.2.16

1 year ago

1.2.14

1 year ago

1.2.15

1 year ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.20

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago