Skip to content

Commit

Permalink
Adapting Hardcoded Data Normalization to Dynamic Ranges in Visualizat…
Browse files Browse the repository at this point in the history
…ion (#30)

* Uptated the plots to make the grouping bars dependent on actual ranges

* Bump up lib version

* Made xAxisRange Dynamic
  • Loading branch information
OssamaRafique authored Nov 15, 2023
1 parent 84dd21b commit 123fd6c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "epiviz.heatmap.gl",
"version": "0.0.19",
"version": "0.0.20",
"repository": "https://github.com/jkanche/epiviz.heatmap.gl",
"homepage": "https://github.com/jkanche/epiviz.heatmap.gl",
"author": {
Expand Down
26 changes: 18 additions & 8 deletions src/BaseGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
DEFAULT_ROW_LABEL_FONT_SIZE,
DEFAULT_ROW_LABEL_SLINT_ANGLE,
DEFAULT_ROW_MAX_LABEL_LENGTH_ALLOWED,
DEFAULT_VISIBLE_RANGE,
LABELS_MARGIN_BUFFER_IN_PX,
INTENSITY_LEGEND_LABEL_SIZE_IN_PX,
INTENSITY_LEGEND_GRADIENT_SIZE_IN_PX,
Expand Down Expand Up @@ -67,6 +66,10 @@ class BaseGL {
ylabels: null,
};

// Plot domain
this.xAxisRange = null;
this.yAxisRange = null;

// state
this.state = {
size: 20,
Expand Down Expand Up @@ -893,7 +896,7 @@ class BaseGL {
**/
renderRowGroupingLegend() {
const position = this.rowGroupingLegendPosition;
const visibleRange = this.viewport?.yRange || DEFAULT_VISIBLE_RANGE;
const visibleRange = this.viewport?.yRange || this.yAxisRange;

if (
!this.rowGroupingLegendDomElement ||
Expand Down Expand Up @@ -927,10 +930,13 @@ class BaseGL {
const yScale = scaleLinear()
.domain(visibleRange) // Input range is currently visible range
.range([svgHeight, 0]); // Output range is SVG height
const maxYRange = this.yAxisRange[1] - this.yAxisRange[0];
const minY = this.yAxisRange[0];

this.groupingRowData.forEach((group, idx) => {
const normalizedStart = (group.startIndex * 2) / totalData - 1;
const normalizedEnd = ((group.endIndex + 1) * 2) / totalData - 1;
const normalizedStart = (group.startIndex / totalData) * maxYRange + minY;
const normalizedEnd =
((group.endIndex + 1) / totalData) * maxYRange + minY;

if (
normalizedEnd >= visibleRange[0] &&
Expand Down Expand Up @@ -973,7 +979,7 @@ class BaseGL {
* */
renderColumnGroupingLegend() {
const position = this.columnGroupingLegendPosition; // should be 'top' or 'bottom'
const visibleRange = this.viewport?.xRange || DEFAULT_VISIBLE_RANGE;
const visibleRange = this.viewport?.xRange || this.xAxisRange;

// Only render the legend if we have the legend data, the dom element,
// the position is either 'top' or 'bottom' and visibleRange exists
Expand Down Expand Up @@ -1013,9 +1019,13 @@ class BaseGL {
.domain(visibleRange) // Input range is currently visible range
.range([0, svgWidth]); // Output range is SVG width

this.groupingColumnData.forEach((group, idx) => {
const normalizedStart = (group.startIndex * 2) / totalData - 1;
const normalizedEnd = ((group.endIndex + 1) * 2) / totalData - 1;
const maxXRange = this.xAxisRange[1] - this.xAxisRange[0];
const minX = this.xAxisRange[0];

this.groupingRowData.forEach((group, idx) => {
const normalizedStart = (group.startIndex / totalData) * maxXRange + minX;
const normalizedEnd =
((group.endIndex + 1) / totalData) * maxXRange + minX;

if (
normalizedEnd >= visibleRange[0] &&
Expand Down
9 changes: 7 additions & 2 deletions src/DotplotGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class DotplotGL extends BaseGL {
const [, maxY] = getMinMax(this.input.y);
let xlen = maxX + 1,
ylen = maxY + 1;

spec_inputs.x = mapArrayOrTypedArray(
this.input.x,
(e, i) => -1 + (2 * e + 1) / xlen
Expand All @@ -108,6 +109,10 @@ class DotplotGL extends BaseGL {
(e, i) => -1 + (2 * e + 1) / ylen
);

// Setting X and Y Axis Domains
this.xAxisRange = spec_inputs.x;
this.yAxisRange = spec_inputs.y;

let spec = {
margins: this.margins,
defaultData: {
Expand All @@ -122,12 +127,12 @@ class DotplotGL extends BaseGL {
x: {
attribute: "x",
type: "quantitative",
domain: [-1, 1],
domain: this.xAxisRange,
},
y: {
attribute: "y",
type: "quantitative",
domain: [-1, 1],
domain: this.yAxisRange,
},
opacity: { value: this.state.opacity },
},
Expand Down
5 changes: 5 additions & 0 deletions src/RectplotGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class RectplotGL extends BaseGL {
};

let spec_inputs = {};

// Setting X and Y Axis Domains to [-1, 1]
this.xAxisRange = [-1, 1];
this.yAxisRange = [-1, 1];

spec_inputs.x = mapArrayOrTypedArray(this.input.x, (e, i) => String(e));
spec_inputs.y = mapArrayOrTypedArray(this.input.y, (e, i) => String(e));

Expand Down
8 changes: 6 additions & 2 deletions src/TickplotGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class TickplotGL extends BaseGL {
}
}

// Setting X and Y Axis Domains
this.xAxisRange = getMinMax(this.input.x);
this.yAxisRange = getMinMax(this.input.y);

let spec = {
margins: this.margins,
defaultData: {
Expand All @@ -90,12 +94,12 @@ class TickplotGL extends BaseGL {
x: {
attribute: "x",
type: "quantitative",
domain: getMinMax(this.input.x),
domain: this.xAxisRange,
},
y: {
attribute: "y",
type: "quantitative",
domain: getMinMax(this.input.y),
domain: this.yAxisRange,
},
opacity: { value: this.state.opacity },
width: { value: default_width },
Expand Down
1 change: 0 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const DEFAULT_ROW_LABEL_SLINT_ANGLE = 0;
export const DEFAULT_COLUMN_LABEL_SLINT_ANGLE = 0;
export const DEFAULT_ROW_LABEL_FONT_SIZE = "7px";
export const DEFAULT_COLUMN_LABEL_FONT_SIZE = "7px";
export const DEFAULT_VISIBLE_RANGE = [-1, 1];

export const LABELS_MARGIN_BUFFER_IN_PX = 20;
export const INTENSITY_LEGEND_LABEL_SIZE_IN_PX = 25;
Expand Down

0 comments on commit 123fd6c

Please sign in to comment.