Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5127905
Update d3 to v7 from v5 and update related dependencies and devDepend…
shixiao-coder Dec 11, 2025
09b9f23
Merge branch 'master' into d3-v7-upgrade
shixiao-coder Dec 11, 2025
c36bf7e
Update branch and lint fix
shixiao-coder Dec 11, 2025
65fbb4a
Merge branch 'master' into d3-v7-upgrade
shixiao-coder Dec 12, 2025
3376ee3
Update event from any to static interface
shixiao-coder Dec 12, 2025
743f03e
Update the logic to replicate behavior before this PR
shixiao-coder Dec 12, 2025
24d3eb3
Update type for event from any
shixiao-coder Dec 12, 2025
4340adc
Update d3 model mapper path
shixiao-coder Dec 12, 2025
651177b
Modify the buffer toString for NPM CI Build
shixiao-coder Dec 12, 2025
122b819
update buffer
shixiao-coder Dec 12, 2025
ab6331a
Merge branch 'master' into d3-v7-upgrade
shixiao-coder Dec 12, 2025
e977e84
Merge branch 'master' into d3-v7-upgrade
shixiao-coder Dec 12, 2025
60d4895
CI test fixes
shixiao-coder Dec 12, 2025
6bca374
Fix NPM test failures
shixiao-coder Dec 12, 2025
422526f
Merge branch 'master' into d3-v7-upgrade
shixiao-coder Dec 15, 2025
884533e
Fix event related arg issues
shixiao-coder Dec 15, 2025
5b1549d
Lint fix
shixiao-coder Dec 15, 2025
90f2976
Update d3 to v7 from v5 and update related dependencies and devDepend…
shixiao-coder Dec 11, 2025
8fd2b42
Update branch and lint fix
shixiao-coder Dec 11, 2025
84e2511
Update event from any to static interface
shixiao-coder Dec 12, 2025
2111270
Update the logic to replicate behavior before this PR
shixiao-coder Dec 12, 2025
0aab151
Update type for event from any
shixiao-coder Dec 12, 2025
d6e6a09
Update d3 model mapper path
shixiao-coder Dec 12, 2025
cf9916c
Modify the buffer toString for NPM CI Build
shixiao-coder Dec 12, 2025
bb243b2
update buffer
shixiao-coder Dec 12, 2025
79774f0
CI test fixes
shixiao-coder Dec 12, 2025
15cbf3d
Fix NPM test failures
shixiao-coder Dec 12, 2025
58f9435
Fix event related arg issues
shixiao-coder Dec 15, 2025
21f81c7
Lint fix
shixiao-coder Dec 15, 2025
a79c75a
Merge branch 'd3-v7-upgrade' of github.com:shixiao-coder/website into…
shixiao-coder Dec 15, 2025
c37578a
Refresh the package lock after merge conflict resolved
shixiao-coder Dec 15, 2025
80506c1
Modify the module back to esnext
shixiao-coder Dec 15, 2025
81e1a01
Merge branch 'master' into d3-v7-upgrade
shixiao-coder Dec 16, 2025
88ca602
Merge branch 'master' into d3-v7-upgrade
shixiao-coder Dec 18, 2025
ff01df1
Merge branch 'master' into d3-v7-upgrade
shixiao-coder Dec 18, 2025
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
3 changes: 3 additions & 0 deletions static/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ module.exports = {
},
},
},
moduleNameMapper: {
'^d3$': '<rootDir>/node_modules/d3/dist/d3.min.js',
},
testEnvironment: "jest-environment-jsdom",
};
2 changes: 1 addition & 1 deletion static/js/apps/visualization/redirect_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("redirect_utils", () => {

afterAll(() => {
// Reset the original window.location for future tests
window.location = originalLocation;
window.location.href = originalLocation.href;
});

// Mocks window.location with a new URL for the given relative path
Expand Down
12 changes: 8 additions & 4 deletions static/js/biomedical/bio_charts_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/
import * as d3 from "d3";

import { DiseaseGeneAssociationData } from "./disease/types";
import {
DiseaseGeneAssociationData,
DiseaseSymptomAssociationData,
} from "./disease/types";
import { ProteinNumData } from "./protein/chart";
import { DiseaseAssociationType } from "./protein/page";
import { InteractionLink, ProteinNode } from "./protein/types";
Expand All @@ -35,6 +38,7 @@ export const DEFAULT_BRIGHTEN_PERCENTAGE = "112%";
export const X_LABEL_SHIFT = 40;
export type Datum =
| DiseaseGeneAssociationData
| DiseaseSymptomAssociationData
| ProteinNumData
| ProteinNode
| InteractionLink
Expand All @@ -60,10 +64,10 @@ export function onMouseOver(
/**
* Update position of global tooltip to track mouse.
*/
export function onMouseMove(): void {
TOOL_TIP.style("left", d3.event.pageX - TOOL_TIP_SHIFT + "px").style(
export function onMouseMove(event: MouseEvent): void {
TOOL_TIP.style("left", event.pageX - TOOL_TIP_SHIFT + "px").style(
"top",
d3.event.pageY - TOOL_TIP_SHIFT + "px"
event.pageY - TOOL_TIP_SHIFT + "px"
);
}

Expand Down
6 changes: 4 additions & 2 deletions static/js/biomedical/disease/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ export function drawDiseaseGeneAssocChart(
.call(
handleMouseEvents,
circleIDFunc,
(d) => `Gene Name: ${d.name}<br>Confidence Score: ${d.score}`
(d: DiseaseGeneAssociationData) =>
`Gene Name: ${d.name}<br>Confidence Score: ${d.score}`
);
}

Expand Down Expand Up @@ -255,7 +256,8 @@ export function drawDiseaseSymptomAssociationChart(
.call(
handleMouseEvents,
circleIDFunc,
(d) => `Symptom: ${d.name}<br>Odds Ratio Association: ${d.oddsRatio}`
(d: DiseaseSymptomAssociationData) =>
`Symptom: ${d.name}<br>Odds Ratio Association: ${d.oddsRatio}`
);
}
/**
Expand Down
42 changes: 26 additions & 16 deletions static/js/biomedical/protein/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,28 @@ function dragNode(
): DragBehavior<Element, SimulationNodeDatum, SimulationNodeDatum> {
// Reference for alphaTarget: https://stamen.com/forcing-functions-inside-d3-v4-forces-and-layout-transitions-f3e89ee02d12/

function dragstarted(nodeDatum: ProteinNode): void {
if (!d3.event.active) {
function dragstarted(
event: { active: number },
nodeDatum: ProteinNode
): void {
if (!event.active) {
// start up simulation
simulation.alphaTarget(0.3).restart();
}
nodeDatum.fx = nodeDatum.x;
nodeDatum.fy = nodeDatum.y;
}

function dragged(nodeDatum: ProteinNode): void {
nodeDatum.fx = d3.event.x;
nodeDatum.fy = d3.event.y;
function dragged(
event: { x: number; y: number },
nodeDatum: ProteinNode
): void {
nodeDatum.fx = event.x;
nodeDatum.fy = event.y;
}

function dragended(nodeDatum: ProteinNode): void {
if (!d3.event.active) {
function dragended(event: { active: number }, nodeDatum: ProteinNode): void {
if (!event.active) {
// cool down simulation
simulation.alphaTarget(0);
}
Expand Down Expand Up @@ -352,7 +358,7 @@ export function drawTissueLegend(id: string, data: ProteinStrData[]): void {
.append("svg")
.attr("width", GRAPH_WIDTH_XL)
.attr("height", GRAPH_HEIGHT_XS);
const organTypes = d3.keys(ORGAN_COLOR_DICT);
const organTypes = Object.keys(ORGAN_COLOR_DICT);
// slicing the dictionary in half to display the legend in two rows
const dictSliceNumber = (organTypes.length + 1) / 2;
const dataRowOne = organTypes.slice(0, dictSliceNumber);
Expand Down Expand Up @@ -505,7 +511,8 @@ export function drawTissueScoreChart(id: string, data: ProteinStrData[]): void {
.call(
handleMouseEvents,
barIdFunc,
(d) => `Name: ${d.name}<br>Expression: ${TISSUE_SCORE_TO_LABEL[d.value]}`,
(d: ProteinNumData) =>
`Name: ${d.name}<br>Expression: ${TISSUE_SCORE_TO_LABEL[d.value]}`,
PTI_BRIGHTEN_PERCENTAGE
);
}
Expand Down Expand Up @@ -657,7 +664,8 @@ export function drawProteinInteractionChart(
.call(
handleMouseEvents,
barIdFunc,
(d) => `Protein Name: ${d.name}<br>Confidence Score: ${d.value}`
(d: InteractingProteinType) =>
`Protein Name: ${d.name}<br>Confidence Score: ${d.value}`
);
}

Expand Down Expand Up @@ -719,7 +727,7 @@ export function drawProteinInteractionGraph(
.call(
handleMouseEvents,
linkIdFunc,
(d) =>
(d: InteractionLink) =>
`Source: ${(d.source as ProteinNode).name}<br>Target: ${
(d.target as ProteinNode).name
}<br>Confidence: ${d.score}`,
Expand Down Expand Up @@ -856,7 +864,7 @@ export function drawDiseaseGeneAssocChart(
.call(
handleMouseEvents,
barIdFunc,
(d) =>
(d: DiseaseAssociationType) =>
`Disease Name: ${formatDiseaseName(d.name)}<br>Association Score: ${
d.value
}`
Expand Down Expand Up @@ -976,7 +984,8 @@ export function drawVarGeneAssocChart(
.call(
handleMouseEvents,
circleIdFunc,
(d) => `Variant ID: ${d.id}<br>Log2 Fold Change: ${d.value}`
(d: VarGeneDataPoint) =>
`Variant ID: ${d.id}<br>Log2 Fold Change: ${d.value}`
);

svg
Expand Down Expand Up @@ -1142,7 +1151,7 @@ export function drawVarTypeAssocChart(
.call(
handleMouseEvents,
barIdFunc,
(d) =>
(d: ProteinNumData) =>
`Variant Functional Category: ${formatVariant(d.name)}<br>Count: ${
d.value
}`
Expand Down Expand Up @@ -1222,7 +1231,7 @@ export function drawVarSigAssocChart(id: string, data: ProteinNumData[]): void {
.call(
handleMouseEvents,
barIdFunc,
(d) =>
(d: ProteinNumData) =>
`Variant Clinical Significance: ${formatVariant(d.name)}<br>Count: ${
d.value
}`
Expand Down Expand Up @@ -1299,6 +1308,7 @@ export function drawChemGeneAssocChart(
.call(
handleMouseEvents,
barIdFunc,
(d) => `Association Type: ${formatChemName(d.name)}<br>Count: ${d.value}`
(d: ProteinNumData) =>
`Association Type: ${formatChemName(d.name)}<br>Count: ${d.value}`
);
}
2 changes: 1 addition & 1 deletion static/js/browser/observation_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class ObservationChart extends React.Component<
);
}

private handleDotClick = (dotData: DataPoint): void => {
private handleDotClick = (_: MouseEvent, dotData: DataPoint): void => {
const date = dotData.label;
this.redirectToObsPage(date);
};
Expand Down
4 changes: 2 additions & 2 deletions static/js/chart/draw_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ function addHighlightOnHover(
tooltip.style("display", "none");
}, HIGHLIGHT_TIMEOUT);
};
const mousemoveFn = function (): void {
const [mouseX, mouseY] = d3.mouse(container.node() as HTMLElement);
const mousemoveFn = function (event: MouseEvent): void {
const [mouseX, mouseY] = d3.pointer(event, container.node() as HTMLElement);
positionTooltip(tooltip, mouseX, mouseY, chartAreaBoundary);
};

Expand Down
37 changes: 19 additions & 18 deletions static/js/chart/draw_d3_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function fitSize(
*/

function showTooltip(
event: MouseEvent,
containerElement: HTMLDivElement,
place: NamedPlace,
getTooltipHtml: (place: NamedPlace) => string
Expand All @@ -142,7 +143,7 @@ function showTooltip(
const leftOffset = 2 * offset;
const topOffset = -tooltipHeight - offset;
let left = Math.min(
d3.event.offsetX + leftOffset,
event.offsetX + leftOffset,
containerWidth - tooltipWidth - offset // account for decoration around the tooltip
);
if (left < 0) {
Expand All @@ -151,9 +152,9 @@ function showTooltip(
} else {
tooltipSelect.style("width", "fit-content");
}
let top = d3.event.offsetY + topOffset;
let top = event.offsetY + topOffset;
if (top < 0) {
top = d3.event.offsetY + offset;
top = event.offsetY + offset;
}
tooltipSelect
.html(tooltipHtml)
Expand All @@ -166,7 +167,7 @@ const onMouseOver =
canClickRegion: (placeDcid: string) => boolean,
containerElement: HTMLDivElement
) =>
(geo: GeoJsonFeature): void => {
(_: MouseEvent, geo: GeoJsonFeature): void => {
mouseHoverAction(
containerElement,
geo.properties.geoDcid,
Expand All @@ -178,7 +179,7 @@ const onMouseOver =

const onMouseOut =
(containerElement: HTMLDivElement) =>
(geo: GeoJsonFeature): void => {
(_: MouseEvent, geo: GeoJsonFeature): void => {
mouseOutAction(containerElement, geo.properties.geoDcid, [
HOVER_HIGHLIGHTED_CLASS_NAME,
HOVER_HIGHLIGHTED_NO_CLICK_CLASS_NAME,
Expand All @@ -194,7 +195,7 @@ const onMouseMove =
containerElement: HTMLDivElement,
getTooltipHtml: (place: NamedPlace) => string
) =>
(geo: GeoJsonFeature): void => {
(event: MouseEvent, geo: GeoJsonFeature): void => {
const placeDcid = geo.properties.geoDcid;
mouseHoverAction(
containerElement,
Expand All @@ -207,7 +208,7 @@ const onMouseMove =
dcid: placeDcid,
name: geo.properties.name,
};
showTooltip(containerElement, place, getTooltipHtml);
showTooltip(event, containerElement, place, getTooltipHtml);
};

const onMapClick =
Expand All @@ -216,7 +217,7 @@ const onMapClick =
containerElement: HTMLDivElement,
redirectAction: (properties: GeoJsonFeatureProperties) => void
) =>
(geo: GeoJsonFeature): void => {
(_: MouseEvent, geo: GeoJsonFeature): void => {
if (!canClickRegion(geo.properties.geoDcid)) return;
redirectAction(geo.properties);
mouseOutAction(containerElement, geo.properties.geoDcid, [
Expand Down Expand Up @@ -559,7 +560,7 @@ export function drawD3Map(
[0, 0],
[chartWidth, chartHeight],
])
.on("zoom", function (): void {
.on("zoom", function (event: d3.D3ZoomEvent<SVGElement, unknown>): void {
mapObjects.forEach((mapObjectLayer) => {
mapObjectLayer.on("mousemove", null).on("mouseover", null);
});
Expand All @@ -568,7 +569,7 @@ export function drawD3Map(
.selectAll("path,circle")
.classed(HOVER_HIGHLIGHTED_CLASS_NAME, false)
.classed(HOVER_HIGHLIGHTED_NO_CLICK_CLASS_NAME, false)
.attr("transform", d3.event.transform);
.attr("transform", event.transform.toString());
})
.on("end", function (): void {
mapObjects.forEach((mapObjectLayer) => {
Expand Down Expand Up @@ -704,12 +705,12 @@ export function addMapPoints(
});
if (getTooltipHtml) {
mapPointsLayer
.on("mouseover", (point: MapPoint) => {
.on("mouseover", (event: MouseEvent, point: MapPoint) => {
const place = {
dcid: point.placeDcid,
name: point.placeName,
};
showTooltip(containerElement, place, getTooltipHtml);
showTooltip(event, containerElement, place, getTooltipHtml);
})
.on("mouseout", () => {
d3.select(containerElement)
Expand All @@ -736,7 +737,7 @@ export function addPolygonLayer(
projection: d3.GeoProjection,
getRegionColor: (geoDcid: string) => string,
getRegionBorder: (geoDcid: string) => string,
onClick: (geoFeature: GeoJsonFeature) => void,
onClick: (event: MouseEvent, geoFeature: GeoJsonFeature) => void,
allowMouseover = true
): void {
// Build the map objects
Expand All @@ -759,14 +760,14 @@ export function addPolygonLayer(
.on("click", onClick);
if (allowMouseover) {
mapObjects
.on("mouseover", (d: GeoJsonFeature) => {
.on("mouseover", (_: MouseEvent, d: GeoJsonFeature) => {
mouseHoverAction(
containerElement,
d.properties.geoDcid,
MAP_POLYGON_HIGHLIGHT_CLASS
);
})
.on("mouseout", (d: GeoJsonFeature) => {
.on("mouseout", (_: MouseEvent, d: GeoJsonFeature) => {
mouseOutAction(containerElement, d.properties.geoDcid, [
MAP_POLYGON_HIGHLIGHT_CLASS,
]);
Expand All @@ -787,7 +788,7 @@ export function addPathLayer(
geoJson: GeoJsonData,
projection: d3.GeoProjection,
getRegionColor: (geoDcid: string) => string,
onClick: (feature: GeoJsonFeature) => void
onClick: (event: MouseEvent, feature: GeoJsonFeature) => void
): void {
// Build map objects.
const mapObjects = addGeoJsonLayer(
Expand All @@ -805,14 +806,14 @@ export function addPathLayer(
return getRegionColor(d.properties.geoDcid);
})
.attr("opacity", MAP_PATH_OPACITY)
.on("mouseover", (d: GeoJsonFeature) => {
.on("mouseover", (_: MouseEvent, d: GeoJsonFeature) => {
mouseHoverAction(
containerElement,
d.properties.geoDcid,
MAP_PATH_HIGHLIGHT_CLASS
);
})
.on("mouseout", (d: GeoJsonFeature) => {
.on("mouseout", (_: MouseEvent, d: GeoJsonFeature) => {
mouseOutAction(containerElement, d.properties.geoDcid, [
MAP_PATH_HIGHLIGHT_CLASS,
]);
Expand Down
Loading
Loading