------------------------------------------------------------------------------
| 622 | |
| 623 | //------------------------------------------------------------------------------ |
| 624 | void vtkAxisActor2D::UpdateTicksValueAndPosition(vtkViewport* viewport) |
| 625 | { |
| 626 | // viewport distances |
| 627 | const double viewportAxisLength = this->GetViewportAxisLength(viewport); |
| 628 | const double viewportRulerDistance = this->GetViewportRulerDistance(viewport); |
| 629 | |
| 630 | // normalized on axis size. |
| 631 | const double majorLengthRatio = this->RulerMode ? viewportRulerDistance / viewportAxisLength |
| 632 | : 1. / (this->AdjustedNumberOfLabels - 1); |
| 633 | const double minorLengthRatio = majorLengthRatio / (this->NumberOfMinorTicks + 1); |
| 634 | |
| 635 | // values (in `Range` unit) |
| 636 | const double majorDelta = (this->AdjustedRange[1] - this->AdjustedRange[0]) * majorLengthRatio; |
| 637 | const double minorDelta = (this->AdjustedRange[1] - this->AdjustedRange[0]) * minorLengthRatio; |
| 638 | |
| 639 | // factor for Range to Axis normalized value conversion. |
| 640 | const double scale = 1. / (this->Range[1] - this->Range[0]); |
| 641 | |
| 642 | this->TickValues.clear(); |
| 643 | this->NormalizedTickPositions.clear(); |
| 644 | |
| 645 | const double minValue = std::min(this->Range[0], this->Range[1]); |
| 646 | const double maxValue = std::max(this->Range[0], this->Range[1]); |
| 647 | |
| 648 | int startingTick = this->SkipFirstTick ? 1 : 0; |
| 649 | for (int major = startingTick; major < this->AdjustedNumberOfLabels; major++) |
| 650 | { |
| 651 | double value = this->AdjustedRange[0] + major * majorDelta; |
| 652 | double position = (value - this->Range[0]) * scale; |
| 653 | |
| 654 | if (position < 0 || value < minValue || position > 1 || value > maxValue) |
| 655 | { |
| 656 | continue; |
| 657 | } |
| 658 | |
| 659 | this->NormalizedTickPositions.push_back(position); |
| 660 | this->TickValues.push_back(value); |
| 661 | |
| 662 | for (int minor = 1; minor <= this->NumberOfMinorTicks; minor++) |
| 663 | { |
| 664 | value = value + minorDelta; |
| 665 | position = (value - this->Range[0]) * scale; |
| 666 | if (position > 1) |
| 667 | { |
| 668 | continue; |
| 669 | } |
| 670 | this->NormalizedTickPositions.push_back(position); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | this->NumberOfLabelsBuilt = static_cast<int>(this->TickValues.size()); |
| 675 | } |
| 676 | |
| 677 | //------------------------------------------------------------------------------ |
| 678 | void vtkAxisActor2D::BuildTicksPolyData(vtkViewport* viewport) |
no test coverage detected