Generic Plot Cosmetic

.. show x-avg on select at the top of a line chart, stops it overwriting
   the min/max values. Especially relevant when using a time/date axis
   hence limiting to a line chart where this is most common.
This commit is contained in:
Mark Liversedge
2020-03-21 08:34:49 +00:00
parent 987e79024f
commit d36b39d31e

View File

@@ -284,7 +284,10 @@ void GenericSelectTool::paint(QPainter*painter, const QStyleOptionGraphicsItem *
// bottom of plotarea, remember Y-axis range doesn't always start from 0
minxp.setY(mapFromScene(host->qchart->plotArea().bottomLeft()).y());
maxxp.setY(mapFromScene(host->qchart->plotArea().bottomLeft()).y());
avgxp.setY(mapFromScene(host->qchart->plotArea().bottomLeft()).y());
if (host->charttype == GC_CHART_SCATTER) avgxp.setY(mapFromScene(host->qchart->plotArea().bottomLeft()).y()-4);
else avgxp.setY(mapFromScene(host->qchart->plotArea().topLeft()).y()+fm.tightBoundingRect("XXX").height()+4);
QColor linecol=GColor(CPLOTMARKER);
linecol.setAlphaF(0.25);
@@ -334,7 +337,9 @@ void GenericSelectTool::paint(QPainter*painter, const QStyleOptionGraphicsItem *
if (host->charttype == GC_CHART_SCATTER) label=QString("%1").arg(calc.x.mean);
else label=QString("%1").arg(calc.x.max - calc.x.min);
}
painter->drawText(avgxp-QPointF(0,4), label);
// paint centered
painter->drawText(avgxp-QPointF(fm.tightBoundingRect(label).width()/2.0,0), label);
//
// MIN AVG MAX Y VALUE ON PLOT AREA