Skip to content

Commit

Permalink
Merge pull request #382 from ExperienceLovelace/bugfix/handle_getbbox…
Browse files Browse the repository at this point in the history
…_errors

Hdl no getBBox if not set (So also ignore x,y,w&h)
  • Loading branch information
exetico authored Dec 3, 2023
2 parents b993b5e + db3a3a3 commit 7831e34
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

name: Last commit

on: [push]
on:
push:
branches:
- master

jobs:
build:
Expand Down
3 changes: 1 addition & 2 deletions dist/floorplan-examples.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/floorplan.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/_docs/floorplan/floorplan-examples.js

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/components/floorplan/floorplan-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,14 @@ export class FloorplanElement extends LitElement {

svg.id = svgElementInfo.svgElement.id;
svg.setAttribute('preserveAspectRatio', 'xMinYMin meet');
svg.setAttribute('height', svgElementInfo.originalBBox.height.toString());
svg.setAttribute('width', svgElementInfo.originalBBox.width.toString());
svg.setAttribute('x', svgElementInfo.originalBBox.x.toString());
svg.setAttribute('y', svgElementInfo.originalBBox.y.toString());

// A clipPath does not have the clipPath function on the element, therefore originalBBox can be null in some cases
if(svgElementInfo.originalBBox !== null){
svg.setAttribute('height', svgElementInfo.originalBBox.height.toString());
svg.setAttribute('width', svgElementInfo.originalBBox.width.toString());
svg.setAttribute('x', svgElementInfo.originalBBox.x.toString());
svg.setAttribute('y', svgElementInfo.originalBBox.y.toString());
}

if (svgElementInfo.svgElement.nodeName !== 'g') {
const originalTransform =
Expand Down Expand Up @@ -1334,7 +1338,8 @@ export class FloorplanElement extends LitElement {
svgElement.id,
svgElement,
svgElement,
svgElement.getBBox()
// A clipPath does not have the clipPath function
svgElement.getBBox ? svgElement.getBBox() : null
);
ruleInfo.svgElementInfos[svgElement.id] = svgElementInfo;

Expand Down
2 changes: 1 addition & 1 deletion src/components/floorplan/lib/floorplan-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class FloorplanSvgElementInfo {
public entityId: string,
public svgElement: SVGGraphicsElement,
public originalSvgElement: SVGGraphicsElement,
public originalBBox: DOMRect
public originalBBox: DOMRect | null,
) { }
}

Expand Down

0 comments on commit 7831e34

Please sign in to comment.