All Projects → curran → D3 Component

curran / D3 Component

Licence: bsd-3-clause
A lightweight component abstraction for D3.js.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to D3 Component

Pyscada
PyScada is a open source scada system that uses the Django framework as backend
Stars: ✭ 233 (+121.9%)
Mutual labels:  data-visualization, html5
React Music Player
🎵 Maybe the best beautiful HTML5 responsive player component for react :)
Stars: ✭ 321 (+205.71%)
Mutual labels:  component, html5
Mag.js
MagJS - Modular Application Glue
Stars: ✭ 157 (+49.52%)
Mutual labels:  user-interface, component
Dashr
Dash for R - An R interface to the Dash ecosystem for creating analytic web applications
Stars: ✭ 337 (+220.95%)
Mutual labels:  web-application, data-visualization
Jspaint
🎨 Classic MS Paint, REVIVED + ✨Extras
Stars: ✭ 5,972 (+5587.62%)
Mutual labels:  web-application, html5
Mopaint
🎨💪 Modern, modular paint and more! (pre-alpha, not much done yet)
Stars: ✭ 50 (-52.38%)
Mutual labels:  web-application, html5
Obscurify
Find out more about your music taste and compare it to others' with Obscurify
Stars: ✭ 200 (+90.48%)
Mutual labels:  web-application, data-visualization
Fe Interview Questions
目前最全的前端开发面试题及答案
Stars: ✭ 502 (+378.1%)
Mutual labels:  web-application, html5
React 3d Viewer
A 3D model viewer component based on react.js 一个基于react.js的组件化3d模型查看工具
Stars: ✭ 100 (-4.76%)
Mutual labels:  component, html5
Gomponents
Declarative view components in Go, that can render to HTML5.
Stars: ✭ 49 (-53.33%)
Mutual labels:  component, html5
Theorytracker
🎼 HTML5/WebAudio multi-track functional harmony analysis and songwriting app! -- https://hlorenzi.github.io/theorytracker/
Stars: ✭ 62 (-40.95%)
Mutual labels:  web-application, html5
Console Log Viewer
Displays logs and Javascript errors in an overlay on top of your site. Useful for mobile webdevelopment. Enabled in 5 seconds
Stars: ✭ 103 (-1.9%)
Mutual labels:  html5
Vue Tweezing
💃 Easy, customizable and automatic tweening nicely served in scoped slots
Stars: ✭ 101 (-3.81%)
Mutual labels:  component
Asf Ui
The official web interface for ASF
Stars: ✭ 100 (-4.76%)
Mutual labels:  user-interface
Micro Racing
🚗 🏎️ 🎮 online 3D multiplayer neural networks based racing game
Stars: ✭ 100 (-4.76%)
Mutual labels:  html5
Object Editor React
Schema-aware editor for structured JSON objects (drop-in React component)
Stars: ✭ 104 (-0.95%)
Mutual labels:  component
Gu
A web ui library for Go. [DEPRECATED]
Stars: ✭ 102 (-2.86%)
Mutual labels:  component
Covid19 Dashboard
🦠 Django + Plotly Coronavirus dashboard. Powerful data driven Python web-app, with an awesome UI. Contributions welcomed! Featured on 🕶Awesome-list
Stars: ✭ 100 (-4.76%)
Mutual labels:  data-visualization
Jscity
Visualizing JavaScript source code as navigable 3D cities
Stars: ✭ 1,367 (+1201.9%)
Mutual labels:  data-visualization
Polyfill Util
This component provides binary-safe string functions, using the mbstring extension when available.
Stars: ✭ 1,364 (+1199.05%)
Mutual labels:  component

d3-component

A lightweight component abstraction for D3.js.

Features:

Examples:

Todos
Clock
Airport Clocks
example-viewer (Redux, ES6)
Fractal Pie Chart (ES6)

