1.0.3 • Published 7 years ago

aframe-scatterplot v1.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

AFrame - Scatterplot

Introduction

An all-purpose data visualization component for the AFrame WebVR Framework.

Check out the example drag and drop application: https://zcanter.github.io/vr-scatterplot/

There is also a full example, with orbit-cam, in ./examples/example2.html

A-Frame Scatterplot

Browser Installation

Install and use by directly including the browser file:

You must also include a link the D3 JavaScript data visualization framework.

<head>
  <title>My A-Frame Scene</title>
  <script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.4.1/d3.min.js"></script>
  <script src="https://cdn.rawgit.com/zcanter/aframe-scatterplot/master/dist/a-scatterplot.min.js"></script>
</head>

<body>
  <a-scene>
    <a-scatterplot src="url(example.json)" x="field1" y="field2" z="field3" val="field4"></a-scatterplot>
  </a-scene>
</body>

NPM Installation

Install via NPM:

npm install aframe
npm install d3
npm install aframe-scatterplot

Then register and use.

require('aframe');
require('d3');
require('aframe-scatterplot');

Data Formatting

Datasets should be formatted as follows:

[
 {
   // Data Point
   "Field1": 13.90738679789567,
   "Field2": 11.77935227940546,
   "Field3": 12.02052097080796,
   "Field4": 11.31274091176219,
   "Field5": 14.13415151546462,
 },
 {
   // Data Point
   "Field1": 12.29829187876160,
   "Field2": 10.12398967761787,
   "Field3": 16.81298749861520,
   "Field4": 13.92371645984898,
   "Field5": 11.35138647618786,
 },
 {...},
 {...},
 ]

Example (Sea Surface Temperature 1km resolution):

[
 {
   "lat":-80,
   "lon":-180,
   "val":-108
 },
 {
   "lat":-80,
   "lon":-179,
   "val":-103
 },
 {...},
 {...},
 ]

How can I format my data in this way?

The easiest way to do this is to get a CSV of your dataset and use the online CSV to JSON conversion tool convertcsv. If you are a programmer you can use your favorite language to do so as well. Most popular programming languages have JSON writing capabilities of some sort.

How can I get a CSV export of my data?

The easiest way to get a CSV export is to open your data in Excel or Google Sheets and export as it a CSV file. You can also do this programmatically in your favorite language.

Can I only use geospatial data?

No, you can use non-geospatial data as long as it is formatted in the style shown above. It is important to note though that if two spacial dimensions share a unit of measurement (i.e. x and y dimensions are both in kelvin) you should specify this in the relationship option (detailed in API below).

How many fields can I have?

You may have as many fields as you like, but note you can only visualize three spacial dimensions and one color mapped dimension at any given time.

How many points can my dataset have?

We have experimented with over 5 million data points with no problems.

Do I need to normalize or scale my values?

No, the a-scatterplot component will do that for you programmatically. It is totally fine for you to leave the values at their original readings.

Where can I find example data?

Example datasets can be found here.

I'm confused mapping my X/Y/Z axis data to Aframe's X/Y/Z space

AFrame's coordinate system starts X,Y at the lower lefthand corner, and Z values increasing toward the camera. The scatterplot component uses this axis system. Further complicating this is the fact that the title and color bar are oriented relative to the Z axis in AFrame space, not to the X axis as you normally expect in a scatterplot. This is because the plot was initially designed for use with geospatial data in which X and Y values are usually latitude and longitude.

Therefore, a nice initial setting for the axes mappings is:

X axis (left/right on screen): Your Y axis values
Z axis (toward camera): your X-axis values
Y axis (up/down on screen): Your Z values

So the component attributes will be like

x="y" y="z" z="x" val="z" xlabel="My Y Axis" ylabel="My Z axis" zlabel="My X axis"

and add

rotation="0 90 0"

to pivot the whole thing so that the title and color bar are placed correctly.

If your X and Y values have the scame scale, add

relationship="zx"

If you want to make the vertical hieght shorter than the X/Y size, set

scale="1 0.5 1

Setting a nice location for an orbit-controls lookat target is a bit tricky, but see example2.html for a working example.

API

PropertyExampleDescriptionDefault Value
srcurl(data.json)The path to the data setnone
titleSea Surface TemperatureTitle of the datasetundefined
xlatX dimension from field nameundefined
yvalY dimension from field nameundefined
zlonZ dimension from field nameundefined
ssizePoint size from field nameundefined
valvalColor mapped dimension from field nameundefined
colorpresetjetName of the color map presetjet
fillval-32768, 4506Number (or numbers) representing fill values/ignored values separated by commanone
relationshipxzDimensions that share units of measurementsnone
pointSize3.5Size of the rendered data point1
pointcolor"rgb(255,0,0)"Color all the points with the same color. If specified, colorpreset is ignored. This should be a string that is parsable by the THREE.Color() function[]
pointspritedist/img/ball.pngURL of the image to use to render each point. If you do not specify point sizes, by default this component will use the THREE.PointMaterial to render the points as pixels, not sprites. If you specify point sizes or specify this spritedist/img/ball.png
raw{lat: -79, lon: 180, val: 103},...The raw data in a JS object arraynone
xfill-45, 63Fill or ignored values in X dimensionnone
yfill-78Fill or ignored values in Y dimensionnone
zfill12Fill or ignored values in Z dimensionnone
xLimit0.7Limit of relative X dimension width in 3D space1
yLimit0.5Limit of relative Y dimension width in 3D space1
zLimit0.2Limit of relative Z dimension width in 3D space1
xFliptrueInvert the X shapefalse
yFliptrueInvert the Y shapefalse
zFliptrueInvert the Z shapefalse
xlabel"aframe X / my Y"label along the X axis (see discussion about Axes)none
ylabel"aframe Y / my Z"label along the Y axis (see discussion about Axes)none
zlabel"aframe Z / my X"label along the Z axis (see discussion about Axes)none
numdecimalplaces1Number of decimal points to show in axis numbering and color bar4
showcolorbarfalseShow the color bar?true
nochrometrueTurn off rendering of axes, tics, title, and color bar? Useful if you want to create a second scatterplot directly on top of another one.false
textColor#F00Color for text#000
ycagetrueDraw vertical frame around plotfalse
showFloortrueDraw a floor on the graphfalse
floorMaterialParamsParameters passed to the foor material"color: #fff; opacity:0.5; transparent:true;"

Questions or Issues?

Feel free to open a GitHub Issue or to contact me directly at zrcanter -at- gmail

Special Thanks

Thank you to the NASA-JPL Instrument Data Systems VR working group for helping in the creation of this tool. Also thanks to Dan Moran for his awesome additions to this project!

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago