(
axis: Axis,
scale: Scale,
rawExtentResult: ScaleRawExtentResultFinal,
ecModel: GlobalModel
)
| 773 | * @see SCALE_EXTENT_CONSTRUCTION for the full processing flow. |
| 774 | */ |
| 775 | export function adoptScaleExtentKindMapping( |
| 776 | axis: Axis, |
| 777 | scale: Scale, |
| 778 | rawExtentResult: ScaleRawExtentResultFinal, |
| 779 | ecModel: GlobalModel |
| 780 | ): void { |
| 781 | |
| 782 | if (!rawExtentResult.ctnShp) { |
| 783 | return; |
| 784 | } |
| 785 | |
| 786 | let linearSupplement: number[] | NullUndefined; |
| 787 | eachKeyOnAxis(axis, function (axisStatKey) { |
| 788 | const handler = axisContainShapeHandlerMap.get(axisStatKey); |
| 789 | if (handler) { |
| 790 | // This feature can be implemented by either expanding axis extent or scale extent. The choice depends |
| 791 | // on whether series shape sizes are defined in pixels or data space. For example, scatter series glyph |
| 792 | // sizes is mainly defined in pixel, while bar series `bandWidth` is mainly determined by given percents |
| 793 | // of data scale. Since currently scatter does not require this feature, we implement it only on the |
| 794 | // data scale. |
| 795 | const singleLinearSupplement = handler(axis, ecModel); |
| 796 | if (singleLinearSupplement) { |
| 797 | linearSupplement = linearSupplement || [0, 0]; |
| 798 | unionExtentStartFromNumber(linearSupplement, singleLinearSupplement[0]); |
| 799 | unionExtentEndFromNumber(linearSupplement, singleLinearSupplement[1]); |
| 800 | |
| 801 | // Consider the consistency of `onZero` behavior (not varying by series data; otherwise error-prone |
| 802 | // to users), if any `containShape` really performed on this axis, discourage `onZero`. |
| 803 | discourageOnAxisZero(axis); |
| 804 | } |
| 805 | } |
| 806 | }); |
| 807 | |
| 808 | if (!linearSupplement) { |
| 809 | return; |
| 810 | } |
| 811 | |
| 812 | const scaleExtent = scale.getExtent(); |
| 813 | |
| 814 | if (isOrdinalScale(scale)) { |
| 815 | if (!axis.onBand) { |
| 816 | // - Zooming on `OrdinalScale` auto "snaps" to integer ticks, which causes edge shapes to |
| 817 | // always overlap and be clipped at the boundaries. Therefore we always supplement it with |
| 818 | // half bandWith to avoid that overlapping. |
| 819 | // - `linearSupplement` is typically [-0.5, 0.5] in this case. `linearSupplement` exists only |
| 820 | // if any series call `registerAxisContainShapeHandler`. |
| 821 | // - PENDING: For historical reason, `onBand: true` has another implementation to handle |
| 822 | // this case. Merge them to this? |
| 823 | scale.setExtent2( |
| 824 | SCALE_EXTENT_KIND_MAPPING, |
| 825 | mathMin(scaleExtent[0], scaleExtent[0] + linearSupplement[0]), |
| 826 | mathMax(scaleExtent[1], scaleExtent[1] + linearSupplement[1]) |
| 827 | ); |
| 828 | } |
| 829 | } |
| 830 | else { |
| 831 | // For other cases, `SCALE_EXTENT_KIND_MAPPING` is only used on the full window of `dataZoom`, |
| 832 | // where the visual result is more intuitive when zooming: when dataZoom is applied and its ends |
no test coverage detected
searching dependent graphs…