-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1570 from ag-grid/AG-11385/initial_proxyInteracti…
…onService AG-11385 Initial ProxyInteractionService
- Loading branch information
Showing
20 changed files
with
139 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/ag-charts-community/src/chart/dom/proxyInteractionService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import type { BBoxProvider, BBoxValues } from '../../util/bboxinterface'; | ||
import { Debug } from '../../util/debug'; | ||
import { createElement, setElementBBox } from '../../util/dom'; | ||
import type { UpdateService } from '../updateService'; | ||
import type { FocusIndicator } from './focusIndicator'; | ||
|
||
type ProxyType = 'button'; | ||
|
||
type ProxyParams<T extends ProxyType> = { | ||
type: T; | ||
id: string; | ||
textContext: string; | ||
parent: HTMLElement; | ||
bboxprovider: BBoxProvider<BBoxValues>; | ||
onclick?: (ev: MouseEvent) => void; | ||
}; | ||
|
||
type ProxyReturnMap = { | ||
button: HTMLButtonElement; | ||
}; | ||
|
||
type ProxyNode = { | ||
element: HTMLElement; | ||
bboxprovider: BBoxProvider<BBoxValues>; | ||
}; | ||
|
||
export class ProxyInteractionService { | ||
// This debug option make the proxies button partially transparent instead of fully transparent. | ||
// To enabled this option, set window.agChartsDebug = ['showDOMProxies']. | ||
private readonly debugShowDOMProxies: boolean = Debug.check('showDOMProxies'); | ||
|
||
private readonly nodes: ProxyNode[] = []; | ||
private readonly destroyFns: (() => void)[]; | ||
|
||
constructor( | ||
updateService: UpdateService, | ||
private readonly focusIndicator: FocusIndicator | ||
) { | ||
this.destroyFns = [updateService.addListener('update-complete', () => this.update())]; | ||
} | ||
|
||
public destroy() { | ||
this.destroyFns.forEach((d) => d()); | ||
} | ||
|
||
private update() { | ||
for (const { element, bboxprovider } of this.nodes) { | ||
setElementBBox(element, bboxprovider.getCachedBBox()); | ||
} | ||
} | ||
|
||
createProxyElement<T extends ProxyType>(params: ProxyParams<T>): ProxyReturnMap[T] | undefined { | ||
const { type, id, parent, bboxprovider, textContext, onclick } = params; | ||
if (type === 'button') { | ||
const newButton = createElement('button'); | ||
|
||
newButton.id = id; | ||
newButton.textContent = textContext; | ||
newButton.style.pointerEvents = 'none'; | ||
newButton.style.opacity = this.debugShowDOMProxies ? '0.25' : '0'; | ||
newButton.addEventListener('focus', (_event: FocusEvent): any => { | ||
newButton.style.setProperty('pointerEvents', null); | ||
this.focusIndicator.updateBBox(bboxprovider.getCachedBBox()); | ||
}); | ||
newButton.addEventListener('blur', (_event: FocusEvent): any => { | ||
newButton.style.pointerEvents = 'none'; | ||
this.focusIndicator.updateBBox(undefined); | ||
}); | ||
if (onclick) { | ||
newButton.addEventListener('click', onclick); | ||
} | ||
|
||
this.nodes.push({ element: newButton, bboxprovider }); | ||
parent.appendChild(newButton); | ||
return newButton; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/ag-charts-community/src/chart/series/cartesian/quadtreeUtil.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export interface BBoxValues { | ||
x: number; | ||
y: number; | ||
width: number; | ||
height: number; | ||
} | ||
|
||
export interface BBoxContainsTester { | ||
containsPoint(x: number, y: number): boolean; | ||
} | ||
|
||
export interface BBoxProvider<T = BBoxValues> { | ||
getCachedBBox(): T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.