Skip to content

Commit 93b4c04

Browse files
committed
add sorting for alphabetical originalvalue containing labels
1 parent daf36a3 commit 93b4c04

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

CommonData/column.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,8 @@ void Column::labelsOrderByValue(bool doDbUpdateEtc)
17311731
replaceDoublesTillLabelsRowWithLabels(labelsTempCount());
17321732

17331733
doublevec asc = valuesNumericOrdered();
1734-
size_t curMax = asc.size()+1;
1734+
auto alpha = valuesAlphabeticalOffsets();
1735+
size_t ascMax = asc.size()+1;
17351736
std::map<double, int> orderMap;
17361737

17371738
for(size_t i=0; i<asc.size(); i++)
@@ -1747,7 +1748,7 @@ void Column::labelsOrderByValue(bool doDbUpdateEtc)
17471748
else
17481749
ColumnUtils::getDoubleValue(label->originalValueAsString(), aValue);
17491750

1750-
label->setOrder(!std::isnan(aValue) ? orderMap[aValue] : curMax++);
1751+
label->setOrder(!std::isnan(aValue) ? orderMap[aValue] : alpha[label] + ascMax);
17511752
}
17521753

17531754
_sortLabelsByOrder();
@@ -1776,6 +1777,26 @@ doublevec Column::valuesNumericOrdered()
17761777
return doublevec(values.begin(), values.end());
17771778
}
17781779

1780+
std::map<Label*, size_t> Column::valuesAlphabeticalOffsets()
1781+
{
1782+
std::map<Label*, size_t> labelMap;
1783+
Labels alphaLabels;
1784+
1785+
for(Label * label : _labels)
1786+
if(!label->originalValue().isDouble())
1787+
alphaLabels.push_back(label);
1788+
1789+
std::sort(alphaLabels.begin(), alphaLabels.end(), [](const Label * l, const Label * r)
1790+
{
1791+
return l->originalValueAsString() < r->originalValueAsString();
1792+
});
1793+
1794+
for(size_t l=0; l<alphaLabels.size(); l++)
1795+
labelMap[alphaLabels[l]] = l;
1796+
1797+
return labelMap;
1798+
}
1799+
17791800
void Column::valuesReverse()
17801801
{
17811802
JASPTIMER_SCOPE(Column::valuesReverse);

CommonData/column.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class Column : public DataSetBaseNode
232232

233233
static void setAutoSortByValuesByDefault(bool autoSort);
234234
static bool autoSortByValuesByDefault();
235-
235+
236236
protected:
237237
void _checkForDependencyLoop(stringset foundNames, std::list<std::string> loopList);
238238
void _dbUpdateLabelOrder(bool noIncRevisionWhenBatchedPlease = false); ///< Sets the order of the _labels to label.order and in DB
@@ -243,6 +243,7 @@ class Column : public DataSetBaseNode
243243
void _convertVectorIntToDouble(intvec & intValues, doublevec & doubleValues);
244244
void _resetLabelValueMap();
245245
doublevec valuesNumericOrdered();
246+
std::map<Label*,size_t> valuesAlphabeticalOffsets();
246247

247248
private:
248249
DataSet * const _data;

0 commit comments

Comments
 (0)