1.0.7 • Published 5 years ago

constellation-3d v1.0.7

Weekly downloads
6
License
ISC
Repository
github
Last release
5 years ago

constellation-3d

constellation-3d is for data visualization, it looks like constellations in the sky. Demo is here.

About this component

I created constellation-3d because I use it to show my skills in my portfolio site. Like this:

picture

picture

I think it is suitable for displaying data in which the data nodes have a loose relationship, such as all the hosts on the Internet, some of them have a connection with others, but some else haven't.

It is based on three.js and d3-force-3d.

Features

  • 3D

constellation-3d uses a 3d engine three.js, that means you can view the data in 3d space.

  • Support HTML/CSS + JSX

You can write HTML/CSS to change the appearance of constellation-3d. In order to let the user write HTML/CSS in js file, I use React 's JSX as a template engine, for more information about JSX, check document here. To define the appearance of nodes in constellation-3d, the code is like this:

<div
    style={{
        backgroundColor        : 'red',
        width        : '100px',
        height        : '100px'
        borderRadius        : '50%',
    }}
    >
        {node.name}
</div>

Install

with NPM

npm install --save constellation-3d

with HTML

    <script src='https://unpkg.com/constellation-3d/dist/main.js' ></script>
    <script src="https://unpkg.com/react@16/umd/react.production.min.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js" crossorigin></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>

NOTE, to use constellation-3d in html file, you need to surround the js code with script tag which type is 'text/babel', thats because we need write JSX in code.

<script type="text/babel">
    ...
</script>

API

Settings for behaver and appearance of the component:

SettingTypeDefaultDescription
containerDOM objectnonethe DOM div element to mount the component/canvas, e.g. document.getElementById('container')
isAnimatedbooleantrueif true, then there is an animation when it shows up
backgroundPictureURLnonebackground picture URL, support PNG, JPEG
backgroundPictureRepeatHorizontalnumbernonehow many time the picture will be repeated in the horizontal direction on the background
backgroundPictureRepeatVerticalnumbernonehow many time the picture will be repeated in the vertical direction on the background
lineColornumber0x000000the color of the line between two nodes
lineDistancenumber80the distance of the line between two nodes
textType'CSS' | 'THREE''CSS'if textType = 'CSS', use CSS+HTML to render the nodes, if = 'THREE', use Three.js 3d model to render the nodes
widthnumbernonethe width of the component
heightnumbernonethe height of the component
isTextDirectionFixedbooleantrueif true, the text of nodes will always keep facing to the camera
isAutoRotatedbooleanfalseif true, the component will rotate automatically
autoRotationSpeednumber1the speed of rotation, the larger the value, the faster the speed
cameraType'orbit' | 'perspective''orbit''orbit': the camera will rotate around the constellations; 'perspective' : the constellation will rotate around the camera
cameraPerspectivePositionXnumbernonevalid in perspective mode, indicates the x-axis coordinates of camera
cameraPerspectivePositionYnumbernonevalid in perspective mode, indicates the y-axis coordinates of camera
cameraPerspectivePositionZnumbernonevalid in perspective mode, indicates the z-axis coordinates of camera
cameraPerspectiveAngleXnumbernonevalid in perspective mode, the rotation angle of the camera around the x-axis
cameraPerspectiveAngleYnumbernonevalid in perspective mode, the rotation angle of the camera around the y-axis
cameraPerspectiveAngleZnumbernonevalid in perspective mode, the rotation angle of the camera around the z-axis
cameraObitPositionXnumbernonevalid in orbit mode, indicates the x-axis coordinates of camera
cameraObitPositionYnumbernonevalid in orbit mode, indicates the y-axis coordinates of camera
cameraObitPositionZnumbernonevalid in orbit mode, indicates the z-axis coordinates of camera
cameraObitFrustmSizenumbernonein orbit mode, distance from nodes to camera
strengthPushAllAwaynumbernonestrength pushing all nodes away
strengthPullToXnumbernonestrength pulling all nodes to X coordination
strengthPullToYnumbernonestrength pulling all nodes to Y coordination
strengthPullToZnumbernonestrength pulling all nodes to Z coordination
strengthToBounceOtherAwaynumbernonestrength bouncing all nodes away
textCSSReact componentnonepass into a react component as the template to display a node
textMeshThree.js modelnonepass into a Three.js model as the template to display a node
dataJSONnonethe data to display, see below for detail

Data format

To display some data, should give constellation-3d a JSON object, the format looks like below:

    [
        {
            name        : 'nameA',
            weight        : 2,
            children        : [
                {
                    name        : 'childA',
                    weight        : 1,
                },{
                    name        : 'childB',
                    wight        : 1,
                }
            ]
        },{
            name        : 'nameB',
            weight        : 3,
        }
    ]

description:

name : the name of this data node

weight : the weight of current node, range is 1-10

children : children array

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago