Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove redundant data-id on HTML #1479

Merged
merged 2 commits into from
Aug 14, 2023
Merged
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
5 changes: 5 additions & 0 deletions .changeset/short-plants-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/g-plugin-html-renderer': patch
---

Remove redundant data-id on HTML.
4 changes: 0 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ name: 🚀 Test

on: [pull_request]

concurrency:
group: ${{github.workflow}}-${{github.event_name}}-${{github.ref}}
cancel-in-progress: true

jobs:
test:
name: Test
Expand Down
3 changes: 0 additions & 3 deletions __tests__/unit/display-objects/html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,5 @@ describe('HTML', () => {
const $el2 = html2.getDomElement();
expect($el1.id).toBe('id');
expect($el2.id).toBe('id');
// unique id
expect($el1.dataset.id).toBe('g-html-' + html1.entity);
expect($el2.dataset.id).toBe('g-html-' + html2.entity);
});
});
20 changes: 12 additions & 8 deletions packages/g-plugin-html-renderer/src/HTMLRenderingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import { isNil, isNumber, isString } from '@antv/util';
import type { mat4 } from 'gl-matrix';

const HTML_PREFIX = 'g-html-';
const CANVAS_CAMERA_ID = 'g-canvas-camera';

export class HTMLRenderingPlugin implements RenderingPlugin {
Expand All @@ -32,6 +31,11 @@ export class HTMLRenderingPlugin implements RenderingPlugin {
*/
private $camera: HTMLDivElement;

private displayObjectHTMLElementMap = new WeakMap<
DisplayObject,
HTMLElement
>();

private joinTransformMatrix(matrix: mat4) {
return `matrix(${[
matrix[0],
Expand Down Expand Up @@ -199,16 +203,16 @@ export class HTMLRenderingPlugin implements RenderingPlugin {

private getOrCreateEl(object: DisplayObject) {
const { document: doc } = this.context.config;
const uniqueHTMLId = `${HTML_PREFIX}${object.entity}`;
let $existedElement: HTMLElement | null = this.$camera.querySelector(
`[data-id=${uniqueHTMLId}]`,
);
let $existedElement: HTMLElement | null =
this.displayObjectHTMLElementMap.get(object);

if (!$existedElement) {
$existedElement = (doc || document).createElement('div');
object.parsedStyle.$el = $existedElement;
$existedElement.id = object.id || uniqueHTMLId;
$existedElement.dataset.id = uniqueHTMLId;

this.displayObjectHTMLElementMap.set(object, $existedElement);
if (object.id) {
$existedElement.id = object.id;
}
if (object.name) {
$existedElement.setAttribute('name', object.name);
}
Expand Down