return keys;
}
-function applyStack(stack, value, dsIndex, options) {
+function applyStack(stack, value, dsIndex, options = {}) {
const keys = stack.keys;
const singleMode = options.mode === 'single';
let i, ilen, datasetIndex, otherValue;
const isDirectUpdateMode = (mode) => mode === 'reset' || mode === 'none';
const cloneIfNotShared = (cached, shared) => shared ? cached : Object.assign({}, cached);
+const createStack = (canStack, meta, chart) => canStack && !meta.hidden && meta._stacked
+ && {keys: getSortedDatasetIndices(chart, true), values: null};
export default class DatasetController {
const values = stack && parsed._stacks[scale.axis];
if (stack && values) {
stack.values = values;
- // Need to consider individual stack values for data range,
- // in addition to the stacked value
- range.min = Math.min(range.min, value);
- range.max = Math.max(range.max, value);
- value = applyStack(stack, parsedValue, this._cachedMeta.index, {all: true});
+ value = applyStack(stack, parsedValue, this._cachedMeta.index);
}
range.min = Math.min(range.min, value);
range.max = Math.max(range.max, value);
const sorted = meta._sorted && scale === meta.iScale;
const ilen = _parsed.length;
const otherScale = this._getOtherScale(scale);
- const stack = canStack && meta._stacked && {keys: getSortedDatasetIndices(this.chart, true), values: null};
+ const stack = createStack(canStack, meta, this.chart);
const range = {min: Number.POSITIVE_INFINITY, max: Number.NEGATIVE_INFINITY};
const {min: otherMin, max: otherMax} = getUserBounds(otherScale);
- let i, value, parsed, otherValue;
+ let i, parsed;
function _skip() {
parsed = _parsed[i];
- value = parsed[scale.axis];
- otherValue = parsed[otherScale.axis];
- return !isFinite(value) || otherMin > otherValue || otherMax < otherValue;
+ const otherValue = parsed[otherScale.axis];
+ return !isFinite(parsed[scale.axis]) || otherMin > otherValue || otherMax < otherValue;
}
for (i = 0; i < ilen; ++i) {
expect(createChart).not.toThrow();
});
+ it('should find min and max for stacked chart', function() {
+ var chart = window.acquireChart({
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [10, 11, 12, 13]
+ }, {
+ data: [1, 2, 3, 4]
+ }],
+ labels: ['a', 'b', 'c', 'd']
+ },
+ options: {
+ scales: {
+ y: {
+ stacked: true
+ }
+ }
+ }
+ });
+ expect(chart.getDatasetMeta(0).controller.getMinMax(chart.scales.y, true)).toEqual({min: 10, max: 13});
+ expect(chart.getDatasetMeta(1).controller.getMinMax(chart.scales.y, true)).toEqual({min: 11, max: 17});
+ chart.hide(0);
+ expect(chart.getDatasetMeta(0).controller.getMinMax(chart.scales.y, true)).toEqual({min: 10, max: 13});
+ expect(chart.getDatasetMeta(1).controller.getMinMax(chart.scales.y, true)).toEqual({min: 1, max: 4});
+ });
+
it('Should create line elements and point elements for each data item during initialization', function() {
var chart = window.acquireChart({
type: 'line',