(
// raw user input breaks, retrieved from axis model.
breakOptionList: AxisBreakOption[] | NullUndefined,
scale: {parse: Scale['parse']},
opt?: ParseBreakOptionOpt
)
| 506 | } |
| 507 | |
| 508 | function parseAxisBreakOption( |
| 509 | // raw user input breaks, retrieved from axis model. |
| 510 | breakOptionList: AxisBreakOption[] | NullUndefined, |
| 511 | scale: {parse: Scale['parse']}, |
| 512 | opt?: ParseBreakOptionOpt |
| 513 | ): AxisBreakParsingResult { |
| 514 | const parsedBreaks: ParsedAxisBreakList = []; |
| 515 | |
| 516 | if (!breakOptionList) { |
| 517 | return {breaks: parsedBreaks}; |
| 518 | } |
| 519 | |
| 520 | function validatePercent(normalizedPercent: number, msg: string): boolean { |
| 521 | if (normalizedPercent >= 0 && normalizedPercent < 1 - 1e-5) { // Avoid division error. |
| 522 | return true; |
| 523 | } |
| 524 | if (__DEV__) { |
| 525 | error(`${msg} must be >= 0 and < 1, rather than ${normalizedPercent} .`); |
| 526 | } |
| 527 | return false; |
| 528 | } |
| 529 | |
| 530 | each(breakOptionList, brkOption => { |
| 531 | if (!brkOption || brkOption.start == null || brkOption.end == null) { |
| 532 | if (__DEV__) { |
| 533 | error('The input axis breaks start/end should not be empty.'); |
| 534 | } |
| 535 | return; |
| 536 | } |
| 537 | if (brkOption.isExpanded) { |
| 538 | return; |
| 539 | } |
| 540 | |
| 541 | const parsedBrk: ParsedAxisBreak = { |
| 542 | breakOption: clone(brkOption), |
| 543 | vmin: scale.parse(brkOption.start), |
| 544 | vmax: scale.parse(brkOption.end), |
| 545 | gapParsed: {type: 'tpAbs', val: 0}, |
| 546 | gapReal: null |
| 547 | }; |
| 548 | |
| 549 | if (brkOption.gap != null) { |
| 550 | let isPrct = false; |
| 551 | if (isString(brkOption.gap)) { |
| 552 | const trimmedGap = trim(brkOption.gap); |
| 553 | if (trimmedGap.match(/%$/)) { |
| 554 | let normalizedPercent = parseFloat(trimmedGap) / 100; |
| 555 | if (!validatePercent(normalizedPercent, 'Percent gap')) { |
| 556 | normalizedPercent = 0; |
| 557 | } |
| 558 | parsedBrk.gapParsed.type = 'tpPrct'; |
| 559 | parsedBrk.gapParsed.val = normalizedPercent; |
| 560 | isPrct = true; |
| 561 | } |
| 562 | } |
| 563 | if (!isPrct) { |
| 564 | let absolute = scale.parse(brkOption.gap); |
| 565 | if (!isFinite(absolute) || absolute < 0) { |
no test coverage detected
searching dependent graphs…