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

feat: get element svg #942

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 36 additions & 0 deletions lib/core/ElementRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,42 @@
return container && (secondary ? container.secondaryGfx : container.gfx);
};

/**
* Return the graphical SVG representation of an element.
*
* @example
*
* ```javascript
* elementRegistry.getGraphicsSvg('SomeElementId_1'); // <svg ...>
*
* elementRegistry.getGraphicsSvg(rootElement); // <svg ...>
* ```
*
* @param {ElementLike|string} filter The element or its ID.
*
* @return {SVGElement} The graphical SVG representation.
*/
ElementRegistry.prototype.getGraphicsSvg = function(filter) {
/**

Check failure on line 279 in lib/core/ElementRegistry.js

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Expected line before comment

Check failure on line 279 in lib/core/ElementRegistry.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04)

Expected line before comment
* @type {SVGElement}
*/
var gfx = this.getGraphics(filter).cloneNode(true);

gfx.removeAttribute('transform');

/**
* @type {SVGRectElement}
*/
var rect = gfx.querySelector('rect').cloneNode(true);

Check failure on line 290 in lib/core/ElementRegistry.js

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Trailing spaces not allowed

Check failure on line 290 in lib/core/ElementRegistry.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04)

Trailing spaces not allowed
var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");

Check failure on line 291 in lib/core/ElementRegistry.js

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Strings must use singlequote

Check failure on line 291 in lib/core/ElementRegistry.js

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Strings must use singlequote

Check failure on line 291 in lib/core/ElementRegistry.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04)

Strings must use singlequote

Check failure on line 291 in lib/core/ElementRegistry.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04)

Strings must use singlequote
svg.setAttribute('width', rect.getAttribute('width'));
svg.setAttribute('height', rect.getAttribute('height'));
svg.appendChild(gfx);

return svg;
};

/**
* Validate an ID and throw an error if invalid.
*
Expand Down
4 changes: 4 additions & 0 deletions lib/core/ElementRegistry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ elementRegistry.getGraphics(shapeLike);

elementRegistry.getGraphics(shape);

elementRegistry.getGraphicsSvg(shapeLike);

elementRegistry.getGraphicsSvg(shape);

elementRegistry.updateGraphics('shape', shapeGfx1);

elementRegistry.updateGraphics(shapeLike, shapeGfx1);
Expand Down
Loading