All Projects → romsson → d3-gridding

romsson / d3-gridding

Licence: BSD-3-Clause license
grids for rapid D3 charts mockups

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to d3-gridding

Carbon Charts
📊 📈⠀Robust dataviz framework implemented using D3 & typescript
Stars: ✭ 287 (+187%)
Mutual labels:  d3, dataviz, d3js
ddplot
Create D3 based SVG graphics easily from R
Stars: ✭ 43 (-57%)
Mutual labels:  d3, dataviz, d3js
Vue D3 Workshop
Workshop content material and excercises for Suncoast Developers
Stars: ✭ 63 (-37%)
Mutual labels:  d3, dataviz, d3js
leaflet heatmap
简单的可视化湖州通话数据 假设数据量很大,没法用浏览器直接绘制热力图,把绘制热力图这一步骤放到线下计算分析。使用Apache Spark并行计算数据之后,再使用Apache Spark绘制热力图,然后用leafletjs加载OpenStreetMap图层和热力图图层,以达到良好的交互效果。现在使用Apache Spark实现绘制,可能是Apache Spark不擅长这方面的计算或者是我没有设计好算法,并行计算的速度比不上单机计算。Apache Spark绘制热力图和计算代码在这 https://github.com/yuanzhaokang/ParallelizeHeatmap.git .
Stars: ✭ 13 (-87%)
Mutual labels:  d3, dataviz, d3js
Ngx Charts
📊 Declarative Charting Framework for Angular
Stars: ✭ 4,057 (+3957%)
Mutual labels:  d3, dataviz, d3js
D3 Parliament
A parliament chart based on D3js
Stars: ✭ 44 (-56%)
Mutual labels:  d3, dataviz, d3js
Dex
Dex : The Data Explorer -- A data visualization tool written in Java/Groovy/JavaFX capable of powerful ETL and publishing web visualizations.
Stars: ✭ 1,238 (+1138%)
Mutual labels:  d3, dataviz, d3js
Reaviz
📊 Data visualization library for React based on D3
Stars: ✭ 215 (+115%)
Mutual labels:  d3, d3js
Ssthouse Blog
个人博客仓库:前端 / 数据可视化 / D3.js
Stars: ✭ 231 (+131%)
Mutual labels:  d3, d3js
k8s-graph
Visualize your Kubernetes (k8s) cluster
Stars: ✭ 23 (-77%)
Mutual labels:  d3, d3js
mastering-d3
Code examples for the book Mastering D3.js, published in August 2014 by Packt Publishing.
Stars: ✭ 56 (-44%)
Mutual labels:  d3, d3js
Keen Dataviz.js
Data Visualization Charting Library
Stars: ✭ 215 (+115%)
Mutual labels:  d3, dataviz
Architecturetree
Draw and share your software architecture without diagramming software. Uses d3.js and Angular.js.
Stars: ✭ 211 (+111%)
Mutual labels:  d3, dataviz
Plotly Graphing Library For Matlab
Plotly Graphing Library for MATLAB®
Stars: ✭ 234 (+134%)
Mutual labels:  d3, d3js
V Chart Plugin
Easily bind a chart to the data stored in your Vue.js components.
Stars: ✭ 188 (+88%)
Mutual labels:  d3, d3js
D3tutorial
📊📈 A D3 v6 tutorial - interactive bar chart and multiple coordinated views (MCV)
Stars: ✭ 163 (+63%)
Mutual labels:  d3, d3js
Gtr Cof
Interactive music theory dashboard for guitarists. http://guitardashboard.com/
Stars: ✭ 244 (+144%)
Mutual labels:  d3, d3js
you-draw-it
Datenjournalismus: Nutzer können schätzen, wie sich Statistiken verändert haben und ihre Einschätzung danach überprüfen.
Stars: ✭ 24 (-76%)
Mutual labels:  d3, d3js
multi-chart
lit-element building blocks for charts and visualization (based on d3.js v5)
Stars: ✭ 24 (-76%)
Mutual labels:  d3, dataviz
lineage
Family Tree Data Expression Engine
Stars: ✭ 90 (-10%)
Mutual labels:  d3, dataviz

d3-gridding

npm version Build Status dependencies Status

Create rapid mock-ups for D3 charts, using data-driven grids.

modes layouts

Left: grids available in the toolkits; Right: layouts for page partition to nest grids within

Example

<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="https://unpkg.com/d3@5"></script>
<script src="https://unpkg.com/[email protected]"></script>
<script>

var width = 400,
    height = 300;

var gridding = d3.gridding()
  .size([width, height])
  .mode("grid");

var data = d3.range(250);

var griddingData = gridding(data);

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

svg.selectAll(".square")
    .data(griddingData)
  .enter().append("rect")
    .style("fill", "none")
    .style("stroke", "black")
    .attr("width", function(d) { return d.width; })
    .attr("height", function(d) { return d.height; })
    .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
    
  </script>
</body>

Output below and live coding version.

minimalistic grid

The code snippet below lets you create dots organized as a grid:

d3.select("body").append("svg")
    .attr("width", 800)
    .attr("height", 600)
    .selectAll("circle")
    .data(
      d3.gridding()
        .size([800, 600])
        .mode("vertical")(d3.range(10))
    )
  .enter().append("circle")
    .attr("r", 10)
    .attr("transform", function(d) { 
      return "translate(" + d.cx + "," + d.cy + ")"; 
      });

More Examples

How to use it

