Interactive 3D plotting with a simple function call using Three.js

Overview

Z3d

Example

About

Generate interactive 3d plots with a simple function call. Function returns a Three.js scene which can be customized as needed.

Basic function call generates a X-Y-Z scatter plot. Optional configuration object can be used to change color and size values.

Install

bower install z3d

Usage

Why use Z3d? Because configuration is optional, an interactive 3d plot with sensible defaults can be generated with as little as a single line.

Plotting function takes the data to plot and an optional configuration object.

###Basic Example (no configuration)

<html>
  <head>
    <script src="bower_components/threejs/build/three.min.js" charset="utf-8"></script>
    <script src="bower_components/z3d/js/OrbitControls.js" charset="utf-8"></script>
    <script src="bower_components/z3d/js/plot.js" charset="utf-8"></script>
  </head>
  <body>
    <script type="text/javascript">

      //HERE IS THE DATA TO PLOT:
      var x = [-0.8234, 0.0952, 1.9594, -0.2831, -0.4147, 1.5859, 0.5326, 0.0925, 0.3293, 1.3635, 0.3396, 0.0677, -0.6739, 0.4084, -1.4487, -0.1101, -0.7521, -1.2118, 1.7191, 0.2020, -0.1573, -0.2298, -0.8230, 1.7924, 0.4511];
      var y = [-1.4166, 1.353, -0.6294, 0.0567, 1.4157, 0.32806, 0.2377, -0.2262, -1.0602, -1.8150, 0.1075, -1.3516, 1.0137, 0.0183, -0.5466, 0.6416, -0.6655, 0.6874, -0.4616, -0.2808, 1.3443, -1.0518, -0.1332, -1.0097, 0.3643];
      var z = [1.4166, -1.353, 0.6294, -0.0567, -1.4157, -0.32806, -0.2377, 0.2262, 1.0602, -1.5089, 0.1543, -0.3516, 0.0137, 1.0183, 1.5466, -1.6416, 1.6655, -1.6874, -0.4616, -1.2808, -1.3443, 1.0518, -0.1332, 1.9700, -0.3643];

      //AND THIS IS HOW WE PLOT IT:
      var plot = plot3d(x,y,z);

    </script>
  </body>
</html>

###Example With Configuration

We can add a configuration object to the example above to modify the height/width of our plot, the DOM element the visualization is appended to, the labels on the points plotted, the size of the points plotted, and the color of the points plotted.

