dc-addons
These dc.js addons provide new charts for the dc namespace.
Addons
- Leaflet.js
- Google Maps
- Tooltip Mixin
- Pagination Mixin
- Bubble Cloud
- Paired Row
- Server
- AngularJS Directives
- Crossfilter Server
- Crossfilter Server With Elastic Search
Installation
bower install dc-addons --savenpm install dc-addons --save
You can either include all addons or each on individually as you need them. To see examples of individual addons see each addon below. The following example will include all addons.
<!-- dc-addons requirements -->script> <!-- dc-addons -->
Leaflet.js
This extension provides support for dc.js charts in a leaflet.js map. This is an extension of https://github.com/yurukov/dc.leaflet.js updated to work with dc.js version 2.
Usage
There are two charts currently implemented - markers and choropleth. They extend the base abstract leaflet chart. Both support selection of datapoints and update in real time. Styling and map options can be set directly to the map object and though functions in the chart. Check the Leaflet reference for more information on the specific map, marker and geojson options. Location can be set as either 'lat,lng' string or as an array [lat,lng].
Marker Chart
Each group is presented as one marker on the map.
dc.leafletMarkerChart(parent,chartGroup)
.mapOptions({..}) - set leaflet specific options to the map object; Default: Leaflet default options
.center([1.1,1.1]) - initial location
.zoom(7) - initial zoom level
.map() - get map object
.locationAccessor() - function (d) to access the property indicating the latlng (string or array); Default: keyAccessor
.marker() - set function (d,map) to build the marker object. Default: standard Leaflet marker is built
.icon() - function (d,map) to build an icon object. Default: L.Icon.Default
.popup() - function (d,marker) to return the string or DOM content of a popup
.renderPopup(true) - set if popups should be shown; Default: true
.cluster(false) - set if markers should be clustered. Requires leaflet.markercluster.js; Default: false
.clusterObject({..}) - options for the markerCluster object
.rebuildMarkers(false) - set if all markers should be rebuild each time the map is redrawn. Degrades performance; Default: false
.brushOn(true) - if the map would select datapoints; Default: true
.filterByArea(false) - if the map should filter data based on the markers inside the zoomed in area instead of the user clicking on individual markers; Default: false
.markerGroup() - get the Leaflet group object containing all shown markers (regular group or cluster)
.popupOnHover(false) - whether or not to display the popup when hovering the marker instead of click; Default: false
.title() - The html title attribute of the markers
.fitOnRender(true) - Whether or not to automatically position the map to fit all markers on the display after the initial rendering; Default: true
.fitOnRedraw(false) - Whether or not to automatically position the map to fit all markers on the display after the markers have been cross filtered; Default: false
.tiles() - function (map) return a new L.tileLayer object to set a custom tile;
Choropleth Chart
Each group is mapped to an feature on the map
dc.leafletChoroplethChart(parent,chartGroup)
.mapOptions({..}) - set leaflet specific options to the map object; Default: Leaflet default options
.center([1.1,1.1]) - get or set initial location
.zoom(7) - get or set initial zoom level
.map() - get map object
.geojson() - geojson object describing the features
.featureOptions() - object or a function (feature, v) to set the options for each feature - warning this will override the d3 color scheming
.featureKeyAccessor() - function (feature) to return a feature property that would be compared to the group key; Defauft: feature.properties.key
.popup() - function (d,feature) to return the string or DOM content of a popup
.renderPopup(true) - set if popups should be shown; Default: true
.brushOn(true) - if the map would select datapoints; Default: true
.legend(dc.leafletLegend().position('bottomright'))
Custom Chart
Gives you full control over what is displayed on the map
dc.leafletCustomChart(parent,chartGroup)
.mapOptions({..}) - set leaflet specific options to the map object; Default: Leaflet default options
.center([1.1,1.1]) - initial location
.zoom(7) - initial zoom level
.map() - get map object
.locationAccessor() - function (d) to access the property indicating the latlng (string or array); Default: keyAccessor
.renderItem() - function (chart, map, d, i) the initial rendering of the map
.redrawItem() - function (chart, map, d, i) run on every crossfilter. The d object will have a filtered value added to it.
Examples
Requirements
These are the requirements for the dc leaflet charts. Ther version number supplied is the version supported when created. It could work with later versions.
- leaflet.js v0.7.2
<!--- through bower --> <!--- through cdn -->
- leaflet.markercluster.js v0.4.0 (in case you use the cluster option)
<!--- through bower --> <!--- through cdn -->
If you want to include individually
Google Maps
This extension provides support for dc.js charts in a google map. This is an extension of https://github.com/yurukov/dc.leaflet.js modified to work with google maps and dc.js version 2.
Usage
There are two charts currently implemented - markers and choropleth. They extend the base abstract google chart. Both support selection of datapoints and update in real time. Styling and map options can be set directly to the map object and though functions in the chart. Check the Google maps reference for more information on the specific map, marker and geojson options. Location can be set as either 'lat,lng' string or as an array [lat,lng].
Marker Chart
Each group is presented as one marker on the map.
dc.googleMarkerChart(parent,chartGroup)
.mapOptions({..}) - set google maps specific options to the map object; Default: Google maps default options
.center([1.1,1.1]) - initial location
.zoom(7) - initial zoom level
.map() - get map object
.locationAccessor() - function (d) to access the property indicating the latlng (string or array); Default: keyAccessor
.marker() - set function (d,map) to build the marker object. Default: standard Google map marker is built
.icon() - function (d,map) to build an icon object. Default: L.Icon.Default
.popup() - function (d,marker) to return the string or DOM content of a popup
.renderPopup(true) - set if popups should be shown; Default: true
.cluster(false) - set if markers should be clustered. Requires markerclusterer; Default: false
.clusterObject({..}) - options for the markerCluster object
.rebuildMarkers(false) - set if all markers should be rebuild each time the map is redrawn. Degrades performance; Default: false
.brushOn(true) - if the map would select datapoints; Default: true
.filterByArea(false) - if the map should filter data based on the markers inside the zoomed in area instead of the user clicking on individual markers; Default: false
.markerGroup() - get the Google maps group object containing all shown markers (regular group or cluster)
.title() - The html title attribute of the markers
.fitOnRender(true) - Whether or not to automatically position the map to fit all markers on the display after the initial rendering; Default: true
.fitOnRedraw(false) - Whether or not to automatically position the map to fit all markers on the display after the markers have been cross filtered; Default: false
Choropleth Chart
Each group is mapped to an feature on the map
dc.googleChoroplethChart(parent,chartGroup)
.mapOptions({..}) - set google maps specific options to the map object; Default: Google maps default options
.center([1.1,1.1]) - get or set initial location
.zoom(7) - get or set initial zoom level
.map() - get map object
.geojson() - geojson object describing the features
.featureOptions() - object or a function (feature) to set the options for each feature
.featureKeyAccessor() - function (feature) to return a feature property that would be compared to the group key; Defauft: feature.properties.key
.popup() - function (d,feature) to return the string or DOM content of a popup
.renderPopup(true) - set if popups should be shown; Default: true
.brushOn(true) - if the map would select datapoints; Default: true
Custom Chart
Gives you full control over what is displayed on the map
dc.googleCustomChart(parent,chartGroup)
.mapOptions({..}) - set google specific options to the map object; Default: Google default options
.center([1.1,1.1]) - initial location
.zoom(7) - initial zoom level
.map() - get map object
.locationAccessor() - function (d) to access the property indicating the latlng (string or array); Default: keyAccessor
.renderItem() - function (chart, map, d, i) the initial rendering of the map
.redrawItem() - function (chart, map, d, i) run on every crossfilter. The d object will have a filtered value added to it.
Examples
Requirements
<!--- through cdn -->
<!--- through cdn -->script>
If you want to include individually
Tooltip Mixin
This allows you to add html and style the chart title
Usage
After you have rendered the chart than run the tooltip mixin on the chart
var chart = dc;// set options...chart; dc;
Examples
Coming soon...
Requirements
<!-- through bower --><!-- through cdn -->
If you want to include individually
Pagination Mixin
This allows you to paginate a chart
Usage
After you have rendered the chart than run the pagination mixin on the chart
var chart = dc;// set options...chart; dc;
Examples
Requirements
None
If you want to include individually
Bubble Cloud
Usage
var chart = dc; // required optionschart width500 height500 xd3scale // optional optionschart label { return dkey; } title { return dkey + ': ' + dvalue; }
Examples
Requirements
None
If you want to include individually
Paired Row
Two row charts beside each other, usually used for gender/age breakdowns
Usage
var chart = dc; // the dimension is required to return an arrayvar ndx = ageGenderDimension = ndx ageGenderGroup = ageGenderDimension; // required optionschart width500 height500 // tells the left chart to filter the data based on this function // tells the right chart to filter the data based on this function // optional options - this chart extends dc.rowChart, so it has all the same options.
Demo
Requirements
None
If you want to include individually
Server
Charts generated on the server for large datasets. Only the following charts currently work:
- Pie
- Bar
- Row
- Line
Usage
var chart = dc; chart options // required options server: 'http://127.0.0.1:3000/' name: 'my-chart' // The name of the object in the config file // optional options errorMessage: 'A problem occurred creating the charts. Please try again later' loadingMessage: 'Loading' reconnectingMessage: 'There appears to be a problem connecting to the server. Retyring...' connectionErrorMessage: 'Could not connect to the server.' ;
To get the server running
iojs index [full path to server-config.js]
The server-config.js file should look something like this.
var dc = ; moduleexports = 'my-chart': connection: host: 'localhost' username: 'root' password: 'password' database: 'my-database' sql: 'SELECT * FROM members' charts: type: 'pieChart' options: width: 250 height: 250 margins: top: 30 right: 50 bottom: 25 left: 40 { if dgender === 0 return 'Male'; else if dgender === 1 return 'Female'; return 'Unknown'; } { return dimension; } ;
Demo
You will need to clone and run the server locally for an example
Requirements
npm install iojs -g
- dc-addons
npm install dc-addons --save
If you want to include individually
AngularJS Directives
Angular directives for creating charts
Usage
Include the angular module AngularDc
angular;
Create the chart. Chart options will be an object of all the charts settings.
Demo
Coming soon...
Requirements
bower install angularjs --save
If you want to include individually
Crossfilter Server
A shell for crossfilter to allow all calculations to happen on the server.
Usage
If the normal crossfilter library is not included, this library will take the crossfilter namespace.
chart; chart;
Demo
You will need to clone and run the server locally for an example
Requirements
None
If you want to include individually
Crossfilter Server With Elastic Search
Helper functions to integration dc.js charts with elastic search.
Usage
If the normal crossfilter library is not included, this library will take the crossfilter namespace.
var query = aggs: date: date_histogram: field: 'date_field' interval: '1d' site: histogram: field: 'site_id' interval: 1 ; // when filtering a chart, the chart with the integer id will filter the values base on the given field var mapping = 1: 'date_field' 2: 'site_id' ; var url = 'http://localhost:9200/_search'; chart; chart;
Demo
You will need to clone and run the server locally for an example
Requirements
None
If you want to include individually