Skip to main content
100%

Diamonds - d3fc version

✓ Published0🌍 Public
CColinEberhardt
Last edited May 28, 2019
Created on Dec 8, 2016

This example visualizes 53,000 diamonds as a scatterplot of price against carat weight, rendered as red points on a Canvas. The d3fc library’s `seriesCanvasPoint` and `chartCartesian` components handle the plotting, with scales and extents from `d3.scaleLinear` and `fc.extentLinear`. Data from the diamonds.tsv file is batched into chunks of 500 points via a `d3.timer`, shuffling the dataset each frame to animate the progressive rendering. The chart re-renders responsively on window resize.

AI-generated description

This is a re-implementation of Mike Bostock's 'Diamonds' bl.ock which renders a large dataset (53k points) to canvas. It takes a number of seconds to render the data, so it is batched into 'chunks' of 500 points in order to avoid having a blank page.

This bl.ock re-implements the example using d3fc which has chart and series components that support rendering to Canvas or SVG. The goal of d3fc is to extend the vocabulary of D3 from basic SVG / Canvas constructs of paths, circles and rectangles, to support a charting vocabulary of series, charts and legends. In this case the code is (marginally) simpler than the D3 equivalent, but has the advantage that the chart is 'responsive', if you open the chart in a new window and re-size you'll find that it re-renders automatically.

The batching of the rendered data is a slightly unusual concept, with d3fc components are rendered via a data-join, which isn;t really compatible with this concept. The Cartesian chart component used in this example makes use of d3fc-element which provides draw and measure events, that provide layout and (throttled) rendering. The solution employed in this example is to bind the chart to an empty array via a data-join, then handle the draw event directly, batching the data and rendering vi the series component.

Slightly unusual, but effective!

mit Licensed

Similar vizzes