Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dist/types/heatmap.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export declare class HeatmapRenderer {
intensity: number;
translate: [number, number];
opacity: number;
disableCircularFalloff: boolean;
hearmapExData: HearmapExData | object;
gradient: MappedGradient | null;
_imageTexture: WebGLTexture | null;
Expand Down Expand Up @@ -91,6 +92,12 @@ export declare class HeatmapRenderer {
*/
setOpacity(opacity: number): HeatmapRenderer;
/**
* Set whether to disable circular falloff
* @param disableCircularFalloff - Boolean to disable circular falloff effect.
* @returns instance
*/
setDisableCircularFalloff(disableCircularFalloff: boolean): HeatmapRenderer;
/**
* Set the background image
* @param config - Accepts Object with { url, height, width, x, and y} properties
* @returns instance
Expand Down
1 change: 1 addition & 0 deletions dist/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type HeatmapConfig = {
opacity?: number;
gradient: GradientElement[];
backgroundImage?: BackgroundImageConfig;
disableCircularFalloff?: boolean;
};
export type HearmapExData = {
posVec: Float32Array;
Expand Down
31 changes: 29 additions & 2 deletions dist/visualHeatmap.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const GradShader = {
uniform float u_max;
uniform float u_min;
uniform float u_intensity;
uniform bool u_disableCircularFalloff;
in float v_i;
out vec4 fragColor;

Expand All @@ -71,7 +72,15 @@ const GradShader = {
float deno = max(u_max - u_min, 1e-6); // Prevent division by zero

if(r <= 1.0) {
float alpha = ((v_i - u_min) / deno) * u_intensity * (1.0 - sqrt(r));
float alpha;
if(u_disableCircularFalloff) {
// No circular falloff - uniform intensity within the point
alpha = ((v_i - u_min) / deno) * u_intensity;
} else {
// Apply circular falloff for smoother gradients
alpha = ((v_i - u_min) / deno) * u_intensity * (1.0 - sqrt(r));
}

alpha = clamp(alpha, 0.0, 1.0); // Clamp alpha to valid range
fragColor = vec4(0, 0, 0, alpha);
} else {
Expand Down Expand Up @@ -295,6 +304,7 @@ const createGradiantShader = function (ctx, shader) {
u_zoom: ctx.getUniformLocation(program, "u_zoom"),
u_angle: ctx.getUniformLocation(program, "u_angle"),
u_density: ctx.getUniformLocation(program, "u_density"),
u_disableCircularFalloff: ctx.getUniformLocation(program, "u_disableCircularFalloff"),
},
};
};
Expand Down Expand Up @@ -458,7 +468,7 @@ function renderExec() {
function renderHeatGrad(ctx, exData) {
var _a, _b, _c, _d;
ctx.useProgram(this._gradShadOP.program);
const { u_resolution, u_translate, u_zoom, u_angle, u_density, u_max, u_min, u_size, u_intensity } = this._gradShadOP.uniform;
const { u_resolution, u_translate, u_zoom, u_angle, u_density, u_max, u_min, u_size, u_intensity, u_disableCircularFalloff } = this._gradShadOP.uniform;
this.min =
this.configMin !== null ? this.configMin : (_b = (_a = exData === null || exData === void 0 ? void 0 : exData.minMax) === null || _a === void 0 ? void 0 : _a.min) !== null && _b !== void 0 ? _b : 0;
this.max =
Expand All @@ -474,12 +484,16 @@ function renderHeatGrad(ctx, exData) {
ctx.uniform1f(u_min, this.min);
ctx.uniform1f(u_size, this.size);
ctx.uniform1f(u_intensity, this.intensity);
ctx.uniform1i(u_disableCircularFalloff, this.disableCircularFalloff ? 1 : 0);
this._gradShadOP.attr.forEach(function (d) {
ctx.bindBuffer(d.bufferType, d.buffer);
ctx.bufferData(d.bufferType, d.data, d.drawType);
ctx.enableVertexAttribArray(d.attribute);
ctx.vertexAttribPointer(d.attribute, d.size, d.valueType, true, 0, 0);
});
if (this.disableCircularFalloff) {
ctx.blendEquation(ctx.MAX);
}
ctx.drawArrays(ctx.POINTS, 0, (exData.posVec || []).length / 2);
}
function renderImage(ctx, imageConfig) {
Expand Down Expand Up @@ -559,6 +573,7 @@ class HeatmapRenderer {
this.intensity = 0;
this.translate = [0, 0];
this.opacity = 0;
this.disableCircularFalloff = false;
this.hearmapExData = {};
this.gradient = null;
this._imageTexture = null;
Expand Down Expand Up @@ -806,6 +821,18 @@ class HeatmapRenderer {
return this;
}
/**
* Set whether to disable circular falloff
* @param disableCircularFalloff - Boolean to disable circular falloff effect.
* @returns instance
*/
setDisableCircularFalloff(disableCircularFalloff) {
if (typeof disableCircularFalloff !== 'boolean') {
throw new Error('Invalid disableCircularFalloff: Expected Boolean');
}
this.disableCircularFalloff = disableCircularFalloff;
return this;
}
/**
* Set the background image
* @param config - Accepts Object with { url, height, width, x, and y} properties
* @returns instance
Expand Down
2 changes: 1 addition & 1 deletion dist/visualHeatmap.esm.min.js

Large diffs are not rendered by default.

31 changes: 29 additions & 2 deletions dist/visualHeatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ vec2 rotation(vec2 v, float a, float aspect) {
uniform float u_max;
uniform float u_min;
uniform float u_intensity;
uniform bool u_disableCircularFalloff;
in float v_i;
out vec4 fragColor;

Expand All @@ -77,7 +78,15 @@ vec2 rotation(vec2 v, float a, float aspect) {
float deno = max(u_max - u_min, 1e-6); // Prevent division by zero

if(r <= 1.0) {
float alpha = ((v_i - u_min) / deno) * u_intensity * (1.0 - sqrt(r));
float alpha;
if(u_disableCircularFalloff) {
// No circular falloff - uniform intensity within the point
alpha = ((v_i - u_min) / deno) * u_intensity;
} else {
// Apply circular falloff for smoother gradients
alpha = ((v_i - u_min) / deno) * u_intensity * (1.0 - sqrt(r));
}

alpha = clamp(alpha, 0.0, 1.0); // Clamp alpha to valid range
fragColor = vec4(0, 0, 0, alpha);
} else {
Expand Down Expand Up @@ -301,6 +310,7 @@ vec2 rotation(vec2 v, float a, float aspect) {
u_zoom: ctx.getUniformLocation(program, "u_zoom"),
u_angle: ctx.getUniformLocation(program, "u_angle"),
u_density: ctx.getUniformLocation(program, "u_density"),
u_disableCircularFalloff: ctx.getUniformLocation(program, "u_disableCircularFalloff"),
},
};
};
Expand Down Expand Up @@ -464,7 +474,7 @@ vec2 rotation(vec2 v, float a, float aspect) {
function renderHeatGrad(ctx, exData) {
var _a, _b, _c, _d;
ctx.useProgram(this._gradShadOP.program);
const { u_resolution, u_translate, u_zoom, u_angle, u_density, u_max, u_min, u_size, u_intensity } = this._gradShadOP.uniform;
const { u_resolution, u_translate, u_zoom, u_angle, u_density, u_max, u_min, u_size, u_intensity, u_disableCircularFalloff } = this._gradShadOP.uniform;
this.min =
this.configMin !== null ? this.configMin : (_b = (_a = exData === null || exData === void 0 ? void 0 : exData.minMax) === null || _a === void 0 ? void 0 : _a.min) !== null && _b !== void 0 ? _b : 0;
this.max =
Expand All @@ -480,12 +490,16 @@ vec2 rotation(vec2 v, float a, float aspect) {
ctx.uniform1f(u_min, this.min);
ctx.uniform1f(u_size, this.size);
ctx.uniform1f(u_intensity, this.intensity);
ctx.uniform1i(u_disableCircularFalloff, this.disableCircularFalloff ? 1 : 0);
this._gradShadOP.attr.forEach(function (d) {
ctx.bindBuffer(d.bufferType, d.buffer);
ctx.bufferData(d.bufferType, d.data, d.drawType);
ctx.enableVertexAttribArray(d.attribute);
ctx.vertexAttribPointer(d.attribute, d.size, d.valueType, true, 0, 0);
});
if (this.disableCircularFalloff) {
ctx.blendEquation(ctx.MAX);
}
ctx.drawArrays(ctx.POINTS, 0, (exData.posVec || []).length / 2);
}
function renderImage(ctx, imageConfig) {
Expand Down Expand Up @@ -565,6 +579,7 @@ vec2 rotation(vec2 v, float a, float aspect) {
this.intensity = 0;
this.translate = [0, 0];
this.opacity = 0;
this.disableCircularFalloff = false;
this.hearmapExData = {};
this.gradient = null;
this._imageTexture = null;
Expand Down Expand Up @@ -812,6 +827,18 @@ vec2 rotation(vec2 v, float a, float aspect) {
return this;
}
/**
* Set whether to disable circular falloff
* @param disableCircularFalloff - Boolean to disable circular falloff effect.
* @returns instance
*/
setDisableCircularFalloff(disableCircularFalloff) {
if (typeof disableCircularFalloff !== 'boolean') {
throw new Error('Invalid disableCircularFalloff: Expected Boolean');
}
this.disableCircularFalloff = disableCircularFalloff;
return this;
}
/**
* Set the background image
* @param config - Accepts Object with { url, height, width, x, and y} properties
* @returns instance
Expand Down
2 changes: 1 addition & 1 deletion dist/visualHeatmap.min.js

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion src/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function renderHeatGrad(
) {
ctx.useProgram(this._gradShadOP.program);

const {u_resolution, u_translate, u_zoom, u_angle, u_density, u_max, u_min, u_size, u_intensity } = this._gradShadOP.uniform;
const {u_resolution, u_translate, u_zoom, u_angle, u_density, u_max, u_min, u_size, u_intensity, u_disableCircularFalloff } = this._gradShadOP.uniform;
this.min =
this.configMin !== null ? this.configMin : exData?.minMax?.min ?? 0;
this.max =
Expand All @@ -189,6 +189,7 @@ function renderHeatGrad(
ctx.uniform1f(u_min, this.min);
ctx.uniform1f(u_size, this.size);
ctx.uniform1f(u_intensity, this.intensity);
ctx.uniform1i(u_disableCircularFalloff, this.disableCircularFalloff ? 1 : 0);

this._gradShadOP.attr.forEach(function (d) {
ctx.bindBuffer(d.bufferType, d.buffer);
Expand All @@ -197,6 +198,10 @@ function renderHeatGrad(
ctx.vertexAttribPointer(d.attribute, d.size, d.valueType, true, 0, 0);
});

if (this.disableCircularFalloff) {
ctx.blendEquation(ctx.MAX);
}

ctx.drawArrays(ctx.POINTS, 0, (exData.posVec || []).length / 2);
}

Expand Down Expand Up @@ -307,6 +312,7 @@ export class HeatmapRenderer {
intensity: number = 0;
translate: [number, number] = [0, 0];
opacity: number = 0;
disableCircularFalloff: boolean = false;
hearmapExData: HearmapExData | object = {};

gradient: MappedGradient | null = null;
Expand Down Expand Up @@ -590,6 +596,19 @@ export class HeatmapRenderer {
return this;
}

/**
* Set whether to disable circular falloff
* @param disableCircularFalloff - Boolean to disable circular falloff effect.
* @returns instance
*/
setDisableCircularFalloff(disableCircularFalloff: boolean): HeatmapRenderer {
if (typeof disableCircularFalloff !== 'boolean') {
throw new Error('Invalid disableCircularFalloff: Expected Boolean');
}
this.disableCircularFalloff = disableCircularFalloff;
return this;
}

/**
* Set the background image
* @param config - Accepts Object with { url, height, width, x, and y} properties
Expand Down
11 changes: 10 additions & 1 deletion src/shaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const GradShader = {
uniform float u_max;
uniform float u_min;
uniform float u_intensity;
uniform bool u_disableCircularFalloff;
in float v_i;
out vec4 fragColor;

Expand All @@ -68,7 +69,15 @@ export const GradShader = {
float deno = max(u_max - u_min, 1e-6); // Prevent division by zero

if(r <= 1.0) {
float alpha = ((v_i - u_min) / deno) * u_intensity * (1.0 - sqrt(r));
float alpha;
if(u_disableCircularFalloff) {
// No circular falloff - uniform intensity within the point
alpha = ((v_i - u_min) / deno) * u_intensity;
} else {
// Apply circular falloff for smoother gradients
alpha = ((v_i - u_min) / deno) * u_intensity * (1.0 - sqrt(r));
}

alpha = clamp(alpha, 0.0, 1.0); // Clamp alpha to valid range
fragColor = vec4(0, 0, 0, alpha);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type HeatmapConfig = {
opacity?: number;
gradient: GradientElement[];
backgroundImage?: BackgroundImageConfig;
disableCircularFalloff?: boolean;
};

export type HearmapExData = {
Expand Down
1 change: 1 addition & 0 deletions src/utils/shaderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const createGradiantShader = function (
u_zoom: ctx.getUniformLocation(program, "u_zoom"),
u_angle: ctx.getUniformLocation(program, "u_angle"),
u_density: ctx.getUniformLocation(program, "u_density"),
u_disableCircularFalloff: ctx.getUniformLocation(program, "u_disableCircularFalloff"),
},
};
};
Expand Down