Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixed chart #5134

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make sure the all the chart options are taken into account
  • Loading branch information
loicbourgois committed Jan 14, 2018
commit 8ea9ee6a4ae45e383fc40c3145b2d9b4759445c5
38 changes: 30 additions & 8 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,48 @@ module.exports = function(Chart) {


// Merge options for mixed charts
// If there is at least one 'bar' chart, main type is set to 'bar'
// If the main chart has no type and there's no 'bar' child chart,
// we set the main chart to 'line'
// This way, users can use a mixed chart without having to set a main type
// Some charts are more compatible than others
// For example, childs 'line' work with 'bar' parent, but not the opposite
// The typesByPriotity array ensure that the less compatibles chart are used
// in priority for the parent chart.
// So if there is at least one 'bar' chart, main type is set to 'bar'
// If no type at all is set, we use 'line'
// Users can use a mixed chart without having to set a main type
// and it alows more compatibility between charts
var types = [];
var typesByPriotity = [
'bar',
'line',
'scatter',
'horizontalBar',
'bubble'
'bubble',
'doughnut',
'global',
'pie',
'polarArea',
'radar',
'scale',
];
var defaultType = 'line';
var mainType;
types.push(config.type); // necessary if parent type is set and some children ar not
// Ensure that charts added in plugins will have top priority
for (var key in defaults) {
if(!typesByPriotity.includes(key)) {
typesByPriotity.unshift(key);
}
}

// Necessary if parent type is set and some identical children ar not
// relying on the fact that the parent type is already set
// Example: 'bar' parent with childs [undefined, undefined, line]
types.push(config.type);

if (data && data.datasets) {
data.datasets.forEach(function(dataset) {
types.push(dataset.type);
});
}

var defaultType = 'line';
var mainType;
for (var i = 0; i < typesByPriotity.length; i++) {
if (types.includes(typesByPriotity[i])) {
mainType = typesByPriotity[i];
Expand Down