diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-10-23 13:35:54 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-11-04 12:30:37 -0500 |
commit | d5be9c7c17fd839f051641ac947aca550d3638c4 (patch) | |
tree | a1c7439301c79af79a2fc6a38c5fe3bc164c234d /chart2 | |
parent | 6e7539a49e61c17eb058dcb7bb395ea1d5f78961 (diff) |
Modify the tick iterator strategy to use fewer ticks.
To pre-determine the size of the largest text label object, auto-staggering
strategy etc. In theory (if I read the code correctly) we could achieve
the same thing by using only 3 ticks rather than 5.
Change-Id: Iee51588061e482c724ee4fb666c51c2a6b636e8c
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/view/axes/VCartesianAxis.cxx | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index 7ff0f997703e..1209664dce4f 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -407,9 +407,10 @@ void getAxisLabelProperties( } /** - * Iterate through only the first 2 and last 2 tick info items, and the tick - * that has the longest text (in terms of character length) in case it's not - * in the first or last 2 items. + * Iterate through only 3 ticks including the one that has the longest text + * length. When the first tick has the longest text, it iterates through + * the first 3 ticks. Otherwise it iterates through 3 ticks such that the + * 2nd tick is the one with the longest text. */ class MaxLabelTickIter : public TickIter { @@ -431,21 +432,27 @@ MaxLabelTickIter::MaxLabelTickIter( m_rTickInfoVector(rTickInfoVector), m_nCurrentIndex(0) { assert(!rTickInfoVector.empty()); // should be checked by the caller. + assert(nLongestLabelIndex < rTickInfoVector.size()); size_t nMaxIndex = m_rTickInfoVector.size()-1; if (nLongestLabelIndex >= nMaxIndex-1) nLongestLabelIndex = 0; - m_aValidIndices.push_back(0); - if( nMaxIndex>=1 ) - m_aValidIndices.push_back(1); - if( nLongestLabelIndex>1 ) + if (nLongestLabelIndex > 0) + m_aValidIndices.push_back(nLongestLabelIndex-1); + + m_aValidIndices.push_back(nLongestLabelIndex); + + while (m_aValidIndices.size() < 3) + { + ++nLongestLabelIndex; + if (nLongestLabelIndex > nMaxIndex) + break; + m_aValidIndices.push_back(nLongestLabelIndex); - if( nMaxIndex > 2 ) - m_aValidIndices.push_back(nMaxIndex-1); - if( nMaxIndex > 1 ) - m_aValidIndices.push_back(nMaxIndex); + } } + MaxLabelTickIter::~MaxLabelTickIter() { } @@ -624,6 +631,9 @@ TickIter* VCartesianAxis::createMaximumLabelTickIterator( sal_Int32 nTextLevel ) if( !m_aAllTickInfos.empty() ) { size_t nLongestLabelIndex = m_bUseTextLabels ? getIndexOfLongestLabel(m_aTextLabels) : 0; + if (nLongestLabelIndex >= m_aAllTickInfos[0].size()) + return NULL; + return new MaxLabelTickIter( m_aAllTickInfos[0], nLongestLabelIndex ); } } |