* Returns the stacks based on groups and bar visibility. * @param {number} [last] - The dataset index * @param {number} [dataIndex] - The data index of the ruler * @returns {string[]} The list of stack IDs * @private
(last, dataIndex)
| 432 | * @private |
| 433 | */ |
| 434 | _getStacks(last, dataIndex) { |
| 435 | const {iScale} = this._cachedMeta; |
| 436 | const metasets = iScale.getMatchingVisibleMetas(this._type) |
| 437 | .filter(meta => meta.controller.options.grouped); |
| 438 | const stacked = iScale.options.stacked; |
| 439 | const stacks = []; |
| 440 | const currentParsed = this._cachedMeta.controller.getParsed(dataIndex); |
| 441 | const iScaleValue = currentParsed && currentParsed[iScale.axis]; |
| 442 | |
| 443 | const skipNull = (meta) => { |
| 444 | const parsed = meta._parsed.find(item => item[iScale.axis] === iScaleValue); |
| 445 | const val = parsed && parsed[meta.vScale.axis]; |
| 446 | |
| 447 | if (isNullOrUndef(val) || isNaN(val)) { |
| 448 | return true; |
| 449 | } |
| 450 | }; |
| 451 | |
| 452 | for (const meta of metasets) { |
| 453 | if (dataIndex !== undefined && skipNull(meta)) { |
| 454 | continue; |
| 455 | } |
| 456 | |
| 457 | // stacked | meta.stack |
| 458 | // | found | not found | undefined |
| 459 | // false | x | x | x |
| 460 | // true | | x | |
| 461 | // undefined | | x | x |
| 462 | if (stacked === false || stacks.indexOf(meta.stack) === -1 || |
| 463 | (stacked === undefined && meta.stack === undefined)) { |
| 464 | stacks.push(meta.stack); |
| 465 | } |
| 466 | if (meta.index === last) { |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | // No stacks? that means there is no visible data. Let's still initialize an `undefined` |
| 472 | // stack where possible invisible bars will be located. |
| 473 | // https://github.com/chartjs/Chart.js/issues/6368 |
| 474 | if (!stacks.length) { |
| 475 | stacks.push(undefined); |
| 476 | } |
| 477 | |
| 478 | return stacks; |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * Returns the effective number of stacks based on groups and bar visibility. |
no test coverage detected