(
rawExtent: number[],
fixMinMax: ScaleExtentFixMinMax,
rawExtentResult?: ScaleRawExtentResultFinal | NullUndefined
)
| 222 | * in "nice" and "align" ticks. |
| 223 | */ |
| 224 | export function intervalScaleEnsureValidExtent( |
| 225 | rawExtent: number[], |
| 226 | fixMinMax: ScaleExtentFixMinMax, |
| 227 | rawExtentResult?: ScaleRawExtentResultFinal | NullUndefined |
| 228 | ): number[] { |
| 229 | const extent = rawExtent.slice(); |
| 230 | |
| 231 | // PENDING: |
| 232 | // This implementation is not rigorous, but has long been in use. |
| 233 | |
| 234 | // If extent start and end are same, expand them |
| 235 | if (extent[0] === extent[1]) { |
| 236 | // If `containShape`, the extent must be evenly distributed to both sides; |
| 237 | // otherwise, shape (e.g., bars) may be overflow and clipped. |
| 238 | const containShapeRequired = rawExtentResult && rawExtentResult.ctnShp; |
| 239 | |
| 240 | if (extent[0] !== 0) { |
| 241 | // Expand extent |
| 242 | // Note that extents can be both negative. See #13154 |
| 243 | const expandSize = mathAbs(extent[0]); |
| 244 | // In the fowllowing case |
| 245 | // Axis has been fixed max 100 |
| 246 | // Plus data are all 100 and axis extent are [100, 100]. |
| 247 | // Extend to the both side will cause expanded max is larger than fixed max. |
| 248 | // So only expand to the smaller side. |
| 249 | if (!fixMinMax[1]) { |
| 250 | extent[1] += expandSize / 2; |
| 251 | extent[0] -= expandSize / 2; |
| 252 | } |
| 253 | else { |
| 254 | extent[0] -= expandSize / 2; |
| 255 | } |
| 256 | } |
| 257 | else { |
| 258 | if (containShapeRequired) { |
| 259 | extent[0] = -1; |
| 260 | extent[1] = 1; |
| 261 | } |
| 262 | else { |
| 263 | extent[1] = 1; |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | // For example, if there are no series data, extent may be `[Infinity, -Infinity]` here. |
| 268 | if (!isValidNumberForExtent(extent[0]) || !isValidNumberForExtent(extent[1])) { |
| 269 | extent[0] = 0; |
| 270 | extent[1] = 1; |
| 271 | } |
| 272 | if (extent[1] < extent[0]) { |
| 273 | extent.reverse(); |
| 274 | } |
| 275 | |
| 276 | return extent; |
| 277 | } |
| 278 | |
| 279 | export function extentDiffers(extent1: number[], extent2: number[]): boolean[] { |
| 280 | return [extent1[0] !== extent2[0], extent1[1] !== extent2[1]]; |
no test coverage detected
searching dependent graphs…