diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 10030d225ad..62bd815df7e 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -212,12 +212,12 @@ if(JKQtPlotter_BUILD_EXAMPLES) functionplot/functionplot,functionplot_fy styledboxplot/test_styledboxplot multiplot/multiplot,multiplot_controlwindow - #symbols_and_styles + symbols_and_styles symbols_and_errors stepplots stackedbars/stackedbars,stackedbars_hor - #geo_arrows - #geo_simple + geo_arrows + geo_simple geometric imageplot/imageplot,imageplot__scale02,imageplot__smallscalelimitcolor,imageplot__smallscalecolor,imageplot__smallscaletransparent/--iteratefunctorsteps imageplot_modifier diff --git a/doc/images/keylayouts/JKQTPKeyLayout_multi_row.png b/doc/images/keylayouts/JKQTPKeyLayout_multi_row.png index c618f93ad78..374c9d0d46f 100644 Binary files a/doc/images/keylayouts/JKQTPKeyLayout_multi_row.png and b/doc/images/keylayouts/JKQTPKeyLayout_multi_row.png differ diff --git a/doc/images/keylayouts/JKQTPKeyLayout_outsidebottom_multi_column.png b/doc/images/keylayouts/JKQTPKeyLayout_outsidebottom_multi_column.png index 97fb868e112..cf06ae80aa2 100644 Binary files a/doc/images/keylayouts/JKQTPKeyLayout_outsidebottom_multi_column.png and b/doc/images/keylayouts/JKQTPKeyLayout_outsidebottom_multi_column.png differ diff --git a/doc/images/keylayouts/JKQTPKeyLayout_outsideright_multi_column.png b/doc/images/keylayouts/JKQTPKeyLayout_outsideright_multi_column.png index 4f896c5f97a..54f6a8425fc 100644 Binary files a/doc/images/keylayouts/JKQTPKeyLayout_outsideright_multi_column.png and b/doc/images/keylayouts/JKQTPKeyLayout_outsideright_multi_column.png differ diff --git a/doc/images/keylayouts/JKQTPKeyLayout_outsideright_multi_row.png b/doc/images/keylayouts/JKQTPKeyLayout_outsideright_multi_row.png index 5060979a8b2..972e692761f 100644 Binary files a/doc/images/keylayouts/JKQTPKeyLayout_outsideright_multi_row.png and b/doc/images/keylayouts/JKQTPKeyLayout_outsideright_multi_row.png differ diff --git a/lib/jkqtplotter/jkqtpkey.cpp b/lib/jkqtplotter/jkqtpkey.cpp index 0f3aa1877ac..1378c83ee7a 100644 --- a/lib/jkqtplotter/jkqtpkey.cpp +++ b/lib/jkqtplotter/jkqtpkey.cpp @@ -225,37 +225,71 @@ void JKQTPBaseKey::modifySize(JKQTPEnhancedPainter &painter, KeySizeDescription #ifdef JKQTBP_AUTOTIMER JKQTPAutoOutputTimer jkaat(QString("JKQTPBaseKey[%1]::modifySize()").arg(objectName())); #endif + // in odd cases (many plots), the initial key size may be larger than the actual plot. then we can have negative sizes. + // in these cases we correct them preliminary plot size to 80% of the widget size (=available size)! + const auto widgetSize=QSizeF(parent->getWidth(), parent->getHeight()); + if (preliminaryPlotSize.width()<0) preliminaryPlotSize.setWidth(widgetSize.width()*0.8); + if (preliminaryPlotSize.height()<0) preliminaryPlotSize.setHeight(widgetSize.height()*0.8); + + const auto lay=getLayout(); if (lay==JKQTPKeyLayoutMultiColumn || lay==JKQTPKeyLayoutMultiRow) { - std::function fCompare=[](const QSizeF& requiredSize, const QSizeF& preliminaryPlotSize) { - return true; - }; + std::function fcmpSizeTooLarge=[](const QSizeF& requiredSize, const QSizeF& preliminaryPlotSize) { return true; }; + + bool increaseColumnCount=true; + bool fillMaxMode=false; if (currentKeyLayout.keyLocation==KeySizeDescription::keyInside) { - fCompare=[](const QSizeF& requiredSize, const QSizeF& preliminaryPlotSize) { + fcmpSizeTooLarge=[](const QSizeF& requiredSize, const QSizeF& preliminaryPlotSize) { return (requiredSize.width()>preliminaryPlotSize.width() || requiredSize.height()>preliminaryPlotSize.height()); - }; + }; } else if (currentKeyLayout.keyLocation==KeySizeDescription::keyOutsideTop || currentKeyLayout.keyLocation==KeySizeDescription::keyOutsideBottom) { - fCompare=[](const QSizeF& requiredSize, const QSizeF& preliminaryPlotSize) { - return (requiredSize.height()>preliminaryPlotSize.height()); - }; + fcmpSizeTooLarge=[widgetSize](const QSizeF& requiredSize, const QSizeF& preliminaryPlotSize) { + return (requiredSize.width()>preliminaryPlotSize.width()); + }; + increaseColumnCount=true; + fillMaxMode=true; + } else if (currentKeyLayout.keyLocation==KeySizeDescription::keyOutsideLeft || currentKeyLayout.keyLocation==KeySizeDescription::keyOutsideRight) { - fCompare=[](const QSizeF& requiredSize, const QSizeF& preliminaryPlotSize) { - return (requiredSize.width()>preliminaryPlotSize.width()); - }; + fcmpSizeTooLarge=[widgetSize](const QSizeF& requiredSize, const QSizeF& preliminaryPlotSize) { + return (requiredSize.height()>preliminaryPlotSize.height()); + }; + increaseColumnCount=false; + fillMaxMode=true; } const int itemCnt=currentKeyLayout.d->countItems(); - int newCount=1; - while ((newCount<=itemCnt) && (currentKeyLayout.requiredSize.width()>preliminaryPlotSize.width() || currentKeyLayout.requiredSize.height()>preliminaryPlotSize.height())) { - newCount++; - if (lay==JKQTPKeyLayoutMultiColumn) { - currentKeyLayout.d->redistributeOverColumns(newCount); - } else if (lay==JKQTPKeyLayoutMultiRow) { - currentKeyLayout.d->redistributeOverRows(newCount); + const auto initialLayout=currentKeyLayout; + if (fillMaxMode) { + int newCount=itemCnt+1; + bool notSizeOK=true; + while (newCount>1 && notSizeOK) { + newCount--; // increase number of rows/columns + currentKeyLayout=initialLayout; // reset to initial layout, which should have one column only! + // this is required, so redistribute...() does not scramble the order + if (increaseColumnCount) { + currentKeyLayout.d->redistributeOverColumns(newCount, lay==JKQTPKeyLayoutMultiColumn); + } else { + currentKeyLayout.d->redistributeOverRows(newCount, lay==JKQTPKeyLayoutMultiRow); + } + calcLayoutSize(painter, currentKeyLayout); + notSizeOK=fcmpSizeTooLarge(currentKeyLayout.requiredSize, preliminaryPlotSize); + } + } else { + int newCount=1; + while (newCountredistributeOverColumns(newCount, lay==JKQTPKeyLayoutMultiColumn); + } else { + currentKeyLayout.d->redistributeOverRows(newCount, lay==JKQTPKeyLayoutMultiRow); + } + calcLayoutSize(painter, currentKeyLayout); } - calcLayoutSize(painter, currentKeyLayout); } + } } @@ -380,6 +414,7 @@ JKQTPBaseKey::KeySizeDescription &JKQTPBaseKey::KeySizeDescription::operator=(co return *this; } + JKQTPBaseKey::KeyColumnDescription::KeyColumnDescription(): rows() { @@ -470,12 +505,12 @@ void JKQTPBaseKey::KeyLayoutDescription::redistributeIntoOneColumn() } } -void JKQTPBaseKey::KeyLayoutDescription::redistributeOverRows(int rowCnt) +void JKQTPBaseKey::KeyLayoutDescription::redistributeOverRows(int rowCnt, bool rowMajor) { const int itemCnt=countItems(); if (itemCnt>1) { const int colCnt=static_cast(ceil(static_cast(itemCnt)/static_cast(rowCnt))); - if (colCnt>1) { + if (true) { redistributeIntoOneColumn(); const auto items=columns[0].rows; columns.clear(); @@ -484,17 +519,26 @@ void JKQTPBaseKey::KeyLayoutDescription::redistributeOverRows(int rowCnt) for (int c=0; c1) { @@ -506,9 +550,20 @@ void JKQTPBaseKey::KeyLayoutDescription::redistributeOverColumns(int colCnt) int i=0; for (int c=0; c