JKQTPCALTprintf for general axis tick formatting with a printf-format string

This commit is contained in:
jkriege2 2022-09-24 00:16:57 +02:00
parent b536d79aeb
commit bf4aa7ebdb
20 changed files with 33 additions and 5 deletions

View File

@ -55,7 +55,8 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>NEW: added new error indicator styles JKQTPErrorHalfBarsOutwards, JKQTPErrorHalfBarsInwards, JKQTPErrorHalfBarsAbove, JKQTPErrorHalfBarsBelow which are especially useful for barcharts</li>
<li>NEW: Added signals JKQTBasePlotter::beforeExporting()/JKQTBasePlotter::afterExporting() and JKQTBasePlotterJKQTBasePlotter:beforePrinting()/JKQTBasePlotter::afterPrinting() which allow to modify the plot just before and just after an export/print</li>
<li>NEW: Added new JKQTPCALabelType elements (JKQTPCALTfrac...), so axis label ticks can be displayed as fractions 1/2 instead of 0.5</li>
<li>NEW: Added new JKQTPCALabelType element JKQTPCALTscientific, so axis label ticks can be displayed as numbers in scientific notation like \c 1.2E-34 </li>
<li>NEW: Added new JKQTPCALabelType elements JKQTPCALTscientific, so axis label ticks can be displayed as numbers in scientific notation like \c 1.2E-34<br>
JKQTPCALTprintf for general formatting with a printf-format string </li>
<li>NEW: all elements of a coordinate axis may have their own color now </li>
</ul></li>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -345,8 +345,9 @@ JKQTPCALabelTypeComboBox::JKQTPCALabelTypeComboBox(QWidget *parent):
setEditable(false);
addLabelType(JKQTPCALTexponent, tr("exponent"), QIcon(":/JKQTPlotter/jkqtp_ticks_exp.png"));
addLabelType(JKQTPCALTdefault, tr("default"), QIcon(":/JKQTPlotter/jkqtp_ticks_default.png"));
addLabelType(JKQTPCALTdefault, tr("scientific"), QIcon(":/JKQTPlotter/jkqtp_ticks_scientific.png"));
addLabelType(JKQTPCALTscientific, tr("scientific"), QIcon(":/JKQTPlotter/jkqtp_ticks_scientific.png"));
addLabelType(JKQTPCALTexponentCharacter, tr("character"), QIcon(":/JKQTPlotter/jkqtp_ticks_expchar.png"));
addLabelType(JKQTPCALTprintf, tr("printf"), QIcon(":/JKQTPlotter/jkqtp_ticks_printf.png"));
addLabelType(JKQTPCALTtime, tr("time"), QIcon(":/JKQTPlotter/jkqtp_ticks_time.png"));
addLabelType(JKQTPCALTdate, tr("date"), QIcon(":/JKQTPlotter/jkqtp_ticks_date.png"));
addLabelType(JKQTPCALTdatetime, tr("datetime"), QIcon(":/JKQTPlotter/jkqtp_ticks_datetime.png"));

View File

