Skip to content

Commit

Permalink
colormap math
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmorris committed Feb 24, 2017
1 parent 8223202 commit 2d95f47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import './Matrix.css';
import {NOINDEX, MODE} from './constants.js';
import config from './config.js';

// TODO: colormap docs (https://www.npmjs.com/package/colormap) say that n>10
// should be enough divisions for any colormap, but using the 'warm' colormap
// with n=12 led to 4 repeated colors. Should file a bug.
var MIN_COLORS = 128;

/** For reasons of performance, we separate the highlighting effects we do on
* hover into a separate component from the basic structure of the matrix. The
* former will change frequently, and the latter rarely (only when the user
Expand All @@ -22,7 +27,7 @@ class BaseMatrix extends Component {
return colormap({colormap: "warm", nshades: 11});
} else {
return colormap({colormap: config.colormap,
nshades: Math.max(11, this.props.verse.nWords)});
nshades: Math.max(MIN_COLORS, this.props.verse.nWords)});
}
}

Expand Down Expand Up @@ -60,6 +65,9 @@ class BaseMatrix extends Component {
if (i === -1) { // hapax
return 'black';
}
if (this.props.verse.nWords < MIN_COLORS) {
i = Math.floor(i * (MIN_COLORS / this.props.verse.nWords));
}
return this.cm[i];
} else if (this.props.mode === MODE.color_title) {
// TODO: maybe should only color intact instances of the title? kind of
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {MODE} from './constants.js';

var config = {
alleys: true,
colormap: 'hsv',
colormap: 'warm',
default_mode: MODE.vanilla,
debug: true,
};
Expand Down

0 comments on commit 2d95f47

Please sign in to comment.