Skip to content

Commit

Permalink
Merge pull request #1522 from concord-consortium/185628921-graph-subp…
Browse files Browse the repository at this point in the history
…lot-mask-fix-tests
  • Loading branch information
pjanik authored Sep 27, 2024
2 parents edb6895 + 8b55ab4 commit b6672c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
4 changes: 2 additions & 2 deletions v3/src/components/data-display/hooks/use-connecting-lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const useConnectingLines = (props: IProps) => {

const handleConnectingLinesMouseOver = useCallback((mouseOverProps: IMouseOverProps) => {
const { caseIDs, event, parentAttrName, primaryAttrValue } = mouseOverProps
if (pixiPoints) pixiPoints.canvas.style.cursor = "pointer"
if (pixiPoints?.canvas) pixiPoints.canvas.style.cursor = "pointer"
// TODO: In V2, the tool tip is only shown when there is a parent attribute. V3 should always show the tool tip,
// but the text needs to be different when there is no parent attribute. We'll need to work out how to handle the
// localization for this. When a parent attribute is present, the tool tip should look like:
Expand All @@ -90,7 +90,7 @@ export const useConnectingLines = (props: IProps) => {
}, [dataTip, dataset?.name, pixiPoints])

const handleConnectingLinesMouseOut = useCallback(() => {
if (pixiPoints) pixiPoints.canvas.style.cursor = ""
if (pixiPoints?.canvas) pixiPoints.canvas.style.cursor = ""
dataTip.hide()
}, [dataTip, pixiPoints])

Expand Down
49 changes: 32 additions & 17 deletions v3/src/components/data-display/pixi/pixi-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,26 @@ export class PixiPoints {
// The function will prioritize the WebGL renderer as it is the most tested safe API to use. In the near future as
// WebGPU becomes more stable and ubiquitous, it will be prioritized over WebGL.
// See: https://pixijs.download/release/docs/rendering.html#autoDetectRenderer
this.renderer = await PIXI.autoDetectRenderer({
resolution: window.devicePixelRatio,
autoDensity: true,
backgroundAlpha: 0,
antialias: true,
// `passive` is more performant and will be used by default in the future Pixi.JS versions
eventMode: "passive",
eventFeatures: {
move: true,
click: true,
// disables the global move events which can be very expensive in large scenes
globalMove: false,
wheel: false
}
})
try {
this.renderer = await PIXI.autoDetectRenderer({
resolution: window.devicePixelRatio,
autoDensity: true,
backgroundAlpha: 0,
antialias: true,
// `passive` is more performant and will be used by default in the future Pixi.JS versions
eventMode: "passive",
eventFeatures: {
move: true,
click: true,
// disables the global move events which can be very expensive in large scenes
globalMove: false,
wheel: false
}
})
} catch (e) {
console.error("PixiPoints failed to initialize renderer")
return
}

this.ticker.add(this.tick.bind(this))
this.stage.addChild(this.background)
Expand All @@ -147,8 +152,8 @@ export class PixiPoints {
}
}

get canvas() {
return this.renderer?.view.canvas as HTMLCanvasElement
get canvas(): HTMLCanvasElement | null {
return this.renderer?.view.canvas as HTMLCanvasElement ?? null
}

get points() {
Expand Down Expand Up @@ -663,6 +668,9 @@ export class PixiPoints {
}

matchPointsToData(datasetID:string, caseData: CaseDataWithSubPlot[], _displayType: string, style: IPixiPointStyle) {
if (!this.renderer) {
return
}
// If the display type has changed, we need to prepare for the transition between types
// For now, the only display type values PixiPoints supports are "points" and "bars", so
// all other display type values passed to this method will be treated as "points".
Expand Down Expand Up @@ -737,6 +745,13 @@ export class PixiPoints {
}

setPointsMask(allCaseData: CaseDataWithSubPlot[]) {
if (!this.renderer || (window as any).Cypress) {
// This method causes Cypress tests to fail in the GitHub Actions environment, so we skip it in that case.
// The exact reason is unclear, but it seems likely that the WebGL (or WebGPU) renderer initialized in GitHub
// Actions is somehow faulty or incomplete, and using masking features causes it to break entirely. This isn't
// a feature that can be tested using Cypress anyway, so it's safe to skip it in this case.
return
}
allCaseData.forEach((caseData, i) => {
const point = this.getPointForCaseData(caseData)
if (point) {
Expand Down
2 changes: 1 addition & 1 deletion v3/src/components/graph/components/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const Graph = observer(function Graph({graphController, graphRef, pixiPoi
xAttrID = graphModel.getAttributeID('x'),
yAttrID = graphModel.getAttributeID('y')

if (pixiPoints && pixiContainerRef.current && pixiContainerRef.current.children.length === 0) {
if (pixiPoints?.canvas && pixiContainerRef.current && pixiContainerRef.current.children.length === 0) {
pixiContainerRef.current.appendChild(pixiPoints.canvas)
pixiPoints.setupBackgroundEventDistribution({
elementToHide: pixiContainerRef.current
Expand Down
2 changes: 1 addition & 1 deletion v3/src/components/map/components/map-point-layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const MapPointLayer = observer(function MapPointLayer({mapLayerModel, set
}, [dataConfiguration.dataset, mapModel, pixiPoints])

useEffect(() => {
if (pixiPoints != null && pixiContainerRef.current && pixiContainerRef.current.children.length === 0) {
if (pixiPoints?.canvas && pixiContainerRef.current && pixiContainerRef.current.children.length === 0) {
pixiContainerRef.current.appendChild(pixiPoints.canvas)
pixiPoints.resize(layout.contentWidth, layout.contentHeight)
}
Expand Down

0 comments on commit b6672c4

Please sign in to comment.