# Class: c3.Plot.Layer.Stackable Abstract

Defined in: | js/c3-layers.coffee
Inherits: | c3.Plot.Layer

## Overview

This class is abstract.
Note: If stacked, the input datasets may not have duplicate values in the same stack for the same X value. There are other resitrictions if `safe` mode is not used.
Note: If you do not provide data elements for all stacks at all x values, then be prepared for your accessor callbacks to be called with null objects.

An abstract class for layers that support stacking such as c3.Plot.Layer.Path and c3.Plot.Layer.Bar.

Stacking allows the user to group their data into different stacks, which are stacked on top of each other in the chart. Stacking is enabled when you define either `stack_options.key`, `stacks`, or both options. `stack_options` allows you to configure how stacking is performed from the layer's data, while `stacks` allows you to manually configure the exact set of stacks.

This layer stacking is flexible to support several different ways of organizing the dataset into stacks:

- For normalized datasets you can define a `stack_options.key()` accessor to provide a key that uniquely identifies which stack an element belongs to.
- Otherwise, you can manually define the set of `stacks` and the layer's `data` is copied into each.
- - The layer `y` accessor will be called with the arguments (datum,index,stack) for you to provide the value for that element for that stack.
- - Or, you can define a `y` accessor for each stack to get the value for that element for that stack.
- You can also directly define `data` in each stack specified in `stacks`.

Please view the examples for more explanation on how to stack data. Remember, the set and order or stacks can always be programmatically constructed and dynamically updated.

## Extensibility

The following c3.Selection members are made available if appropriate:

- groups - An entry will exist for an svg:g node for each stack in the layer

### Author:

- Douglas Armstrong

### See also:

- ../../../examples/doc/stack_example.html

## Direct Known Subclasses

c3.Plot.Layer.Path c3.Plot.Layer.Bar

## Variables Summary

version =

      0.2

type =

      'stackable'

stack_options =

      undefined

  [c3.Selection.Options] Enable stacking and specify stacking options for this layer. This provides the normal c3.Selection.Options applied to each stack in the layer. For callbacks, the first argument is the stack object and the second argument is the index to the stack In addition, the following options control stacking behaviour:

  - key [Function] An accessor you can define to return a key that uniquely identifies which stack a data element belongs to. If this is specified, then this callback is used to determine which stack each data element is assigned to. Otherwise, the layer data array is used in full for each stack.
  - name [Function] A callback you define to set the name of a stack that is passed the stack key as an argument.
  - offset [String, Function] The name or a function for the stacking algorithm used to place the data. See d3.stack.offset() for details.
  - - `zero` - The default for a zero baseline.
  - - `expand` - Normalize all points to range from 0-1.
  - order [String] Specify the mechanism to order the stacks. See d3.stack.order() for details.
stacks =

      undefined

  [Array<c3.Plot.Layer.Stackable.Stack>] An array of stack objects that can be used to manually specify the set of stacks. Stack objects may contain:

  - key [String] The key for this stack
  - y [Function] A y accessor to use for this stack overriding the one provided by the chart or layer.
  - data [Array] Manually specified dataset for this stack instead of using the layer's `data`.
  - name [String] Name for the stack
  - options [c3.Selection.Options] Options to manually set the class, classes, styles, events, and title of just this stack.
safe =

      true

  [Boolean] Safe Mode. Preform additional checks and fix up the data for situations such as:

  - Data not sorted along X axis
  - Remove data elements where X or Y values are undefined
  - Pad missing values where stacks are not defined for all X values. Note that this mode may cause the indexes passed to the accessors to match the corrected data instead of the original data array.

### Variable inherited from c3.Plot.Layer

version type _next_uid data name class static_data h v x y options handlers restyle

## Instance Method Summary

- # (void) _stack() Bound Restack the data based on the stack and stacks options.
- # (void) _update() Bound
- # (void) _style(style_new) Bound
- # (void) min_x() Bound
- # (void) max_x() Bound
- # (void) min_y() Bound
- # (void) max_y() Bound

## Inherited Method Summary

### Methods inherited from c3.Plot.Layer

#init #size #update #draw #style #zoom #redraw #scale #min_x #max_x #min_y #max_y

## Instance Method Details

# (void) _stack() Bound

Restack the data based on the stack and stacks options.

# (void) _update() Bound

# (void) _style(style_new) Bound

# (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