Skip to content

Commit

Permalink
Code: sorting: remembered per color set
Browse files Browse the repository at this point in the history
  • Loading branch information
SAKryukov committed Nov 6, 2023
1 parent 888e681 commit 6bab6c6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions code/js/colors/sorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const orderSet = (() => {

const sort = (colorMapMetadata, sort, inverted) => {
const sort = (colorMapMetadata, sort, reverse) => {

if (!colorMapMetadata.isRemapped) return;

Expand All @@ -14,13 +14,13 @@ const orderSet = (() => {
right = colorMapMetadata.map.get(right).color;
const leftHsl = conversionSet.rgbToHsl(left[0], left[1], left[2], left[3]);
const rightHsl = conversionSet.rgbToHsl(right[0], right[1], right[2], right[3]);
const sign = inverted ? -1 : 1;
const sign = reverse ? -1 : 1;
return sign * (hslToFactor(rightHsl) - hslToFactor(leftHsl));
}; //compare

const nameCompare = (left, right) => {
if (left == right) return 0;
return right > left ? (inverted ? 1 : -1) : (inverted ? -1 : 1);
return right > left ? (reverse ? 1 : -1) : (reverse ? -1 : 1);
} //nameCompare

colorMapMetadata.source.sort(sort ? compare : nameCompare);
Expand Down
2 changes: 1 addition & 1 deletion code/js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
header { background-color: aliceBlue; }
footer { background-color: beige; }
header, footer, main { padding: var(--padding); }
header p > * { vertical-align: middle; }
header p > * { vertical-align: bottom; }
header p select { margin-left: var(--deltaX); font-size: 100%; padding-left: var(--padding-horizontal); padding-right: var(--padding-horizontal); }
main { border-top: solid thin gray; border-bottom: solid thin gray; }
input[type=radio]:last-of-type { margin-left: var(--deltaX); }
Expand Down
8 changes: 5 additions & 3 deletions code/js/ui/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ window.onload = () => {
const elements = getElements();
elements.metadata.copyright.textContent = definitionSet.metadata.copyright;
elements.metadata.version.textContent = definitionSet.metadata.version;
const cssColorMapMetadata = { source: cssColorNames, map: new Map(), isRemapped: false };
const wpfColorMapMetadata = { source: wpfColorNames, map: new Map(), isRemapped: false };
const cssColorMapMetadata = { source: cssColorNames, map: new Map(), orderIndex: 0, isRemapped: false };
const wpfColorMapMetadata = { source: wpfColorNames, map: new Map(), orderIndex: 0, isRemapped: false };

const remap = colorMapMetadata => {
if (colorMapMetadata.isRemapped) return;
Expand All @@ -22,6 +22,7 @@ window.onload = () => {
const dataSourceHandler = (event, colorMapMetadata) => {
if (event.target.checked) {
populate(colorMapMetadata);
elements.sort.selectedIndex = colorMapMetadata.orderIndex;
if (colorMapMetadata.isRemapped) return
const remapPromise = new Promise(resolve => resolve(colorMapMetadata));
remapPromise.then(metadata => {
Expand Down Expand Up @@ -150,9 +151,10 @@ window.onload = () => {
select(currentCell, true);
}; //populate
populate(cssColorMapMetadata);
;

elements.sort.onchange = event => {
let sort; let inverted;
currentColorMapMetadata.orderIndex = event.target.selectedIndex;
switch (event.target.selectedIndex) {
case 0: sort = undefined; inverted = false; break;
case 1: sort = undefined; inverted = true; break;
Expand Down

0 comments on commit 6bab6c6

Please sign in to comment.