mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-07 12:49:07 +02:00
4b421a50bf
The `fill` option now accepts the index of the target dataset (number) or a string starting by "+" or "-" followed by a number representing the dataset index relative to the current one (e.g. `fill: "-2"` on dataset at index 3 will fill to dataset at index 1). It's also possible to "propagate" the filling to the target of an hidden dataset (`options.plugins.filler.propagate`). Fill boundaries `zero`, `top` and `bottom` have been deprecated and replaced by `origin`, `start` and `end`. Implementation has been moved out of the line element into a new plugin (`src/plugins/plugin.filler.js`) and does not rely anymore on the deprecated model `scaleTop`, `scaleBottom` and `scaleZero` values. Drawing Bézier splines has been refactored in the canvas helpers (note that `Chart.helpers.canvas` is now an alias of `Chart.canvasHelpers`). Add 3 new examples and extend utils with a pseudo-random number generator that can be initialized with `srand`. That makes possible to design examples starting always with the same initial data.
67 lines
1.4 KiB
JavaScript
67 lines
1.4 KiB
JavaScript
/* global Chart */
|
|
|
|
'use strict';
|
|
|
|
(function() {
|
|
Chart.plugins.register({
|
|
id: 'samples_filler_analyser',
|
|
|
|
beforeInit: function(chart, options) {
|
|
this.element = document.getElementById(options.target);
|
|
},
|
|
|
|
afterUpdate: function(chart) {
|
|
var datasets = chart.data.datasets;
|
|
var element = this.element;
|
|
var stats = [];
|
|
var meta, i, ilen, dataset;
|
|
|
|
if (!element) {
|
|
return;
|
|
}
|
|
|
|
for (i=0, ilen=datasets.length; i<ilen; ++i) {
|
|
meta = chart.getDatasetMeta(i).$filler;
|
|
if (meta) {
|
|
dataset = datasets[i];
|
|
stats.push({
|
|
fill: dataset.fill,
|
|
target: meta.fill,
|
|
visible: meta.visible,
|
|
index: i
|
|
});
|
|
}
|
|
}
|
|
|
|
this.element.innerHTML = '<table>' +
|
|
'<tr>' +
|
|
'<th>Dataset</th>' +
|
|
'<th>Fill</th>' +
|
|
'<th>Target (visibility)</th>' +
|
|
'</tr>' +
|
|
stats.map(function(stat) {
|
|
var target = stat.target;
|
|
var row =
|
|
'<td><b>' + stat.index + '</b></td>' +
|
|
'<td>' + JSON.stringify(stat.fill) + '</td>';
|
|
|
|
if (target === false) {
|
|
target = 'none';
|
|
} else if (isFinite(target)) {
|
|
target = 'dataset ' + target;
|
|
} else {
|
|
target = 'boundary "' + target + '"';
|
|
}
|
|
|
|
if (stat.visible) {
|
|
row += '<td>' + target + '</td>';
|
|
} else {
|
|
row += '<td>(hidden)</td>';
|
|
}
|
|
|
|
return '<tr>' + row + '</tr>';
|
|
}).join('') + '</table>';
|
|
}
|
|
});
|
|
}());
|