Commit 47f87a56 authored by anneb's avatar anneb

addjust classCount to max available colors

parent 98f1d353
...@@ -345,18 +345,24 @@ ...@@ -345,18 +345,24 @@
// legendTypes 'div', 'qual', 'seq' // legendTypes 'div', 'qual', 'seq'
// for diverging, qualitative and sequential legends // for diverging, qualitative and sequential legends
function getColorSchemes(numClasses, legendType) { function getColorSchemes(numClasses, legendType) {
return colorbrewer.filter(scheme=>scheme.type===legendType && scheme.sets.length > numClasses - 3) for (; numClasses > 2; numClasses--) {
.map(scheme=>{ let result = colorbrewer.filter(scheme=>scheme.type===legendType && scheme.sets.length > numClasses - 3)
const result = scheme.sets[numClasses - 3]; .map(scheme=>{
result.name = scheme.name; const result = scheme.sets[numClasses - 3];
result.type = scheme.type; result.name = scheme.name;
return result; result.type = scheme.type;
}); return result;
});
if (result.length) {
return result;
}
}
return [];
} }
function classButton(classType) { function classButton(classType) {
if (prepareLegend()) { if (prepareLegend()) {
const classCount = Number(document.querySelector('#classcount').value); let classCount = Number(document.querySelector('#classcount').value);
if (classCount === 1) { if (classCount === 1) {
// special case, single classification // special case, single classification
} else { } else {
...@@ -406,7 +412,9 @@ ...@@ -406,7 +412,9 @@
result.push(percentile); result.push(percentile);
return result; return result;
},[]); },[]);
const seqSchemes = getColorSchemes(classCount, 'qual'); const legendType = (typeof percentileBreaks[0].value === "string") ? 'qual' : 'seq';
const seqSchemes = getColorSchemes(classCount, legendType);
classCount = seqSchemes[0].colors.length;
if (classCount > percentileBreaks.length) { if (classCount > percentileBreaks.length) {
classCount = percentileBreaks.length classCount = percentileBreaks.length
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment