npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

d3-plot3d

v0.0.1

Published

d3 plugin for 3D visualizations

Downloads

3

Readme

d3-plot3d

d3-plot3d is a D3 plugin that allows users to plot 3D data, lines, polygons, curves, and surfaces.

Installing

If you use NPM, npm install d3-plot3d. Otherwise, download the latest release.

API Reference

Overview

d3-plot3d projects data in the form of points using the logic employed by perspective projections. It is meant to be used with D3 and allows users to visualize 3d data and transformations on SVG's.

An example usage is shown below:

let svg = d3.select('body').append('svg')
            .attr('width', width + margin.left + margin.right)
            .attr('height', height + margin.top + margin.bottom)
let plot = d3.plot3d()
                   .scale({scale: 10})
                   .origin({origin: {x: 0, y: 0, z: 0}})
                   .axes({xRange: 10, yRange: 10, zRange: 10})
                   .plot({type: 'line', data: [{x: 5, y: 10, z: 10}, {x: 10, y: 15, z: 10}], attributes: {stroke: 'purple'}}) 
                   .plot({type: 'polygon', data: [{x: 0, y: 0, z: 0}, {x: 10, y: 10, z: 10}, {x: 0, y: 10, z: 0}], attributes: {fill: 'orange'}}) 
                   .plot({type: 'curve', data: {x: (t) => 3*Math.cos(t), y: (t) => 3*Math.sin(t), z: (t) => t, tMin: -10, tMax: 10, tStep: 0.1}, attributes: {stroke: 'brown'}})
                   .plot({type: 'curve', data: {x: (t) => -3*Math.cos(t), y: (t) => 3*Math.sin(t), z: (t) => t, tMin: -10, tMax: 10, tStep: 0.1}, attributes: {stroke: 'maroon'}})
                   .plot({type: 'point', data: [{x: 10, y:0 , z:0}], attributes: {stroke: 'maroon'}})
                   .plot({type: 'surface', data: {z: (x, y) => Math.sin((x*x+y*y))}, attributes: {fill: 'purple'}})

svg.call(plot)

plot.draw()

For a visualization of this plot, refer to the following bl.ock.

# plot3d()

Construct a new plot with default settings.

# scale({scale=100})

Defines the scale of 3d plot.

Default: scale = 100

# origin({origin={x:0, y:0, z:0}})

Defines where to place the origin of the plot. For example, if passed the point {x: 10, y:0, z:0}, then the point {x: 10, y:0, z:0} would appear at the center of the plot.

Default: origin = {x: 0, y:0, z:0}

# rotation({yaw=-2, pitch=0.66, roll=0})

Defines rotational elements according the aircraft principal axes, based on the concepts of yaw, pitch and roll. For a full visualization for how each of these individual elements affect the plot, refer to this demonstration.

Default: yaw=-2, pitch=0.66, roll=0

# rotationFactor({rotationFactor=1000})

Defines how much a mouse drag event rotates the plot where larger values cause the plot to rotate faster and vice a versa. Note that increasing/decreasing the rotation factor can affect render speed.

Default: rotationFactor=1000

# zoomFactor({zoomFactor=1})

Defines how much a click event on the + and - buttons at the top left of the plot zooms in or out. Note that increasing/decreasing the zoom factor can affect render speed

Default: zoomFactor=1000

# plot(plot)

Add a plot of specific type to the current plot. Plot types are defined as follows:

plot = {type, data, attributes} 

Plot types

POINT Represented by an svg <circle/> element. data must be an array of objects, each representing an individual point. attributes is an object consisting of optional attributes the user can set including fill, radius, and class.

Example usage:

let plot = d3.plot3d()
                    .plot({type: 'point', data: [{x: 10, y:0 , z:0}], attributes: {fill: 'maroon'}})

LINE Represented by an svg <line/>. data must be an array of 2 objects, each representing an individual point to draw the line between. attributes is an object consisting of optional attributes the user can set including stroke_width, stroke, and class.

Example usage:

let plot = d3.plot3d()
                   .plot({type: 'line', data: [{x: 5, y: 10, z: 10}, {x: 10, y: 15, z: 10}], attributes: {stroke: 'purple'}}) 

POLYGON Represented by an svg <polygon/>. data must be an array of 3 or more objects, each representing an individual point to draw the lines between in sequence. attributes is an object consisting of optional attributes the user can set including fill, opacity, and class.

Example usage:

let plot = d3.plot3d()
                   .plot({type: 'polygon', data: [{x: 0, y: 0, z: 0}, {x: 10, y: 10, z: 10}, {x: 0, y: 10, z: 0}], attributes: {fill: 'orange'}}) 

CURVE Represented by an svg <path/> and can be used to draw parametric curves. data must be an object defined as follows:

data = {x: x(t), y: y(t), z: z(t), tMin, tMax, tStep}

In the above object, x, y, and z are defined as functions of t and will be graphed in the domain specified by [tMin, tMax]. Individual points will be computed within the domain by incrementing t from tMin to tMax by tStep and interpolated via d3.curveCardinal.

attributes is an object consisting of optional attributes the user can set including stroke, stroke_width, and class.

Example usage:

let plot = d3.plot3d()
                   .plot({type: 'curve', data: {x: (t) => 3*Math.cos(t), y: (t) => 3*Math.sin(t), z: (t) => t, tMin: -10, tMax: 10, tStep: 0.1}, attributes: {stroke: 'brown'}})

SURFACE Represented by an svg multiple svg <polygon/> elements consisting of 4 points. data must be an object consisting of a z attribute defined as a function of x and y (i.e. data = {z: z(x, y)}).

attributes is an object consisting of optional attributes the user can set including opacity, fill, and class. fill must be one of the following colors defined by d3's sequential single hue scales. Hence, fill must be one of the following: 'blue', 'green', 'grey', 'orange', 'purple', or 'red'.

Example usage:

let plot = d3.plot3d()
                   .plot({type: 'surface', data: {z: (x, y) => Math.sin((x*x+y*y))}, attributes: {fill: 'purple'}})

# draw()

Draw the plot according to the previously defined settings and shapes.