Skip to content

Commit

Permalink
Merge pull request #32 from Abbe98/tags-sorting
Browse files Browse the repository at this point in the history
add various sorting options to the keyword bar
  • Loading branch information
cpietsch authored May 23, 2023
2 parents 30e175f + bcd5530 commit 25a8090
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions js/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function Tags() {
var keywords = [];
var wordBackground;
var keywordsNestGlobal;
var sortKeywords = "alphabetical";

// var filterWords = ["Potsdam"];
var filterWords = [];
Expand Down Expand Up @@ -42,6 +43,10 @@ function Tags() {
.append("div")
//.attr("transform", "translate("+ margin.left +","+ margin.top +")")

if (config.sortKeywords != undefined) {
sortKeywords = config.sortKeywords;
}

tags.update();
}

Expand Down Expand Up @@ -103,10 +108,33 @@ function Tags() {
// c("num",sliceNum)

var keywordsNest = keywordsNestGlobal
.slice(0,sliceNum)
.sort(function(a,b){
.slice(0,sliceNum);

if (sortKeywords == "alphabetical") {
keywordsNest = keywordsNest.sort(function(a,b){
return d3.ascending(a.key[0], b.key[0]);
})
});
} else if (sortKeywords == "alfabetical-reverse") {
keywordsNest = keywordsNest.sort(function(a,b){
return d3.descending(a.key[0], b.key[0]);
});
} else if (sortKeywords == "count") {
keywordsNest = keywordsNest.sort(function(a,b){
return d3.descending(a.values.length, b.values.length);
});
} else if (sortKeywords == "count-reverse") {
keywordsNest = keywordsNest.sort(function(a,b){
return d3.ascending(a.values.length, b.values.length);
});
} else if (Array.isArray(sortKeywords)) {
keywordsNest = keywordsNest.sort(function(a,b){
var indexA = sortKeywords.indexOf(a.key);
var indexB = sortKeywords.indexOf(b.key);
if (indexA === -1) return 1;
if (indexB === -1) return -1;
return indexA - indexB;
});
}

// c("keywordsNest", keywordsNest);

Expand Down

0 comments on commit 25a8090

Please sign in to comment.