Commit 87543539d13a14676905c7000d7b77a8003320a2
1 parent
7de75729
Added cmcOpts file to simplify and compartmentalize plot options
Showing
1 changed file
with
17 additions
and
11 deletions
openbr/core/plot.cpp
| @@ -220,14 +220,16 @@ bool Plot(const QStringList &files, const File &destination, bool show) | @@ -220,14 +220,16 @@ bool Plot(const QStringList &files, const File &destination, bool show) | ||
| 220 | 220 | ||
| 221 | const bool minimalist = destination.getBool("minimalist"); | 221 | const bool minimalist = destination.getBool("minimalist"); |
| 222 | 222 | ||
| 223 | - const QString title = destination.get<QString>("title", QString()); | ||
| 224 | - const QString thickness = QString::number(destination.get<float>("thickness", 1)); | ||
| 225 | - const QString textSize = QString::number(destination.get<float>("textSize",12)); | 223 | + // Use a br::file for simple storage of plot options |
| 224 | + File cmcOpts; | ||
| 225 | + const QStringList cmcOptions = destination.get<QStringList>("cmcOptions", QStringList()); | ||
| 226 | + foreach (const QString& option, cmcOptions) { | ||
| 227 | + QStringList words = QtUtils::parse(option, '='); | ||
| 228 | + QtUtils::checkArgsSize(words[0],words,1,2); | ||
| 229 | + cmcOpts.set(words[0],words[1]); | ||
| 230 | + } | ||
| 226 | 231 | ||
| 227 | - const QPointF legendPoint = destination.get<QPointF>("legendPosition",QPointF()); | ||
| 228 | - const QString legendPosition = legendPoint.isNull() ? "'right'" : "c" + QtUtils::toString(legendPoint); | ||
| 229 | - const QPointF yLimitPoint = destination.get<QPointF>("yLimits",QPointF()); | ||
| 230 | - const QString yLimits = yLimitPoint.isNull() ? QString() : "c" + QtUtils::toString(yLimitPoint); | 232 | + qDebug() << cmcOpts.flat(); |
| 231 | 233 | ||
| 232 | RPlot p(files, destination); | 234 | RPlot p(files, destination); |
| 233 | 235 | ||
| @@ -254,13 +256,15 @@ bool Plot(const QStringList &files, const File &destination, bool show) | @@ -254,13 +256,15 @@ bool Plot(const QStringList &files, const File &destination, bool show) | ||
| 254 | (p.major.size > 1 ? (p.minor.size > 1 ? QString(" + facet_grid(%2 ~ %1, scales=\"free\")").arg((p.flip ? p.major.header : p.minor.header), (p.flip ? p.minor.header : p.major.header)) : QString(" + facet_wrap(~ %1, scales = \"free\")").arg(p.major.header)) : QString()) + | 256 | (p.major.size > 1 ? (p.minor.size > 1 ? QString(" + facet_grid(%2 ~ %1, scales=\"free\")").arg((p.flip ? p.major.header : p.minor.header), (p.flip ? p.minor.header : p.major.header)) : QString(" + facet_wrap(~ %1, scales = \"free\")").arg(p.major.header)) : QString()) + |
| 255 | QString(" + theme(aspect.ratio=1)\n\n"))); | 257 | QString(" + theme(aspect.ratio=1)\n\n"))); |
| 256 | 258 | ||
| 257 | - p.file.write(qPrintable(QString("ggplot(CMC, aes(x=X, y=Y%1%2)) + ggtitle(\"%3\") + xlab(\"Rank\") + ylab(\"Retrieval Rate\")").arg(p.major.size > 1 ? QString(" ,colour=factor(%1)").arg(p.major.header) : QString(), p.minor.size > 1 ? QString(", linetype=factor(%1)").arg(p.minor.header) : QString(), title) + | ||
| 258 | - QString(((p.major.smooth || p.minor.smooth) ? (minimalist ? " + stat_summary(geom=\"line\", fun.y=mean, size=%1)" : " + stat_summary(geom=\"line\", fun.y=min, aes(linetype=\"Min/Max\"), size=%1) + stat_summary(geom=\"line\", fun.y=max, aes(linetype=\"Min/Max\"), size=%1) + stat_summary(geom=\"line\", fun.y=mean, aes(linetype=\"Mean\"), size=%1) + scale_linetype_manual(\"Legend\", values=c(\"Mean\"=1, \"Min/Max\"=2))") : " + geom_line(size=%1)")).arg(thickness) + | 259 | + p.file.write(qPrintable(QString("ggplot(CMC, aes(x=X, y=Y%1%2)) + ggtitle(\"%3\") + xlab(\"Rank\") + ylab(\"Retrieval Rate\")").arg(p.major.size > 1 ? QString(" ,colour=factor(%1)").arg(p.major.header) : QString(), p.minor.size > 1 ? QString(", linetype=factor(%1)").arg(p.minor.header) : QString(), cmcOpts.get<QString>("title",QString())) + |
| 260 | + QString(((p.major.smooth || p.minor.smooth) ? (minimalist ? " + stat_summary(geom=\"line\", fun.y=mean, size=%1)" : " + stat_summary(geom=\"line\", fun.y=min, aes(linetype=\"Min/Max\"), size=%1) + stat_summary(geom=\"line\", " | ||
| 261 | + "fun.y=max, aes(linetype=\"Min/Max\"), size=%1) + stat_summary(geom=\"line\", fun.y=mean, aes(linetype=\"Mean\"), size=%1) + scale_linetype_manual(\"Legend\", values=c(\"Mean\"=1, \"Min/Max\"=2))") : " + geom_line(size=%1)")).arg(QString::number(cmcOpts.get<float>("thickness",1))) + | ||
| 259 | (minimalist ? "" : " + scale_x_log10(labels=c(1,5,10,50,100), breaks=c(1,5,10,50,100)) + annotation_logticks(sides=\"b\")") + | 262 | (minimalist ? "" : " + scale_x_log10(labels=c(1,5,10,50,100), breaks=c(1,5,10,50,100)) + annotation_logticks(sides=\"b\")") + |
| 260 | (p.major.size > 1 ? getScale("colour", p.major.header, p.major.size) : QString()) + | 263 | (p.major.size > 1 ? getScale("colour", p.major.header, p.major.size) : QString()) + |
| 261 | (p.minor.size > 1 ? QString(" + scale_linetype_discrete(\"%1\")").arg(p.minor.header) : QString()) + | 264 | (p.minor.size > 1 ? QString(" + scale_linetype_discrete(\"%1\")").arg(p.minor.header) : QString()) + |
| 262 | - (yLimits.isEmpty() ? QString(" + scale_y_continuous(labels=percent)") : QString(" + scale_y_continuous(labels=percent, limits=%3)").arg(yLimits)) + | ||
| 263 | - QString(" + theme_minimal() + theme(legend.title = element_text(size = %1), plot.title = element_text(size = %1), axis.text = element_text(size = %1), axis.title.x = element_text(size = %1), axis.title.y = element_text(size = %1), legend.position=%2, legend.background = element_rect(fill = 'white'), panel.grid.major = element_line(colour = \"gray\"), panel.grid.minor = element_line(colour = \"gray\", linetype = \"dashed\"), legend.text = element_text(size = %1))\n\n").arg(textSize,legendPosition))); | 265 | + (cmcOpts.contains("yLimits") ? QString(" + scale_y_continuous(labels=percent, limits=%3)").arg("c"+QtUtils::toString(cmcOpts.get<QPointF>("yLimits",QPointF()))) : QString(" + scale_y_continuous(labels=percent)")) + |
| 266 | + QString(" + theme_minimal() + theme(legend.title = element_text(size = %1), plot.title = element_text(size = %1), axis.text = element_text(size = %1), axis.title.x = element_text(size = %1), axis.title.y = element_text(size = %1)," | ||
| 267 | + " legend.position=%2, legend.background = element_rect(fill = 'white'), panel.grid.major = element_line(colour = \"gray\"), panel.grid.minor = element_line(colour = \"gray\", linetype = \"dashed\"), legend.text = element_text(size = %1))\n\n").arg(QString::number(cmcOpts.get<float>("textSize",12)), cmcOpts.contains("legendPosition") ? "c"+QtUtils::toString(cmcOpts.get<QPointF>("legendPosition")) : "'right'"))); | ||
| 264 | 268 | ||
| 265 | p.file.write(qPrintable(QString("qplot(factor(%1)%2, data=BC, %3").arg(p.major.smooth ? (p.minor.header.isEmpty() ? "Algorithm" : p.minor.header) : p.major.header, (p.major.smooth || p.minor.smooth) ? ", Y" : "", (p.major.smooth || p.minor.smooth) ? "geom=\"boxplot\"" : "geom=\"bar\", position=\"dodge\", weight=Y") + | 269 | p.file.write(qPrintable(QString("qplot(factor(%1)%2, data=BC, %3").arg(p.major.smooth ? (p.minor.header.isEmpty() ? "Algorithm" : p.minor.header) : p.major.header, (p.major.smooth || p.minor.smooth) ? ", Y" : "", (p.major.smooth || p.minor.smooth) ? "geom=\"boxplot\"" : "geom=\"bar\", position=\"dodge\", weight=Y") + |
| 266 | (p.major.size > 1 ? QString(", fill=factor(%1)").arg(p.major.header) : QString()) + | 270 | (p.major.size > 1 ? QString(", fill=factor(%1)").arg(p.major.header) : QString()) + |
| @@ -309,6 +313,8 @@ bool filesHaveSinglePoint(const QStringList &files) { | @@ -309,6 +313,8 @@ bool filesHaveSinglePoint(const QStringList &files) { | ||
| 309 | return false; | 313 | return false; |
| 310 | } | 314 | } |
| 311 | 315 | ||
| 316 | +// Properly | ||
| 317 | + | ||
| 312 | bool PlotDetection(const QStringList &files, const File &destination, bool show) | 318 | bool PlotDetection(const QStringList &files, const File &destination, bool show) |
| 313 | { | 319 | { |
| 314 | qDebug("Plotting %d detection file(s) to %s", files.size(), qPrintable(destination)); | 320 | qDebug("Plotting %d detection file(s) to %s", files.size(), qPrintable(destination)); |