/* Copyright (c) 2008-2024 Jan W. Krieger () This software is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License (LGPL) for more details. You should have received a copy of the GNU Lesser General Public License (LGPL) along with this program. If not, see . */ #include "jkqtplotter/graphs/jkqtpgraphlabels.h" #include "jkqtplotter/jkqtpbaseplotter.h" #include "jkqtplotter/jkqtplotter.h" #include #include #include "jkqtcommon/jkqtpdrawingtools.h" #include "jkqtplotter/jkqtptools.h" #define SmallestGreaterZeroCompare_xvsgz() if ((xvsgz>10.0*DBL_MIN)&&((smallestGreaterZero<10.0*DBL_MIN) || (xvsgzgetPlotter()) { } JKQTPXYGraphLabels::JKQTPXYGraphLabels(const LabelGenerator &lgen, JKQTBasePlotter *parent): JKQTPXYGraphLabels(YValueLabel, parent) { setCustomLabelGenerator(lgen); } JKQTPXYGraphLabels::JKQTPXYGraphLabels(const LabelGenerator &lgen, JKQTPlotter *parent): JKQTPXYGraphLabels(lgen, parent->getPlotter()) { } JKQTPXYGraphLabels::JKQTPXYGraphLabels(LabelContentsDefaultType lt, JKQTBasePlotter* parent): JKQTPXYGraph(parent), JKQTPGraphValueLabelStyleMixin(parent) { sortData=JKQTPXYGraph::Unsorted; initValueLabelStyle(parent, parentPlotStyle, JKQTPPlotStyleType::Default); switch(lt) { case XValueLabel: setDefaultXLabelGenerator(); break; case YValueLabel: setDefaultYLabelGenerator(); break; case XYValueLabel: setDefaultXYLabelGenerator(); break; } } void JKQTPXYGraphLabels::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER JKQTPAutoOutputTimer jkaaot("JKQTPXYGraphLabels::draw"); #endif if (parent==nullptr) return; const JKQTPDatastore* datastore=parent->getDatastore(); if (datastore==nullptr) return; drawErrorsBefore(painter); { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); int imax=0; int imin=0; if (getIndexRange(imin, imax)) { for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); const double yv=datastore->get(static_cast(yColumn),static_cast(i)); const double x=transformX(xv); const double y=transformY(yv); if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv) && JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) { const QString label=generateLabel(xv,yv,iii); drawLabel(painter, QPointF(x,y), QPointF(xv,yv), label, parent); } } } } drawErrorsAfter(painter); } void JKQTPXYGraphLabels::drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.setFont(QFont(QGuiApplication::font().family(), getTextFontSize())); painter.setPen(getTextColor()); painter.drawText(rect,Qt::AlignHCenter|Qt::AlignVCenter, "12"); } QColor JKQTPXYGraphLabels::getKeyLabelColor() const { return getTextColor(); } void JKQTPXYGraphLabels::setColor(QColor c, bool setTextColor_, bool setFrameColor_) { if (setTextColor_) setTextColor(c); if (setFrameColor_) setLineColor(c); } void JKQTPXYGraphLabels::setCustomLabelGenerator(const LabelGenerator &labgen) { m_labelGenerator=labgen; } void JKQTPXYGraphLabels::setDefaultXLabelGenerator() { m_labelGenerator=std::bind(std::mem_fn(&JKQTPXYGraphLabels::generateDefaultXLabel), this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); } void JKQTPXYGraphLabels::setDefaultYLabelGenerator() { m_labelGenerator=std::bind(std::mem_fn(&JKQTPXYGraphLabels::generateDefaultYLabel), this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); } void JKQTPXYGraphLabels::setDefaultXYLabelGenerator() { m_labelGenerator=std::bind(std::mem_fn(&JKQTPXYGraphLabels::generateDefaultXYLabel), this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); } bool JKQTPXYGraphLabels::getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) { const bool baseResult=JKQTPXYGraph::getXMinMax(minx,maxx,smallestGreaterZero); if (baseResult) { /* // this does not work, as it depends on the widget size, when called!!! qDebug()<<"JKQTPXYGraphLabels::getXMinMax():"; qDebug()<<" minx="<minx="<minx="<