Skip to content

Commit

Permalink
Better handling of mixed line / scatter charts
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jan 15, 2018
1 parent e585c75 commit 949ab1a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
13 changes: 6 additions & 7 deletions src/controllers/controller.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var elements = require('../elements/index');
var helpers = require('../helpers/index');

defaults._set('line', {
showLines: true,
spanGaps: false,

hover: {
Expand All @@ -26,10 +25,6 @@ defaults._set('line', {

module.exports = function(Chart) {

function lineEnabled(dataset, options) {
return helpers.valueOrDefault(dataset.showLine, options.showLines);
}

Chart.controllers.line = Chart.DatasetController.extend({

datasetElementType: elements.Line,
Expand All @@ -46,7 +41,7 @@ module.exports = function(Chart) {
var scale = me.getScaleForId(meta.yAxisID);
var i, ilen, custom;
var dataset = me.getDataset();
var showLine = lineEnabled(dataset, options);
var showLine = me.lineEnabled(dataset, options);

// Update Line
if (showLine) {
Expand Down Expand Up @@ -287,7 +282,7 @@ module.exports = function(Chart) {

helpers.canvas.clipArea(chart.ctx, area);

if (lineEnabled(me.getDataset(), chart.options)) {
if (me.lineEnabled(me.getDataset(), chart.options)) {
meta.dataset.draw();
}

Expand Down Expand Up @@ -328,6 +323,10 @@ module.exports = function(Chart) {
model.backgroundColor = me.getPointBackgroundColor(point, index);
model.borderColor = me.getPointBorderColor(point, index);
model.borderWidth = me.getPointBorderWidth(point, index);
},

lineEnabled: function(dataset, options) {
return helpers.valueOrDefault(dataset.showLine, helpers.valueOrDefault(options.showLines, true));
}
});
};
10 changes: 6 additions & 4 deletions src/controllers/controller.scatter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var defaults = require('../core/core.defaults');
var helpers = require('../helpers/index');

defaults._set('scatter', {
hover: {
Expand All @@ -20,8 +21,6 @@ defaults._set('scatter', {
}]
},

showLines: false,

tooltips: {
callbacks: {
title: function() {
Expand All @@ -36,7 +35,10 @@ defaults._set('scatter', {

module.exports = function(Chart) {

// Scatter charts use line controllers
Chart.controllers.scatter = Chart.controllers.line;
Chart.controllers.scatter = Chart.controllers.line.extend({
lineEnabled: function(dataset, options) {
return helpers.valueOrDefault(dataset.showLine, helpers.valueOrDefault(options.showLines, false));
}
});

};
1 change: 0 additions & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ defaults._set('global', {
defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
defaultFontSize: 12,
defaultFontStyle: 'normal',
showLines: true,

// Element defaults defined in element extensions
elements: {},
Expand Down

0 comments on commit 949ab1a

Please sign in to comment.