To install, use NPM npm install d3-gridding or download the latest release.

To use, include the d3-gridding.js JavaScript file in your HTML code or use the following:

<script src="https://unpkg.com/[email protected]"></script>

Output below and live coding version.

minimalistic circle grid

The magic happens with gridding which turns an array of JavaScript Objects, into another array with additional attributes:

> gridding([{}, {}, {}])

[▶ Object, ▶ Object, ▶ Object]

[ Object                    ]
    x: 0
    y: 300
    cx: 300
    cy: 300
    height: 600
    width: 266.6666666666667
  • (x, y) the computed coordinates (which can be seen as top / left values)
  • (height, width) gives the bounding box if combined with (x, y)
  • (cx, cy) the center of the bounding box

It becomes interesting when changing the type of layout, which will organize the elements differently, by changing the value of the attributes above:

gridding.mode("horizontal");

var points = svgPoints.selectAll(".point")
  .data(gridding(data));

That's pretty much what you need to know at this point to get started. Below is a list of functions that will let you customize the layouts and retrieve internal values.

Note that parameters can also be set as group, using a JSON object:

var gridding = d3.gridding()
  .params({
    "size": [800, 600],
    "mode": "vertical",
    "offset": function(d) { return [d.x, d.y]; }
  });

Layouts

Layouts help to divide and organize a page into regions. Layouts actually are grids that are generated with some dataset that can be seen as proportions. Below is an example of dataset that is from this list of layouts. See the layout list and source code.

var layout = {
  "name": "basic3columns",
  "values": [
    {"index": 1, "__x": 10, "__y": 10, "__height": 0, "__width": 0},
    {"index": 2, "__x": 0, "__y": 0, "__height": 10, "__width": 2, "name": "left"},
    {"index": 3, "__x": 2, "__y": 0, "__height": 10, "__width": 6, "name": "main"},
    {"index": 4, "__x": 8, "__y": 0, "__height": 10, "__width": 2, "name": "right"}]
};

The result is as below and can be found on this page.

layout 3col

Then to draw the layout you may need to set the grid parameters accordingly as below.

var gridding = d3.gridding()
  .params({
    "size": [width, height],
    "offset": [0, 0],
    "mode": "coordinate",
    "valueX": "__x",
    "valueY": "__y",
    "valueWidth": function(d) { return d["__width"]},
    "valueHeight": function(d) { return d["__height"]}
  });

And finally drawing the layout the very same way one draws a grid.

svgSquares.selectAll(".square")
    .data(gridding(layout.values))
  .enter().append("rect")
    .attr("class", "square")
      .attr("width", function(d) { return d.width; })
      .attr("height", function(d) { return d.height; })
      .attr("transform", function(d) { 
        return "translate(" + d.x + "," + d.y + ")"; 
      });

Nesting

One of the most powerful property of grids is to allow their nesting

-Simple recursive function

-How to set the grids in one param element?

Rendering methods

d3-gridding is agnostic to the rendering method

SVG

Canvas

Divs

WebGL

API

# d3.gridding().mode(mode)

The mode parameter sets the layout:

  • vertical - vertical partitioning of value .valueHeight() and vertical offset .valueX()
  • horizontal - horizontal partitioning of value .valueWidth() and vertical offset .valueY()
  • central - overlapping partitioning
  • grid - classic grid partitioning
  • coordinate - position (.valueX() and .valueY()) and dimensions (.valueWidth(), .valueHeight()) can be set with relative or absolute positions
  • radial - circular partitioning (e.g. pie chart with uniform wedges)
  • treemap- using d3.treemap() layout
  • pack - using d3.pack()
  • pyramid - centered grids overlays
  • stack - using d3.stack()
  • diagonal - aligned on the diagonal
  • cascade - like diagonal but with larger and overlapping cells
  • identity - does nothing, returns same values

Others

  • gridding.modes() returns the list of all available modes as an array, e.g. ["brick", "cascade", "central", "coordinate", "corner", "diagonal", "grid", "horizontal", "pack", "pyramid", "radial", "stack", "step", "tree", "treemap", "vertical"]

  • gridding.modes("brick") returns the properties for a single mode that are exposed as [an array of key/values] such as [{"key": "orient", "value": "left"}, {"key": "valueX", "value": null}] that contain both possible values and the default ones.

# d3.gridding().sort([compare])

Sets the sort function, similar to D3's and defaults to:

function(a, b) { return a - b; }

Thus you can use D3's sorting functions such as d3.ascending and d3.descending.

# d3.gridding().value([accessor])

Sets the value accessor function, similar to D3's and defaults to:

function value(d) { return d; }

# d3.gridding().valueY([string || accessor])

The value can either be a traditional accessor function but for attributes this time, or the data attribute itself directly as a string:

.valueY(function value(d) { return d["index"]; })

or

.valueY("index")

# d3.gridding().valueY([string || accessor])

See valueY().

# d3.gridding().padding(value)

Sets the local offset between grid elements (default: 1px).

# d3.gridding().offset(value)

Sets the global offset for all elements (default: 0px) as an array [left, top].

# d3.gridding().orient("up" | "down" (default))

Orients the grid & diagonal layouts either upwards or downwards when adding / removing cells.

# d3.gridding().radius(value)

Radius for radial layout.

# d3.gridding().sort(value || function)

Sort by attribute value (or function if value is a function.

# d3.sortAsc().sortAsc(true || false)

By default, ascending sorting by sort attribute || function defined previously.

Credits

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].