Use XOR for font coloring. Scale greyscale color swatch correctly.

This commit is contained in:
Bill Thiede 2019-10-26 15:01:23 -07:00
parent 134bfdbd4f
commit 9b1080c43e

View File

@ -12,10 +12,14 @@ const DATA_URL = ROOT + 'data.json';
const MAX_ZOOM_FACTOR = 32; const MAX_ZOOM_FACTOR = 32;
const Sidebar = (props) => { const Sidebar = (props) => {
let {binary, imageMetadata, zoomFactor, x, y, onZoom} = props; let {
binary, binaryMax, imageMetadata, zoomFactor, x, y,
onZoom,
} = props;
let samples = imageMetadata.map((md) => { let samples = imageMetadata.map((md) => {
let pix = binary[md.name]; let pix = binary[md.name];
if (pix === undefined) { return <p key={md.name}>Loading...</p>; } if (pix === undefined) { return <p key={md.name}>Loading...</p>; }
let max = binaryMax[md.name];
let [w, h] = md.size; let [w, h] = md.size;
let xOff = Math.min(w, Math.max(0, Math.round(x*w))); let xOff = Math.min(w, Math.max(0, Math.round(x*w)));
let yOff = Math.min(h, Math.max(0, Math.round(y*h))); let yOff = Math.min(h, Math.max(0, Math.round(y*h)));
@ -24,6 +28,7 @@ const Sidebar = (props) => {
console.log(`${x} ${y} ${w} ${h} ${xOff} ${yOff} ${v} ${pix.length}`); console.log(`${x} ${y} ${w} ${h} ${xOff} ${yOff} ${v} ${pix.length}`);
return <p key={md.name}>Loading...</p>; return <p key={md.name}>Loading...</p>;
} }
let color = "#fff";
let rgb = ""; let rgb = "";
let value = ""; let value = "";
if (md.format === "RGB01") { if (md.format === "RGB01") {
@ -31,14 +36,20 @@ const Sidebar = (props) => {
let g = Math.round(v[1]*255); let g = Math.round(v[1]*255);
let b = Math.round(v[2]*255); let b = Math.round(v[2]*255);
rgb = `rgb(${r}, ${g}, ${b})`; rgb = `rgb(${r}, ${g}, ${b})`;
color = `rgb(${255^r}, ${255^g}, ${255^b})`;
value = rgb; value = rgb;
} else { } else {
rgb = `rgb(${v}, ${v}, ${v})`; let c = 255*v/max;
rgb = `rgb(${c}, ${c}, ${c})`;
color = `rgb(${255^c}, ${255^c}, ${255^c})`;
value = v; value = v;
} }
return <div className="sample" key={md.name}> return <div className="sample" key={md.name}>
<p>{md.name}</p> <p>{md.name}</p>
<p className="value" style={{backgroundColor: rgb}}>{value}</p> <p className="value" style={{
color,
backgroundColor: rgb,
}}>{value}</p>
</div> </div>
}); });
return <aside className="menu"> return <aside className="menu">
@ -71,6 +82,7 @@ class App extends React.Component {
this.state = { this.state = {
data: null, data: null,
binary: {}, binary: {},
binaryMax: {},
isFetching: false, isFetching: false,
isFrozen: false, isFrozen: false,
isZoomed: false, isZoomed: false,
@ -88,6 +100,8 @@ class App extends React.Component {
} }
fetchTracerData() { fetchTracerData() {
this.setState({...this.state, isFetching: true}) this.setState({...this.state, isFetching: true})
const max = (acc, cur) => Math.max(acc, cur);
// console.log(array1.reduce(max));
fetch(DATA_URL) fetch(DATA_URL)
.then(response => response.json()) .then(response => response.json())
.then(result => { .then(result => {
@ -101,10 +115,19 @@ class App extends React.Component {
.then(response => response.json()) .then(response => response.json())
.then(result => { .then(result => {
let curBinary = this.state.binary; let curBinary = this.state.binary;
this.setState({binary: { let curBinaryMax = this.state.binaryMax;
[md.name]: result, let binaryMax = result.reduce(max);
...curBinary console.log(`${md.name} ${binaryMax}`);
}}); this.setState({
binary: {
[md.name]: result,
...curBinary
},
binaryMax: {
[md.name]: binaryMax,
...curBinaryMax
}
});
}) })
.catch(e => console.log(e)); .catch(e => console.log(e));
}); });
@ -118,6 +141,7 @@ class App extends React.Component {
let images = []; let images = [];
let { let {
binary, binary,
binaryMax,
data, data,
isFrozen, isFrozen,
isZoomed, isZoomed,
@ -206,6 +230,7 @@ class App extends React.Component {
zoomFactor={zoomFactor} zoomFactor={zoomFactor}
x={x} y={y} x={x} y={y}
binary={binary} binary={binary}
binaryMax={binaryMax}
onZoom={onZoom} />; onZoom={onZoom} />;
} }
return ( return (