dc@v5 Migration Guide

dc v5 Upgrade Guide

The library has been significantly refactored in v5. The code has been arranged around clearer separation of responsibilities. This has enabled fixing long-standing issues and enabled clean support for remote data sources.

The library is distributed in two variants:

  • dc.js — only the newer API, recommended for new projects.
  • dc-compat.js — v4 compatibility mode, which is close to the v4 API.

In certain cases, however, you would need to upgrade:

  • Only UMD bundles are distributed with compat option. If you were using ES6 modules, you would need to upgrade.
  • Support for newer features is not guaranteed in the compat mode. Mixing of newer APIs with older ones may produce unexpected results.
  • Some APIs are no longer available. Notably filterHandler, hasFilterHandler, addFilterHandler and removeFilterHandler. If your code relies on any of these, you would need to upgrade rewrite using newer features.

Please raise an issue on GitHub if you run into problems not covered here!

Key changes

Chart creation

This was introduced in v4. The older function-based methods were deprecated and now have been removed from v5.

Change dc.pieChart(parent, chartGroup)new dc.PieChart(parent, chartGroup)

Key/value pair configuration

Charts now support key/value configuration. This should simplify sharing configuration across charts easier.

For every chart, there is a corresponding interface that covers the list of supported options. For example, the interface for PieChart is IPieChartConf. The configure and conf will refer to this interface.

To use it:

// It will be merged with exisiting configuration
chart.configure({
minHeight: 250,
minWidth: 300
});

// it will return entire configuration
const conf = chart.conf();

// minHeight
chart.conf().minHeight;

List of accessors that have moved to conf:

Deprecated

Examples

DataProviders

The data related concerns are separated and provided by Data Adaptor classes. This will allow additional flexibility:

  • Filters are managed by the DataProvider, this allows more than one chart to use the same dimension without messing up filters.
  • Create stand alone dc charts without CrossFilter.
  • Ability to create dc dashboards with entire data on a remote server with zero hacks. A proof of concept with Elastic Search will be released very soon.
  • Make it possible to adapt charts created by other libraries to a dc dashboard (future plan).
  • Ability to save and restore filter state of the dc dashboard, including ability to preserve these across sessions.

DataProviders, are arranged in a class hierarchy with each layer handling a specific need:

See examples folder for complete examples.

Sample snippets:

const quarterChart = new dc.PieChart('#quarter-chart', chartGroup);
quarterChart.dataProvider(
new dc.CFSimpleAdapter({
dimension: quarter,
group: quarterGroup,
})
);

const chart = new dc.PieChart('#pie01', chartGroup);
chart.dataProvider(
new dc.CFDataCapHelper({
cap: 4,
dimension: runDimension,
group: speedSumGroup,
})
);

const moveChart = new dc.LineChart('#monthly-move-chart', chartGroup);
moveChart.dataProvider(
new dc.CFMultiAdapter({
dimension: moveMonths,
layers: [
// Add the first layer of the stack with group. The `name` is used for label in legends.
{
group: indexAvgByMonthGroup,
name: 'Monthly Index Average',
valueAccessor: d => d.value.avg,
},
{
// Stack additional layers with `.stack`. The first paramenter is a new group.
// The second parameter is the series name. The third is a value accessor.
group: monthlyMoveGroup,
name: 'Monthly Index Move',
valueAccessor: d => d.value,
},
],
})
);

How to use DataAdaptor

  1. Choose the appropriate class:
    1. If your chart supports stacks (currently BarChart and LineChart), you will need CFMultiAdapter.
    2. If you need to cap data number of entries in the chart, you will need CFDataCapHelper.
    3. In other cases you will need CFSimpleAdapter.
  2. Typically you will set dimesnion, group and valueAccessor. Please see ICFSimpleAdapterConf for all possible options.
  3. In addition, if you are using capping, you will also set cap. Please see ICFDataCapHelperConf for all possible options.
  4. For stack based charts, please set dimension and layers. Please see ICFMultiAdapterConf for all possible options. Also check the example above.

ChartGroup

ChartGroup is a key concept in dc. This links all charts so that filtering one of the charts causes updates in all linked charts. Up to dc@v4 ChartRegistry maintained these lists as global variables. This required deregisterAllCharts to be called to clear those references so that charts could be garbage collected. dc@v5 introduces ChartGroup, an instance of ChartGroup maintains list of all related charts. References to charts are no longer kept in global variables, so as soon as the chartObject instance and all chart instances go out of scope, these should get garbage collected without needing an explicit call to clear the list.

It is recommended that a chartGroup is explicitly created for better code structuring. If a chartGroup is not explicitly passed during chart creation, the instances will be linked to the default chartGroup, which is a global object.

In either case the chartGroup is available as an attribute in each of charts.

Example for ChartRegistry to ChartGroup

Generated using TypeDoc