# Class: c3.Plot.Layer Abstract

Defined in: | js/c3-layers.coffee

## Overview

This class is abstract.

The root abstract class of layers for the c3 XY Plot Chart

## Internal Interface

The internal interface that plot layers can implement essentially match the c3.Base internal abstract interface:

- {c3.base#init init()}
- {c3.base#size size()}
- {c3.base#update update()}
- {c3.base#draw draw()}
- {c3.base#style style()}

An additional method is added:

- zoom() - Called when the chart is zoomed or panned.

## Extensibility

Each layer has the following members added:

- chart - Reference to the XY Plot Chart this layer belongs to
- content - A selection of the layer content
- g - A D3 selection for the SVG g node for this layer
- width - width of the layer
- height - height of the layer

Items should be positioned on the the layer using the layer's `h` and `v` scales. As a performance optimization some layers may create a g node with the `scaled` class. When the plot is zoomed then this group will have a transform applied to reflect the zoom so individual elements do not need to be adjusted. Please use the `chart.orig_h` scale in this case. Not that this approach does not work for many circumstances as it affects text aspect ratio, stroke widths, rounding errors, etc.

### Author:

- Douglas Armstrong

## Direct Known Subclasses

c3.Plot.Layer.Stackable c3.Plot.Layer.Line.Straight c3.Plot.Layer.Region c3.Plot.Layer.Scatter c3.Plot.Layer.Swimlane

## Variables Summary

version =

      0.1

type =

      'layer'

_next_uid =

      0

data =

      undefined

  [Array] Data for this layer This can be set for each individual layer or a default for the entire chart.

name =

      undefined

  [String] User name for this layer. This is used in legends, for example.

class =

      undefined

  [String] CSS class to assign to this layer for user style sheets to customize

static_data =

      false

  [Boolean] If true this layer is considered to have "static" data and will not update when redraw() is called.

h =

      undefined

  [d3.scale] Scale for the vertical Y axis for this layer. Please set the domain(), c3 will set the range(). The vertical scale may be set for the entire chart instead of for each layer.

v =

      undefined

  [d3.scale] Scale for the vertical Y axis for this layer. Please set the domain(), c3 will set the range(). The vertical scale may be set for the entire chart instead of for each layer.

x =

      undefined

  [Function] An accessor function to get the X value from a data item. This can be set for each individual layer or a default for the entire chart. Some plots support calling this accessor with the index of the data as well as the datum itself.

y =

      undefined

  [Function] An accessor function to get the Y value from a data item. This can be set for each individual layer or a default for the entire chart. Some plots support calling this accessor with the index of the data as well as the datum itself.

options =

      undefined

  [c3.Selection.Options] Options to set the class, classes, styles, events, and title for this layer.

handlers =

      undefined

  [Object] An object to setup event handlers to catch events triggered by this c3 layer. The keys represent event names and the values are the cooresponding handlers.

restyle =

      Layer

  Method to restyle this layer

## Instance Method Summary

- # (void) init(chart, g) Bound Internal function for the Plot to prepare the layer.
- # (void) size(width, height) Bound Resize the layer, but doesn't update the rendering, `resize()` should be used for that.
- # (void) update(origin) Bound Update the DOM bindings based on the new or modified data set
- # (void) draw(origin) Bound Position the DOM elements based on current scales.
- # (void) style(style_new) Bound Restyle existing items in the layer
- # (void) zoom() Bound Called when a layer needs to update from a zoom, decimated layers overload this
- # (void) redraw(origin = 'redraw') Bound Redraw just this layer
- # (void) scale() Bound Adjust domains for layer scales for any automatic domains.
- # (void) min_x() Bound
- # (void) max_x() Bound
- # (void) min_y() Bound
- # (void) max_y() Bound

## Constructor Details

# (void) constructor(opt)

## Instance Method Details

# (void) init(chart, g) Bound

Internal function for the Plot to prepare the layer.

# (void) size(width, height) Bound

Resize the layer, but doesn't update the rendering, `resize()` should be used for that.

# (void) update(origin) Bound

Update the DOM bindings based on the new or modified data set

# (void) draw(origin) Bound

Position the DOM elements based on current scales.

# (void) style(style_new) Bound

Restyle existing items in the layer

# (void) zoom() Bound

Called when a layer needs to update from a zoom, decimated layers overload this

# (void) redraw(origin = 'redraw') Bound

Redraw just this layer

# (void) scale() Bound

Note: Needs to happen after update() so that stacked layers are computed

Adjust domains for layer scales for any automatic domains. For layer-specific automatic domains the layer needs its own scale defined, it cannot update the chart's shared scale.

# (void) min_x() Bound

# (void) max_x() Bound

# (void) min_y() Bound

# (void) max_y() Bound

Quickly fuzzy find classes, mixins, methods, file:

- T Open fuzzy finder dialog

Control the navigation frame:

- L Toggle list view
- C Show class list
- I Show mixin list
- F Show file list
- M Show method list
- E Show extras list

You can focus and blur the search input:

- S Focus search input
- Esc Blur search input