Using this component abstraction, you can easily encapsulate data-driven user interface components as conceptual "boxes-within-boxes", cleanly isolating concerns for various levels of your DOM tree. This component abstraction is similar in concept and functionality to React Stateless Functional Components. Everything a component needs to render itself and interact with application state gets passed down through the component tree at render time. Components don't store any local state; this is the main difference between d3-component and the Towards Reusable Charts pattern. No special treatment is given to events or event delegation, because the intended use is within a unidirectional data flow architecture like Redux.

Installing

If you use NPM, npm install d3-component. Otherwise, download the latest release. You can also load directly from unpkg.com as a standalone library. AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3 global is exported:

<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/[email protected]"></script>
<script>
  var myComponent = d3.component("div");
</script>

API Reference

Note: There was a recent major version release, and along with it there were substantial API Changes.

In summary, the API looks like this:

var myComponent = d3.component("div", "some-class")
  .create((selection, d, i) => { ... }) // Invoked for entering component instances.
  .render((selection, d, i) => { ... }) // Invoked for entering AND updating component instances.
  .destroy((selection, d, i) => { ... }); // Invoked for exiting instances, may return a transition.

// To invoke the component,
d3.select("body") // create a selection with a single element,
  .call(myComponent, "Hello d3-component!"); // then use selection.call().

To see the full API in action, check out this "Hello d3-component" example.

# component(tagName[, className]))

Creates a new component generator that manages and renders into DOM elements of the specified tagName.

The optional parameter className determines the value of the class attribute on the DOM elements managed.

# component.create(function(selection, d, i))

Sets the create function of this component generator, which will be invoked whenever a new component instance is created, being passed a selection containing the current DOM element, the current datum (d), and the index of the current datum (i).

# component.render(function(selection, d, i))

Sets the render function of this component generator. This function will be invoked for each component instance during rendering, being passed a selection containing the current DOM element, the current datum (d), and the index of the current datum (i).

# component.destroy(function(selection, d, i))

Sets the destroy function of this component generator, which will be invoked whenever a component instance is destroyed, being passed a selection containing the current DOM element, the current datum (d), and the index of the current datum (i).

When a component instance gets destroyed, the destroy function of all its children is also invoked (recursively), so you can be sure that this function will be invoked before the compoent instance is removed from the DOM.

The destroy function may optionally return a transition, which will defer DOM element removal until after the transition is finished (but only if the parent component instance is not destroyed). Deeply nested component instances may have their DOM nodes removed before the transition completes, so it's best not to depend on the DOM node existing after the transition completes.

# component.key(function)

Sets the key function used in the internal data join when managing DOM elements for component instances. Specifying a key function is optional (the array index is used as the key by default), but will make re-rendering more efficient in cases where data arrays get reordered or spliced over time.

# component(selection[,data[,context]])

Renders the component to the given selection, a D3 selection containing a single DOM element. A raw DOM element may also be passed in as the selection argument. Returns a D3 selection containing the merged Enter and Update selections for component instances.

  • If data is specified and is an array, one component instance will be rendered for each element of the array, and the render function will receive a single element of the data array as its d argument.
    • Useful case: If data is specified as an empty array [], all previously rendered component instances will be removed.
  • If data is specified and is not an array, exactly one component instance will be rendered, and the render function will receive the data value as its d argument.
  • If data is not specified, exactly one component instance will be rendered, and the render function will receive undefined as its d argument.

In summary, components can be rendered using the following signatures:

  • selection.call(myComponent, dataObject) → One instance, render function d will be dataObject.
  • selection.call(myComponent, dataArray)dataArray.length instances, render function d will be dataArray[i]
  • selection.call(myComponent) → One instance, render function d will be undefined.

If a context object is specified, each data element in the data array will be shallow merged into a new object whose prototype is the context object, and the resulting array will be used in place of the data array. This is useful for passing down callback functions through your component tree. To clarify, the following two invocations are equivalent:

var context = {
  onClick: function (){ console.log("Clicked!");
};
selection.call(myComponent, dataArray.map(function (d){
  return Object.assign(Object.create(context), d);
}));
var context = {
  onClick: function (){ console.log("Clicked!");
};
selection.call(myComponent, dataArray, context);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].