mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-07 20:59:08 +02:00
Merge pull request #1887 from mathiask88/v2.0-dev
Add option to disable line drawing
This commit is contained in:
commit
b756507625
@ -120,6 +120,7 @@ The default options for line chart are defined in `Chart.defaults.Line`.
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- | --- | --- | ---
|
||||
showLines | Boolean | true | If false, the lines between points are not drawn
|
||||
stacked | Boolean | false | If true, lines stack on top of each other along the y axis.
|
||||
*hover*.mode | String | "label" | Label's hover mode. "label" is used since the x axis displays data by the index in the dataset.
|
||||
scales | - | - | -
|
||||
|
@ -7,6 +7,8 @@
|
||||
helpers = Chart.helpers;
|
||||
|
||||
Chart.defaults.line = {
|
||||
showLines: true,
|
||||
|
||||
hover: {
|
||||
mode: "label"
|
||||
},
|
||||
@ -58,6 +60,7 @@
|
||||
this.getDataset().metaData.splice(index, 0, point);
|
||||
|
||||
// Make sure bezier control points are updated
|
||||
if (this.chart.options.showLines)
|
||||
this.updateBezierControlPoints();
|
||||
},
|
||||
|
||||
@ -78,6 +81,7 @@
|
||||
}
|
||||
|
||||
// Update Line
|
||||
if (this.chart.options.showLines) {
|
||||
helpers.extend(line, {
|
||||
// Utility
|
||||
_scale: yScale,
|
||||
@ -103,12 +107,14 @@
|
||||
},
|
||||
});
|
||||
line.pivot();
|
||||
}
|
||||
|
||||
// Update Points
|
||||
helpers.each(points, function(point, index) {
|
||||
this.updateElement(point, index, reset);
|
||||
}, this);
|
||||
|
||||
if (this.chart.options.showLines)
|
||||
this.updateBezierControlPoints();
|
||||
},
|
||||
|
||||
@ -258,6 +264,7 @@
|
||||
}, this);
|
||||
|
||||
// Transition and Draw the line
|
||||
if (this.chart.options.showLines)
|
||||
this.getDataset().metaDataset.transition(easingDecimal).draw();
|
||||
|
||||
// Draw the points
|
||||
|
@ -87,6 +87,7 @@ describe('Line controller tests', function() {
|
||||
type: 'line'
|
||||
},
|
||||
options: {
|
||||
showLines: true,
|
||||
scales: {
|
||||
xAxes: [{
|
||||
id: 'firstXScaleID'
|
||||
@ -114,6 +115,45 @@ describe('Line controller tests', function() {
|
||||
expect(chart.data.datasets[0].metaData[3].draw.calls.count()).toBe(1);
|
||||
});
|
||||
|
||||
it('should draw all elements except lines', function() {
|
||||
var chart = {
|
||||
data: {
|
||||
datasets: [{
|
||||
data: [10, 15, 0, -4]
|
||||
}]
|
||||
},
|
||||
config: {
|
||||
type: 'line'
|
||||
},
|
||||
options: {
|
||||
showLines: false,
|
||||
scales: {
|
||||
xAxes: [{
|
||||
id: 'firstXScaleID'
|
||||
}],
|
||||
yAxes: [{
|
||||
id: 'firstYScaleID'
|
||||
}]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var controller = new Chart.controllers.line(chart, 0);
|
||||
|
||||
spyOn(chart.data.datasets[0].metaDataset, 'draw');
|
||||
spyOn(chart.data.datasets[0].metaData[0], 'draw');
|
||||
spyOn(chart.data.datasets[0].metaData[1], 'draw');
|
||||
spyOn(chart.data.datasets[0].metaData[2], 'draw');
|
||||
spyOn(chart.data.datasets[0].metaData[3], 'draw');
|
||||
|
||||
controller.draw();
|
||||
|
||||
expect(chart.data.datasets[0].metaDataset.draw.calls.count()).toBe(0);
|
||||
expect(chart.data.datasets[0].metaData[0].draw.calls.count()).toBe(1);
|
||||
expect(chart.data.datasets[0].metaData[2].draw.calls.count()).toBe(1);
|
||||
expect(chart.data.datasets[0].metaData[3].draw.calls.count()).toBe(1);
|
||||
});
|
||||
|
||||
it('should update elements', function() {
|
||||
var data = {
|
||||
datasets: [{
|
||||
@ -177,6 +217,7 @@ describe('Line controller tests', function() {
|
||||
type: 'line'
|
||||
},
|
||||
options: {
|
||||
showLines: true,
|
||||
elements: {
|
||||
line: {
|
||||
backgroundColor: 'rgb(255, 0, 0)',
|
||||
|
Loading…
Reference in New Issue
Block a user