* Note: pixel values are not clamped to the scale area. * @private
(index)
| 561 | * @private |
| 562 | */ |
| 563 | _calculateBarValuePixels(index) { |
| 564 | const {_cachedMeta: {vScale, _stacked, index: datasetIndex}, options: {base: baseValue, minBarLength}} = this; |
| 565 | const actualBase = baseValue || 0; |
| 566 | const parsed = this.getParsed(index); |
| 567 | const custom = parsed._custom; |
| 568 | const floating = isFloatBar(custom); |
| 569 | let value = parsed[vScale.axis]; |
| 570 | let start = 0; |
| 571 | let length = _stacked ? this.applyStack(vScale, parsed, _stacked) : value; |
| 572 | let head, size; |
| 573 | |
| 574 | if (length !== value) { |
| 575 | start = length - value; |
| 576 | length = value; |
| 577 | } |
| 578 | |
| 579 | if (floating) { |
| 580 | value = custom.barStart; |
| 581 | length = custom.barEnd - custom.barStart; |
| 582 | // bars crossing origin are not stacked |
| 583 | if (value !== 0 && sign(value) !== sign(custom.barEnd)) { |
| 584 | start = 0; |
| 585 | } |
| 586 | start += value; |
| 587 | } |
| 588 | |
| 589 | const startValue = !isNullOrUndef(baseValue) && !floating ? baseValue : start; |
| 590 | let base = vScale.getPixelForValue(startValue); |
| 591 | |
| 592 | if (this.chart.getDataVisibility(index)) { |
| 593 | head = vScale.getPixelForValue(start + length); |
| 594 | } else { |
| 595 | // When not visible, no height |
| 596 | head = base; |
| 597 | } |
| 598 | |
| 599 | size = head - base; |
| 600 | |
| 601 | if (Math.abs(size) < minBarLength) { |
| 602 | size = barSign(size, vScale, actualBase) * minBarLength; |
| 603 | if (value === actualBase) { |
| 604 | base -= size / 2; |
| 605 | } |
| 606 | const startPixel = vScale.getPixelForDecimal(0); |
| 607 | const endPixel = vScale.getPixelForDecimal(1); |
| 608 | const min = Math.min(startPixel, endPixel); |
| 609 | const max = Math.max(startPixel, endPixel); |
| 610 | base = Math.max(Math.min(base, max), min); |
| 611 | head = base + size; |
| 612 | |
| 613 | if (_stacked && !floating) { |
| 614 | // visual data coordinates after applying minBarLength |
| 615 | parsed._stacks[vScale.axis]._visualValues[datasetIndex] = vScale.getValueForPixel(head) - vScale.getValueForPixel(base); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | if (base === vScale.getPixelForValue(actualBase)) { |
| 620 | const halfGrid = sign(size) * vScale.getLineWidthForValue(actualBase) / 2; |
no test coverage detected