<html>
  <head>
    <script src="bower_components/threejs/build/three.min.js" charset="utf-8"></script>
    <script src="bower_components/z3d/js/OrbitControls.js" charset="utf-8"></script>
    <script src="bower_components/z3d/js/plot.js" charset="utf-8"></script>
  </head>
  <body>
    <div id='myDOMel'></div>
    <script type="text/javascript">

      //HERE IS THE DATA TO PLOT:
      var x = [-0.8234, 0.0952, 1.9594, -0.2831, -0.4147, 1.5859, 0.5326, 0.0925, 0.3293, 1.3635, 0.3396, 0.0677, -0.6739, 0.4084, -1.4487, -0.1101, -0.7521, -1.2118, 1.7191, 0.2020, -0.1573, -0.2298, -0.8230, 1.7924, 0.4511];
      var y = [-1.4166, 1.353, -0.6294, 0.0567, 1.4157, 0.32806, 0.2377, -0.2262, -1.0602, -1.8150, 0.1075, -1.3516, 1.0137, 0.0183, -0.5466, 0.6416, -0.6655, 0.6874, -0.4616, -0.2808, 1.3443, -1.0518, -0.1332, -1.0097, 0.3643];
      var z = [1.4166, -1.353, 0.6294, -0.0567, -1.4157, -0.32806, -0.2377, 0.2262, 1.0602, -1.5089, 0.1543, -0.3516, 0.0137, 1.0183, 1.5466, -1.6416, 1.6655, -1.6874, -0.4616, -1.2808, -1.3443, 1.0518, -0.1332, 1.9700, -0.3643];

      var labs = [];
      z.forEach(function(el,i){
        labs.push('label '+i);
      });

      //make a function to generate random colors for the points in our example
      function getHexColor(){
        var chars = ['1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];
        var string = '';
        for (var i=0;i<6;i++){
          var index = Math.floor(Math.random()*16);
          string += chars[index];
        }
        return string;
      }

      //now we generate size and color arrays for our points
      var sizes = [];
      var colors = [];
      for (var i=0; i<x.length; i++){
        sizes.push(Math.random());
        colors.push(getHexColor());
      }

      //THIS IS WHERE WE MAKE THE CONFIGURATION OBJECT:
      var config = {
        size: sizes,
        color: colors,
        label: labs,
        //height and width of the DOM element
        height: 400,
        width: 400,
        elementID: 'myDOMel'
      }

      //AND THIS IS HOW WE PLOT IT:
      var plot = plot3d(x,y,z,config);

    </script>
  </body>

</html>

License

The MIT License (MIT)

Copyright (c) 2014 Nathan Epstein

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You might also like...

The invoker based on event model provides an elegant way to call your methods in another container via promisify functions

The invoker based on event model provides an elegant way to call your methods in another container via promisify functions. (like child-processes, iframe, web worker etc).

Dec 29, 2022

fcall, fetch and call any remote hot functions, anywhere, anytime, without installations or configurations.

fcall, fetch and call any remote hot functions, anywhere, anytime, without installations or configurations.

Sep 20, 2022

Minimal web3 implementation: call eth contracts directly from JS

micro-web3 Minimal web3 implementation: call eth contracts directly from JS Connect to any web3 server: host your own with execution layer client, or

Dec 29, 2022

⚡🚀 Call multiple view functions, from multiple Smart Contracts, in a single RPC query!

ethers-multicall ⚡ 🚀 Call multiple view functions, from multiple Smart Contracts, in a single RPC query! Querying an RPC endpoint can be very costly

Dec 30, 2022

ESLint plugin to disallow the optional-call operator

ESLint Plugin: no-optional-call Overview The no-optional-call ESLint plugin provides a single rule (non-configurable) that disallows any usage of the

Sep 24, 2022

In this project I'll use Asynchronous Javascript to call an API and set the leaderboard of the best players.

Leaderboard Project In this project I'll use Asynchronous Javascript to call an API and set the leaderboard of the best players. The main goals of thi

Oct 17, 2022

A Stacks DeFi app that automates covered call writing to generate sustainable, risk-adjusted yield.

A Stacks DeFi app that automates covered call writing to generate sustainable, risk-adjusted yield.

💰 Options Vault 💰 A Stacks DeFi app that automates covered call writing to generate sustainable, risk-adjusted yield. Options vaults allow you to al

Nov 16, 2022

Color palette generation function using hue cycling and simple easing functions.

Color palette generation function using hue cycling and simple easing functions.

Rampensau 🐷 Color palette generation function using hue cycling and easing functions. Check out a simple demo or see it in action over on farbvelo 10

Dec 28, 2022
Releases(0.0.3)
Owner
Nathan Epstein
Nathan Epstein
Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Lily Scott 3 Feb 28, 2022
100% type-safe query builder for node-postgres :: Generated types, call any function, tree-shakable, implicit type casts, and more

⚠️ This library is currently in alpha. Contributors wanted! tusken Postgres client from a galaxy far, far away. your database is the source-of-truth f

alloc 54 Dec 29, 2022
Straight forward plotting built on D3

D3xter About Simple and powerful syntax to make common charts with minimal code. Highly flexible plotting for deep customization. Sensible defaults bu

Nathan Epstein 341 Oct 20, 2022
three.js examples. if you are first in learning three.js , this will give you much help.

three-projected-material Three.js Material which lets you do Texture Projection on a 3d Model. Installation After having installed three.js, install i

null 22 Nov 2, 2022
Text Engraving & Extrusion demo based on Three.js is implemented with Typescript and webpack5. Used THREE-CSGMesh as the core tech to achieve engraving and extrusion results

Text Engraving & Extrusion Text Engraving & Extrusion demo is implemented using Three.js, with Typescript and webpack5. Used THREE-CSGMesh as the core

Jiahong Li 3 Oct 12, 2022
A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM deffiniation and appropriate file structure.

Welcome to function-stencil ?? A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM

Ben Smith 21 Jun 20, 2022
Tries to execute sync/async function, returns a specified default value if the function throws

good-try Tries to execute sync/async function, returns a specified default value if the function throws. Why Why not nice-try with it's 70+ million do

Antonio Stoilkov 14 Dec 8, 2022
Wrap a function with bun-livereload to automatically reload any imports inside the function the next time it is called

bun-livereload Wrap a function with bun-livereload to automatically reload any imports inside the function the next time it is called. import liveRelo

Jarred Sumner 19 Dec 19, 2022
an open-source package to make it easy and simple to work with RabbitMQ's RPC ( Remote Procedure Call )

RabbitMQ Easy RPC (Remote Procedure Call ) The Node.js's RabbitMQ Easy RPC Library rabbitmq-easy-RPC is an easy to use npm package for rabbitMQ's RPC

Ali Amjad 4 Sep 22, 2022
1on1 call demo using Chime SDK meetings, Next.js, AppSync, and CDK!

Chime SDK Meetings 1on1 call demo with Next.js / AppSync / CDK This is a sample project to demonstrate Chime SDK meetings for one-on-one call with Nex

AWS Samples 4 Dec 15, 2022