@ -473,6 +473,9 @@ QString JKQTPCoordinateAxis::floattolabel(double data, int past_comma) const {
dt.setMSecsSinceEpoch(uint64_t(data));
return dt.toString(axisStyle.tickDateTimeFormat);
}; break;
case JKQTPCALTprintf: {
return QString::asprintf(axisStyle.tickPrintfFormat.toLatin1().data(), data);
}; break;
}
return QString();
}
@ -803,6 +806,12 @@ void JKQTPCoordinateAxis::setTickDateTimeFormat(const QString& __value) {
redrawPlot();
}
void JKQTPCoordinateAxis::setTickPrintfFormat(const QString& __value) {
this->axisStyle.tickPrintfFormat = __value;
this->paramsChanged=true;
redrawPlot();
}
void JKQTPCoordinateAxis::setTickLabelFontSize(double __value) {
this->axisStyle.tickLabelFontSize = __value;
this->paramsChanged=true;

View File

@ -307,6 +307,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
inline QString getTickDateFormat() const { return this->axisStyle.tickDateFormat; }
/** \copydoc JKQTPCoordinateAxisStyle::tickDateTimeFormat */
inline QString getTickDateTimeFormat() const { return this->axisStyle.tickDateTimeFormat; }
/** \copydoc JKQTPCoordinateAxisStyle::tickPrintfFormat */
inline QString getTickPrintfFormat() const { return this->axisStyle.tickPrintfFormat; }
/** \copydoc JKQTPCoordinateAxisStyle::tickMode */
inline JKQTPLabelTickMode getTickMode() const { return this->axisStyle.tickMode; }
@ -479,6 +481,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
/** \copydoc JKQTPCoordinateAxisStyle::tickDateTimeFormat */
void setTickDateTimeFormat (const QString& __value);
/** \copydoc JKQTPCoordinateAxisStyle::tickPrintfFormat */
void setTickPrintfFormat(const QString& __value);
/** \copydoc JKQTPCoordinateAxisStyle::tickLabelFontSize */
void setTickLabelFontSize (double __value);

View File

@ -55,6 +55,7 @@ JKQTPCoordinateAxisStyle::JKQTPCoordinateAxisStyle():
tickTimeFormat(QLocale().timeFormat(QLocale::NarrowFormat)),
tickDateFormat(QLocale().dateFormat(QLocale::NarrowFormat)),
tickDateTimeFormat(QLocale().dateTimeFormat(QLocale::NarrowFormat)),
tickPrintfFormat("%f"),
minTicks(5),
minorTicks(1),
tickOutsideLength(3),
@ -100,6 +101,7 @@ void JKQTPCoordinateAxisStyle::loadSettings(const QSettings &settings, const QSt
tickTimeFormat = settings.value(group+"ticks/time_format", defaultStyle.tickTimeFormat).toString();
tickDateFormat = settings.value(group+"ticks/date_format", defaultStyle.tickDateFormat).toString();
tickDateTimeFormat = settings.value(group+"ticks/datetime_format", defaultStyle.tickDateTimeFormat).toString();
tickPrintfFormat = settings.value(group+"ticks/printf_format", defaultStyle.tickPrintfFormat).toString();
minTicks = settings.value(group+"min_ticks", defaultStyle.minTicks).toUInt();
minorTicks = settings.value(group+"minor_tick/count", defaultStyle.minorTicks).toUInt();
tickOutsideLength = settings.value(group+"ticks/outside_length", defaultStyle.tickOutsideLength).toDouble();
@ -151,6 +153,7 @@ void JKQTPCoordinateAxisStyle::saveSettings(QSettings &settings, const QString &
settings.setValue(group+"ticks/type", JKQTPCALabelType2String(tickLabelType));
settings.setValue(group+"ticks/date_format", tickDateFormat);
settings.setValue(group+"ticks/datetime_format", tickDateTimeFormat);
settings.setValue(group+"ticks/printf_format", tickPrintfFormat);
settings.setValue(group+"ticks/inside_length", tickInsideLength);
settings.setValue(group+"ticks/label_distance", tickLabelDistance);
settings.setValue(group+"ticks/label_font_size", tickLabelFontSize);

View File

@ -152,12 +152,14 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxisStyle {
double lineWidthZeroAxis;
/** \brief format string for time tick labels, see see QDateTime::toString() documentation for details on format strings */
/** \brief format string for time tick labels, see QDateTime::toString() documentation for details on format strings */
QString tickTimeFormat;
/** \brief format string for date tick labels, see see QDateTime::toString() documentation for details on format strings */
/** \brief format string for date tick labels, see QDateTime::toString() documentation for details on format strings */
QString tickDateFormat;
/** \brief format string for datetime tick labels, see see QDateTime::toString() documentation for details on format strings */
/** \brief format string for datetime tick labels, see QDateTime::toString() documentation for details on format strings */
QString tickDateTimeFormat;
/** \brief format string for printf tick labels, see https://en.wikipedia.org/wiki/Printf_format_string documentation for details on format strings */
QString tickPrintfFormat;

View File

@ -114,6 +114,7 @@ QString JKQTPCALabelType2String(JKQTPCALabelType pos) {
case JKQTPCALTfrac: return "frac";
case JKQTPCALTsfrac: return "sfrac";
case JKQTPCALTslashfrac: return "slashfrac";
case JKQTPCALTprintf: return "printf";
case JKQTPCALTcount: return "";
}
return "";
@ -134,6 +135,7 @@ JKQTPCALabelType String2JKQTPCALabelType(const QString& pos) {
if (s=="intfrac") return JKQTPCALTintfrac;
if (s=="intsfrac") return JKQTPCALTintsfrac;
if (s=="intslashfrac") return JKQTPCALTintslashfrac;
if (s=="printf" || s=="sprintf") return JKQTPCALTprintf;
return JKQTPCALTdefault;
}

View File

@ -445,6 +445,7 @@ enum JKQTPCALabelType {
JKQTPCALTscientific, /*!< \brief print the numbers in scientific notation, e.g. \c "1.23e-4" \image html axisstyle/JKQTPCALTscientific.png */
JKQTPCALTexponentCharacter, /*!< \brief print the numbers and show a unit character, i.e. 5&mu; for \f$ 5\cdot 10^{-6} \f$ , \c 3k for \f$ 3\cdot 10^3 \f$ ... \image html axisstyle/JKQTPCALTexponentCharacter.png */
JKQTPCALTexponent, /*!< \brief show numbers in exponential for, e.g. \f$ 3\cdot 10^5 \f$ ... \image html axisstyle/JKQTPCALTexponent.png */
JKQTPCALTprintf, /*!< \brief generate axis label from an arbitrary "printf" formatting string (see e.g. https://en.wikipedia.org/wiki/Printf_format_string ). The only data parameter is the tick value as \c double The following image shows an example for \c "y=%+.2f": \image html axisstyle/JKQTPCALTprintf.png */
JKQTPCALTdate, /*!< \brief show numbers as dates \image html axisstyle/JKQTPCALTdate.png */
JKQTPCALTtime, /*!< \brief show numbers as times \image html axisstyle/JKQTPCALTtime.png*/
JKQTPCALTdatetime, /*!< \brief show numbers as times \image html axisstyle/JKQTPCALTdatetime.png */

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -253,6 +253,11 @@ void doListAxisStyling(const QDir& outputDir, int iconsize, QColor backgroundCol
plot.getYAxis()->setTickLabelType(JKQTPCALTdatetime);
plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,0,iconsize*2.5,plot.getHeight()).save(outputDir.absoluteFilePath("JKQTPCALTdatetime.png"), "png");
plot.setY(-1,1);
plot.getYAxis()->setTickLabelType(JKQTPCALTprintf);
plot.getYAxis()->setTickPrintfFormat("y=%+.2f");
plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,0,iconsize*2.5,plot.getHeight()).save(outputDir.absoluteFilePath("JKQTPCALTprintf.png"), "png");
plot.setXY(0,10,0,1);