Skip to content

Commit 4bfbdac

Browse files
author
Dan Moran
committed
introduce flipPalette
1 parent d2b6079 commit 4bfbdac

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ totally indebted to [Amit's](http://www.redblobgames.com/grids/hexagons/) expana
2525
| scaleArea | Scale tile sizes proportional to value? | false |
2626
| scaleHeight | Scale tile height proportional to their value? | true |
2727
| palette | A predefined palette or palette as JSON string | redblue |
28+
| flipPalette | Reverse the palette directions? | false |
2829
| width | Width of map, in AFRAME units. | 1 |
2930
| wireframeOn | Display wireframe overlay? | false |
3031
| wireframeColor | Color of wireframe | #fff |

aframe-hexgraph-hexmap.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
hexDensityMobile:{ type: "number", default:0.1},
1919

2020
palette: { type: "string", default: 'redblue'},
21+
flipPalette: { type: "boolean", default: false},
2122
scaleHeight: { type: "boolean", default: true}, // Scale the height of each hex tile according to its value?
2223
scaleArea: { type: "boolean", default: true}, // Scale the area of each hex tile according to its value?
2324

@@ -241,7 +242,8 @@
241242
for (idx=0; idx<grid.numCells; idx++) {
242243
if (grid.cellValsAsArray[idx]===grid.NODATA) continue;
243244
grid.cellValsAsArray[idx] = grid.cellValsAsArray[idx]/maxBin;
244-
grid.cellColorsAsArray[idx] = elData.palette.length==1 ? elData.palette[0] : G.scaleColor(grid.cellValsAsArray[idx]);
245+
246+
grid.cellColorsAsArray[idx] = elData.palette.length==1 ? elData.palette[0] : G.scaleColor(data.flipPalette ? (1-grid.cellValsAsArray[idx]) : grid.cellValsAsArray[idx]);
245247
grid.cellHeightsAsArray[idx] = grid.cellValsAsArray[idx] || 0;
246248
grid.cellAreasAsArray[idx] = Math.min(0.5, Math.max(0.3, (Math.log(grid.cellValsAsArray[idx])+1)/Math.log(1.8)));
247249
}

0 commit comments

Comments
 (0)