! Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. */
| 8602 | Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. |
| 8603 | */ |
| 8604 | double QCPAxis::coordToPixel(double value) const |
| 8605 | { |
| 8606 | if (orientation() == Qt::Horizontal) |
| 8607 | { |
| 8608 | if (mScaleType == stLinear) |
| 8609 | { |
| 8610 | if (!mRangeReversed) |
| 8611 | return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); |
| 8612 | else |
| 8613 | return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); |
| 8614 | } else // mScaleType == stLogarithmic |
| 8615 | { |
| 8616 | if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range |
| 8617 | return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; |
| 8618 | else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range |
| 8619 | return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; |
| 8620 | else |
| 8621 | { |
| 8622 | if (!mRangeReversed) |
| 8623 | return qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); |
| 8624 | else |
| 8625 | return qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); |
| 8626 | } |
| 8627 | } |
| 8628 | } else // orientation() == Qt::Vertical |
| 8629 | { |
| 8630 | if (mScaleType == stLinear) |
| 8631 | { |
| 8632 | if (!mRangeReversed) |
| 8633 | return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); |
| 8634 | else |
| 8635 | return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); |
| 8636 | } else // mScaleType == stLogarithmic |
| 8637 | { |
| 8638 | if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range |
| 8639 | return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; |
| 8640 | else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range |
| 8641 | return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; |
| 8642 | else |
| 8643 | { |
| 8644 | if (!mRangeReversed) |
| 8645 | return mAxisRect->bottom()-qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); |
| 8646 | else |
| 8647 | return mAxisRect->bottom()-qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); |
| 8648 | } |
| 8649 | } |
| 8650 | } |
| 8651 | } |
| 8652 | |
| 8653 | /*! |
| 8654 | Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function |
no test coverage detected