Git Product home page Git Product logo

d3fc-annotation's Introduction

d3fc-annotation

A collection of components for rendering plot area annotations (bands, crosshairs, gridlines and lines) onto Cartesian charts using SVG and canvas (coming soon! #2) .

Main d3fc package

Installation

npm install d3fc-annotation

API

Gridline Annotation

The gridline component renders horizontal and vertical gridlines.

# fc.annotationSvgGridline()

Constructs a new gridline annotation component. Once constructed, configure the component with scales and call it on a selection -

const xScale = d3.scaleLinear()
  .range([0, 100]);

const yScale = d3.scaleLinear()
  .range([0, 100]);

const gridline = fc.annotationSvgGridline()
  .xScale(xScale)
  .yScale(yScale);

d3.select('svg')
  .call(gridline);

# gridline.xScale([scale])

If scale is specified, sets the scale used for the vertical gridline positions (combined with xTicks). Additionally, its range is taken as the bounds of the horizontal gridlines. If scale is not specified, returns the current xScale.

# gridline.yScale([scale])

If scale is specified, sets the scale used for the horizontal gridline positions (combined with yTicks). Additionally, its range is taken as the bounds of the vertical gridlines. If scale is not specified, returns the current yScale.

# gridline.xTicks([count])

If count is specified, sets the count passed to ticks when requesting the horizontal gridline positions when xScale is a continuous scale. For other scales, this value is ignored and the domain is used directly. If count is not specified, returns the current count.

# gridline.xTickValues([values])

Manually specify the vertical gridline positions. Overrides xTicks.

# gridline.yTicks([count])

If count is specified, sets the count passed to ticks when requesting the vertical gridline positions when yScale is a continuous scale. For other scales, this value is ignored and the domain is used directly. If count is not specified, returns the current count.

# gridline.yTickValues([args])

Manually specify the vertical gridline positions. Overrides yTicks.

# gridline.xKey([keyFunc])

If keyFunc is specified, sets the key function used when joining the vertical gridlines to SVG elements. If not specified, returns the current key function.

# gridline.yKey([keyFunc])

If keyFunc is specified, sets the key function used when joining the horizontal gridlines to SVG elements. If not specified, returns the current key function.

# gridline.xDecorate([decorateFunc])

If decorateFunc is specified, sets the decorate function used when joining the vertical gridlines to SVG elements. If not specified, returns the current decorate function.

# gridline.yDecorate([decorateFunc])

If decorateFunc is specified, sets the decorate function used when joining the horizontal gridlines to SVG elements. If not specified, returns the current decorate function.

Band Annotation

The band component renders horizontal and vertical bands.

# fc.annotationSvgBand()

Constructs a new band annotation component. Once constructed, configure the component with scales, associate a selection with some data representing the band locations and call it on the selection -

const xScale = d3.scaleLinear()
  .range([0, 100]);

const yScale = d3.scaleLinear()
  .range([0, 100]);

const band = fc.annotationSvgBand()
  .xScale(xScale)
  .yScale(yScale);

d3.select('svg')
  .datum([{ from: 45, to: 55 }])
  .call(band);

# band.xScale([scale])

If scale is specified, sets the scale used for transforming the fromValue/toValue positions of vertical bands. Additionally, its range is taken as the bounds of the horizontal bands. If scale is not specified, returns the current xScale.

# band.yScale([scale])

If scale is specified, sets the scale used for transforming the fromValue/toValue positions of horizontal bands. Additionally, its range is taken as the bounds of the vertical bands. If scale is not specified, returns the current yScale.

# band.orient([orientation])

If orientation is specified, sets the orientation of the bars to either horizontal or vertical. If orientation is not specified, returns the current orientation.

# band.fromValue([accessorFunc])

If accessorFunc is specified, sets the function used to retrieve the start value for bands. This value will be passed through the appropriate scale. If not specified, returns the current start value.

# band.toValue([accessorFunc])

If accessorFunc is specified, sets the function used to retrieve the end value for bands. This value will be passed through the appropriate scale. If not specified, returns the current end value.

# band.decorate([decorateFunc])

If decorateFunc is specified, sets the decorate function used when joining the bands to SVG elements. If not specified, returns the current decorate function.

Line Annotation

The line component renders horizontal and vertical lines.

# fc.annotationSvgLine()

Constructs a new line annotation component. Once constructed, configure the component with scales, associate a selection with some data representing the line locations and call it on the selection -

const xScale = d3.scaleLinear()
  .range([0, 100]);

const yScale = d3.scaleLinear()
  .range([0, 100]);

const line = fc.annotationSvgLine()
  .xScale(xScale)
  .yScale(yScale);

d3.select('svg')
  .datum([50])
  .call(line);

# line.xScale([scale])

If scale is specified, sets the scale used for transforming the value of the line. Additionally, its range is taken as the bounds of the horizontal lines. If scale is not specified, returns the current xScale.

# line.yScale([scale])

If scale is specified, sets the scale used for transforming the value of the line. Additionally, its range is taken as the bounds of the vertical lines. If scale is not specified, returns the current yScale.

# line.orient([orientation])

If orientation is specified, sets the orientation of the lines to either horizontal or vertical. If orientation is not specified, returns the current orientation.

# line.value([accessorFunc])

If accessorFunc is specified, sets the function used to retrieve the value for lines. This value will be passed through the appropriate scale. If not specified, returns the current value.

# line.label([accessorFunc])

If accessorFunc is specified, sets the function used to retrieve the label for lines. If not specified, returns the current label.

# line.decorate([decorateFunc])

If decorateFunc is specified, sets the decorate function used when joining the lines to SVG elements. If not specified, returns the current decorate function.

Crosshair Annotation

The crosshair component renders a pair of vertical and horizontal lines with a point at their center.

# fc.annotationSvgCrosshair()

Constructs a new crosshair annotation component. Once constructed, configure the component with scales, associate a selection with some data representing the crosshair locations and call it on the selection -

const xScale = d3.scaleLinear()
  .range([0, 100]);

const yScale = d3.scaleLinear()
  .range([0, 100]);

const crosshair = fc.annotationSvgCrosshair()
  .xScale(xScale)
  .yScale(yScale);

d3.select('svg')
  .datum([{x: 50, y: 50}])
  .call(crosshair);

# crosshair.xScale([scale])

If scale is specified, sets the scale whose range is taken as the bounds of the horizontal lines. If scale is not specified, returns the current xScale.

# crosshair.yScale([scale])

If scale is specified, sets the scale whose range is taken as the bounds of the vertical lines. If scale is not specified, returns the current yScale.

# crosshair.x([accessorFunc])

If accessorFunc is specified, sets the function used to retrieve the x position of the crosshair. N.B. this value will not be passed through the appropriate scale. If not specified, returns the current value.

# crosshair.y([accessorFunc])

If accessorFunc is specified, sets the function used to retrieve the y position of the crosshair. N.B. this value will not be passed through the appropriate scale. If not specified, returns the current value.

# crosshair.xLabel([accessorFunc])

If accessorFunc is specified, sets the function used to retrieve the label for vertical lines. If not specified, returns the current label.

# crosshair.yLabel([accessorFunc])

If accessorFunc is specified, sets the function used to retrieve the label for horizontal lines. If not specified, returns the current label.

# crosshair.decorate([decorateFunc])

If decorateFunc is specified, sets the decorate function used when joining the crosshairs to SVG elements. If not specified, returns the current decorate function.

d3fc-annotation's People

Contributors

alisd23 avatar chrisprice avatar colineberhardt avatar greenkeeperio-bot avatar mbssantos avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.