"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/backend/worksheet/plots/cartesian/Axis.cpp" between
labplot-2.8.1.tar.gz and labplot-2.8.2.tar.gz

About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.

Axis.cpp  (labplot-2.8.1):Axis.cpp  (labplot-2.8.2)
skipping to change at line 1208 skipping to change at line 1208
} }
//determine the increment for the major ticks //determine the increment for the major ticks
double majorTicksIncrement = 0; double majorTicksIncrement = 0;
int tmpMajorTicksNumber = 0; int tmpMajorTicksNumber = 0;
if (majorTicksType == Axis::TicksType::TotalNumber) { if (majorTicksType == Axis::TicksType::TotalNumber) {
//the total number of major ticks is given - > determine the incr ement //the total number of major ticks is given - > determine the incr ement
tmpMajorTicksNumber = majorTicksNumber; tmpMajorTicksNumber = majorTicksNumber;
switch (scale) { switch (scale) {
case Axis::Scale::Linear: case Axis::Scale::Linear:
majorTicksIncrement = (end-start)/(majorTicksNumb er-1); majorTicksIncrement = end-start;
break; break;
case Axis::Scale::Log10: case Axis::Scale::Log10:
majorTicksIncrement = (log10(end)-log10(start))/( majorTicksNumber-1); majorTicksIncrement = log10(end)-log10(start);
break; break;
case Axis::Scale::Log2: case Axis::Scale::Log2:
majorTicksIncrement = (log(end)-log(start))/log(2 )/(majorTicksNumber-1); majorTicksIncrement = log2(end)-log2(start);
break; break;
case Axis::Scale::Ln: case Axis::Scale::Ln:
majorTicksIncrement = (log(end)-log(start))/(majo rTicksNumber-1); majorTicksIncrement = log(end)-log(start);
break; break;
case Axis::Scale::Sqrt: case Axis::Scale::Sqrt:
majorTicksIncrement = (sqrt(end)-sqrt(start))/(ma jorTicksNumber-1); majorTicksIncrement = sqrt(end)-sqrt(start);
break; break;
case Axis::Scale::X2: case Axis::Scale::X2:
majorTicksIncrement = (end*end - start*start)/(ma jorTicksNumber-1); majorTicksIncrement = end*end - start*start;
} }
if (majorTicksNumber > 1)
majorTicksIncrement /= majorTicksNumber - 1;
} else if (majorTicksType == Axis::TicksType::Spacing) { } else if (majorTicksType == Axis::TicksType::Spacing) {
//the increment of the major ticks is given -> determine the numb er //the increment of the major ticks is given -> determine the numb er
majorTicksIncrement = majorTicksSpacing * GSL_SIGN(end-start); majorTicksIncrement = majorTicksSpacing * GSL_SIGN(end-start);
switch (scale) { switch (scale) {
case Axis::Scale::Linear: case Axis::Scale::Linear:
tmpMajorTicksNumber = qRound((end-start)/majorTic ksIncrement + 1); tmpMajorTicksNumber = qRound((end-start)/majorTic ksIncrement + 1);
break; break;
case Axis::Scale::Log10: case Axis::Scale::Log10:
tmpMajorTicksNumber = qRound((log10(end)-log10(st art))/majorTicksIncrement + 1); tmpMajorTicksNumber = qRound((log10(end)-log10(st art))/majorTicksIncrement + 1);
break; break;
case Axis::Scale::Log2: case Axis::Scale::Log2:
tmpMajorTicksNumber = qRound((log(end)-log(start) )/log(2)/majorTicksIncrement + 1); tmpMajorTicksNumber = qRound((log2(end)-log2(star t))/majorTicksIncrement + 1);
break; break;
case Axis::Scale::Ln: case Axis::Scale::Ln:
tmpMajorTicksNumber = qRound((log(end)-log(start) )/majorTicksIncrement + 1); tmpMajorTicksNumber = qRound((log(end)-log(start) )/majorTicksIncrement + 1);
break; break;
case Axis::Scale::Sqrt: case Axis::Scale::Sqrt:
tmpMajorTicksNumber = qRound((sqrt(end)-sqrt(star t))/majorTicksIncrement + 1); tmpMajorTicksNumber = qRound((sqrt(end)-sqrt(star t))/majorTicksIncrement + 1);
break; break;
case Axis::Scale::X2: case Axis::Scale::X2:
tmpMajorTicksNumber = qRound((end*end - start*sta rt)/majorTicksIncrement + 1); tmpMajorTicksNumber = qRound((end*end - start*sta rt)/majorTicksIncrement + 1);
} }
skipping to change at line 1448 skipping to change at line 1450
creates the tick label strings starting with the most optimal creates the tick label strings starting with the most optimal
(=the smallest possible number of float digits) precision for the floats (=the smallest possible number of float digits) precision for the floats
*/ */
void AxisPrivate::retransformTickLabelStrings() { void AxisPrivate::retransformTickLabelStrings() {
DEBUG(Q_FUNC_INFO) DEBUG(Q_FUNC_INFO)
if (suppressRetransform) if (suppressRetransform)
return; return;
if (labelsAutoPrecision) { if (labelsAutoPrecision) {
//check, whether we need to increase the current precision //check, whether we need to increase the current precision
int newPrecision = upperLabelsPrecision(labelsPrecision); int newPrecision = upperLabelsPrecision(labelsPrecision, labelsFo rmat);
if (newPrecision != labelsPrecision) { if (newPrecision != labelsPrecision) {
labelsPrecision = newPrecision; labelsPrecision = newPrecision;
emit q->labelsPrecisionChanged(labelsPrecision); emit q->labelsPrecisionChanged(labelsPrecision);
} else { } else {
//check, whether we can reduce the current precision //check, whether we can reduce the current precision
newPrecision = lowerLabelsPrecision(labelsPrecision); newPrecision = lowerLabelsPrecision(labelsPrecision, labe lsFormat);
if (newPrecision != labelsPrecision) { if (newPrecision != labelsPrecision) {
labelsPrecision = newPrecision; labelsPrecision = newPrecision;
emit q->labelsPrecisionChanged(labelsPrecision); emit q->labelsPrecisionChanged(labelsPrecision);
} }
} }
} }
//DEBUG("labelsPrecision =" << labelsPrecision); //DEBUG("labelsPrecision =" << labelsPrecision);
//automatically switch from 'decimal' to 'scientific' format for big numb ers (>10^4) //automatically switch from 'decimal' to 'scientific' format for big numb ers (>10^4)
//and back to decimal when the numbers get smaller after the auto-switch again //and back to decimal when the numbers get smaller after the auto-switch again
skipping to change at line 1507 skipping to change at line 1509
QString nullStr = numberLocale.toString(0., 'f', labelsPr ecision); QString nullStr = numberLocale.toString(0., 'f', labelsPr ecision);
for (const auto value : tickLabelValues) { for (const auto value : tickLabelValues) {
str = numberLocale.toString(value, 'f', labelsPre cision); str = numberLocale.toString(value, 'f', labelsPre cision);
if (str == "-" + nullStr) str = nullStr; if (str == "-" + nullStr) str = nullStr;
str = labelsPrefix + str + labelsSuffix; str = labelsPrefix + str + labelsSuffix;
tickLabelStrings << str; tickLabelStrings << str;
} }
} else if (labelsFormat == Axis::LabelsFormat::ScientificE) { } else if (labelsFormat == Axis::LabelsFormat::ScientificE) {
QString nullStr = numberLocale.toString(0., 'e', labelsPr ecision); QString nullStr = numberLocale.toString(0., 'e', labelsPr ecision);
for (const auto value : tickLabelValues) { for (const auto value : tickLabelValues) {
str = numberLocale.toString(value, 'e', labelsPre if (value == 0) // just show "0"
cision); str = numberLocale.toString(value, 'f', 0
);
else
str = numberLocale.toString(value, 'e', l
abelsPrecision);
if (str == "-" + nullStr) str = nullStr; if (str == "-" + nullStr) str = nullStr;
str = labelsPrefix + str + labelsSuffix; str = labelsPrefix + str + labelsSuffix;
tickLabelStrings << str; tickLabelStrings << str;
} }
} else if (labelsFormat == Axis::LabelsFormat::Powers10) { } else if (labelsFormat == Axis::LabelsFormat::Powers10) {
for (const auto value : tickLabelValues) { for (const auto value : tickLabelValues) {
str = "10<sup>" + numberLocale.toString(log10(val if (value == 0) // just show "0"
ue), 'f', labelsPrecision) + "</sup>"; str = numberLocale.toString(value, 'f', 0
);
else {
str = "10<sup>" + numberLocale.toString(l
og10(qAbs(value)), 'f', labelsPrecision) + "</sup>";
if (value < 0)
str.prepend("-");
}
str = labelsPrefix + str + labelsSuffix; str = labelsPrefix + str + labelsSuffix;
tickLabelStrings << str; tickLabelStrings << str;
} }
} else if (labelsFormat == Axis::LabelsFormat::Powers2) { } else if (labelsFormat == Axis::LabelsFormat::Powers2) {
for (const auto value : tickLabelValues) { for (const auto value : tickLabelValues) {
str = "2<span style=\"vertical-align:super\">" + if (value == 0) // just show "0"
numberLocale.toString(log2(value), 'f', labelsPrecision) + "</span>"; str = numberLocale.toString(value, 'f', 0
);
else {
str = "2<span style=\"vertical-align:supe
r\">" + numberLocale.toString(log2(qAbs(value)), 'f', labelsPrecision) + "</span
>";
if (value < 0)
str.prepend("-");
}
str = labelsPrefix + str + labelsSuffix; str = labelsPrefix + str + labelsSuffix;
tickLabelStrings << str; tickLabelStrings << str;
} }
} else if (labelsFormat == Axis::LabelsFormat::PowersE) { } else if (labelsFormat == Axis::LabelsFormat::PowersE) {
for (const auto value : tickLabelValues) { for (const auto value : tickLabelValues) {
str = "e<span style=\"vertical-align:super\">" + if (value == 0) // just show "0"
numberLocale.toString(log(value), 'f', labelsPrecision) + "</span>"; str = numberLocale.toString(value, 'f', 0
);
else {
str = "e<span style=\"vertical-align:supe
r\">" + numberLocale.toString(log(qAbs(value)), 'f', labelsPrecision) + "</span>
";
if (value < 0)
str.prepend("-");
}
str = labelsPrefix + str + labelsSuffix; str = labelsPrefix + str + labelsSuffix;
tickLabelStrings << str; tickLabelStrings << str;
} }
} else if (labelsFormat == Axis::LabelsFormat::MultipliesPi) { } else if (labelsFormat == Axis::LabelsFormat::MultipliesPi) {
for (const auto value : tickLabelValues) { for (const auto value : tickLabelValues) {
str = "<span>" + numberLocale.toString(value / M_ if (value == 0) // just show "0"
PI, 'f', labelsPrecision) + "</span>" + QChar(0x03C0); str = numberLocale.toString(value, 'f', 0
);
else
str = "<span>" + numberLocale.toString(va
lue / M_PI, 'f', labelsPrecision) + "</span>" + QChar(0x03C0);
str = labelsPrefix + str + labelsSuffix; str = labelsPrefix + str + labelsSuffix;
tickLabelStrings << str; tickLabelStrings << str;
} }
} }
} else { } else {
for (const auto value : tickLabelValues) { for (const auto value : tickLabelValues) {
QDateTime dateTime; QDateTime dateTime;
dateTime.setMSecsSinceEpoch(value); dateTime.setMSecsSinceEpoch(value);
str = dateTime.toString(labelsDateTimeFormat); str = dateTime.toString(labelsDateTimeFormat);
str = labelsPrefix + str + labelsSuffix; str = labelsPrefix + str + labelsSuffix;
skipping to change at line 1555 skipping to change at line 1581
} }
//recalculate the position of the tick labels //recalculate the position of the tick labels
retransformTickLabelPositions(); retransformTickLabelPositions();
} }
/*! /*!
returns the smallest upper limit for the precision returns the smallest upper limit for the precision
where no duplicates for the tick label float occur. where no duplicates for the tick label float occur.
*/ */
int AxisPrivate::upperLabelsPrecision(int precision) { int AxisPrivate::upperLabelsPrecision(const int precision, const Axis::LabelsFor
DEBUG(Q_FUNC_INFO << ", precision =" << precision); mat format) {
DEBUG(Q_FUNC_INFO << ", precision = " << precision);
// avoid problems with zero range axis // avoid problems with zero range axis
if (tickLabelValues.isEmpty() || qFuzzyCompare(tickLabelValues.constFirst (), tickLabelValues.constLast())) { if (tickLabelValues.isEmpty() || qFuzzyCompare(tickLabelValues.constFirst (), tickLabelValues.constLast())) {
DEBUG(Q_FUNC_INFO << ", zero range axis detected. ticklabel value s: ") DEBUG(Q_FUNC_INFO << ", zero range axis detected. ticklabel value s: ")
QDEBUG(Q_FUNC_INFO << tickLabelValues) QDEBUG(Q_FUNC_INFO << tickLabelValues)
return 0; return 0;
} }
//round float to the current precision and look for duplicates. //round float to the current precision and look for duplicates.
//if there are duplicates, increase the precision. //if there are duplicates, increase the precision.
QVector<double> tempValues; QVector<double> tempValues;
for (const auto value : tickLabelValues) switch (format) {
tempValues.append( nsl_math_round_places(value, precision) ); case Axis::LabelsFormat::Decimal:
case Axis::LabelsFormat::MultipliesPi:
for (const auto value : tickLabelValues)
tempValues.append( nsl_math_round_places(value, precision
) );
break;
case Axis::LabelsFormat::ScientificE:
for (const auto value : tickLabelValues)
tempValues.append( nsl_math_round_precision(value, precis
ion) );
break;
case Axis::LabelsFormat::Powers10:
for (const auto value : tickLabelValues)
tempValues.append( nsl_math_round_places(log10(qAbs(value
)), precision) );
break;
case Axis::LabelsFormat::Powers2:
for (const auto value : tickLabelValues)
tempValues.append( nsl_math_round_places(log2(qAbs(value)
), precision) );
break;
case Axis::LabelsFormat::PowersE:
for (const auto value : tickLabelValues)
tempValues.append( nsl_math_round_places(log(qAbs(value))
, precision) );
}
for (int i = 0; i < tempValues.size(); ++i) { for (int i = 0; i < tempValues.size(); ++i) {
for (int j = 0; j < tempValues.size(); ++j) { for (int j = 0; j < tempValues.size(); ++j) {
if (i == j) if (i == j)
continue; continue;
//duplicate for the current precision found, increase the precision and check again //duplicate for the current precision found, increase the precision and check again
if (tempValues.at(i) == tempValues.at(j)) if (tempValues.at(i) == tempValues.at(j))
return upperLabelsPrecision(precision + 1); return upperLabelsPrecision(precision + 1, format );
} }
} }
//no duplicates for the current precision found: return the current value //no duplicates for the current precision found: return the current value
DEBUG(Q_FUNC_INFO << ", upper precision = " << precision); DEBUG(Q_FUNC_INFO << ", upper precision = " << precision);
return precision; return precision;
} }
/*! /*!
returns highest lower limit for the precision returns highest lower limit for the precision
where no duplicates for the tick label float occur. where no duplicates for the tick label float occur.
*/ */
int AxisPrivate::lowerLabelsPrecision(int precision) { int AxisPrivate::lowerLabelsPrecision(const int precision, const Axis::LabelsFor
// DEBUG("AxisPrivate::lowerLabelsPrecision() precision =" << precision); mat format) {
//round float to the current precision and look for duplicates. DEBUG(Q_FUNC_INFO << ", precision = " << precision);
//round value to the current precision and look for duplicates.
//if there are duplicates, decrease the precision. //if there are duplicates, decrease the precision.
QVector<double> tempValues; QVector<double> tempValues;
for (auto value : tickLabelValues) switch (format) {
tempValues.append( nsl_math_round_places(value, precision-1) ); case Axis::LabelsFormat::Decimal:
case Axis::LabelsFormat::MultipliesPi:
for (auto value : tickLabelValues)
tempValues.append( nsl_math_round_places(value, precision
-1) );
break;
case Axis::LabelsFormat::ScientificE:
for (auto value : tickLabelValues)
tempValues.append( nsl_math_round_precision(value, precis
ion-1) );
break;
case Axis::LabelsFormat::Powers10:
for (auto value : tickLabelValues)
tempValues.append( nsl_math_round_places(log10(qAbs(value
)), precision-1) );
break;
case Axis::LabelsFormat::Powers2:
for (auto value : tickLabelValues)
tempValues.append( nsl_math_round_places(log2(qAbs(value)
), precision-1) );
break;
case Axis::LabelsFormat::PowersE:
for (auto value : tickLabelValues)
tempValues.append( nsl_math_round_places(log(qAbs(value))
, precision-1) );
}
//check whether we have duplicates with reduced precision //check whether we have duplicates with reduced precision
//-> current precision cannot be reduced, return the current value //-> current precision cannot be reduced, return the current value
for (int i = 0; i < tempValues.size(); ++i) { for (int i = 0; i < tempValues.size(); ++i) {
for (int j = 0; j < tempValues.size(); ++j) { for (int j = 0; j < tempValues.size(); ++j) {
if (i == j) continue; if (i == j) continue;
if (tempValues.at(i) == tempValues.at(j)) if (tempValues.at(i) == tempValues.at(j))
return precision; return precision;
} }
} }
skipping to change at line 1625 skipping to change at line 1691
} }
} }
//if we have double values we don't want to show them as integers , keep at least one float digit. //if we have double values we don't want to show them as integers , keep at least one float digit.
if (hasDoubles) if (hasDoubles)
return 1; return 1;
else else
return 0; return 0;
} else { } else {
//no duplicates found, reduce further, and check again //no duplicates found, reduce further, and check again
return lowerLabelsPrecision(precision - 1); return lowerLabelsPrecision(precision - 1, format);
} }
} }
/*! /*!
recalculates the position of the tick labels. recalculates the position of the tick labels.
Called when the geometry related properties (position, offset, font size, suffix, prefix) of the labels are changed. Called when the geometry related properties (position, offset, font size, suffix, prefix) of the labels are changed.
*/ */
void AxisPrivate::retransformTickLabelPositions() { void AxisPrivate::retransformTickLabelPositions() {
tickLabelPoints.clear(); tickLabelPoints.clear();
if (majorTicksDirection == Axis::noTicks || labelsPosition == Axis::Label sPosition::NoLabels) { if (majorTicksDirection == Axis::noTicks || labelsPosition == Axis::Label sPosition::NoLabels) {
 End of changes. 21 change blocks. 
30 lines changed or deleted 115 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)