WebGLModule.BipolarHeatmapLayer = class extends WebGLModule.VisualizationLayer {
static type() {
return "bipolar-heatmap";
}
static name() {
return "Bi-polar Heatmap";
}
static description() {
return "values are of two categories, smallest considered in the middle";
}
static sources() {
return [{
acceptsChannelCount: (x) => x===1,
description: "1D diverging data encoded in opacity"
}];
}
static defaultControls = {
colorHigh: {
default: {type: "color", default: "#ff1000", title: "Color High: "},
accepts: (type, instance) => type === "vec3",
},
colorLow: {
default: {type: "color", default: "#01ff00", title: "Color Low: "},
accepts: (type, instance) => type === "vec3"
},
threshold: {
default: {type: "range_input", default: 1, min: 1, max: 100, step: 1, title: "Threshold: "},
accepts: (type, instance) => type === "float"
},
};
getFragmentShaderExecution() {
return `
float chan = ${this.sampleChannel('tile_texture_coords', 0, true)};
if (!close(chan, .5)) {
if (chan < .5) {
chan = ${this.filter(`1.0 - chan * 2.0`)};
if (chan > ${this.threshold.sample('chan', 'float')}) {
return vec4(${this.colorLow.sample('chan', 'float')}, chan);
}
return vec4(.0);
}
chan = ${this.filter(`(chan - 0.5) * 2.0`)};
if (chan > ${this.threshold.sample('chan', 'float')}) {
return vec4(${this.colorHigh.sample('chan', 'float')}, chan);
}
return vec4(.0);
}
`;
}
htmlControls() {
return [
this.colorHigh.toHtml(true),
this.colorLow.toHtml(true),
this.opacity.toHtml(true),
this.threshold.toHtml(true)
].join("");
}
};
WebGLModule.ShaderMediator.registerLayer(WebGLModule.BipolarHeatmapLayer);