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

[FEATURE] 'floorplan.text_set' should support element which has text as child #358

Closed
Skarbo opened this issue Aug 24, 2023 · 4 comments
Closed
Labels
feature request Feature requests goes here waiting on review Issues which are not categorized, yet.

Comments

@Skarbo
Copy link

Skarbo commented Aug 24, 2023

Description
Prior to version 1.0.36 setText would look for any existing tspan children and change the child text.

From version 1.0.36 with new line feature setText will presume that entity is a text node and append tspan with the text to that node.

This does not work if you use floorplan.text_set on a entity that is a g node, for example.

Current experience
Original SVG

<svg>
<g id="temperature.kitchen">
<text><tspan x="5" y="5">99.9°</tspan></text>
</g>
</svg>

YAML

- name: Temperatures
   entities:
     - element: temperature.kitchen
       entity: sensor.kitchen
   state_action:
     - service: floorplan.text_set
       service_data: '10.0°'

Produced SVG

<svg>
<g id="temperature.kitchen">
<tspan>10.0°</tspan>
</g>
</svg>

Expected SVG

<svg>
<g id="temperature.kitchen">
<text><tspan x="5" y="5">10.0°</tspan></text>
</g>
</svg>

Suggestion
Update setText to look for child text node if element is not SVGTextElement.

static setText(
  textElement: HTMLElement | SVGElement,
  text: string,
  shiftAxisY: string
): void {
  if (!(textElement instanceof SVGTextElement)) {
    textElement = textElement.querySelector('text') || textElement;
  }
@bernji
Copy link

bernji commented Sep 15, 2023

I sencond that as I have the same problem: attribes of child (e.g. tsdpan) of text nodes are erased

@exetico
Copy link
Member

exetico commented Sep 15, 2023

That's a fair input. I'll fix it whenever possible. I thought @pkozul looked into it.

PR's also much appreciated, if they're tested. Else,I'll try and prioritize it as soon as possible.

@exetico
Copy link
Member

exetico commented Sep 21, 2023

Before fix:

<svg height="100%" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink" style="height: 100%; width: 100%; margin: auto; cursor: default; opacity: 1; display: block;">
<g id="temperature.kitchen"><tspan>21.42</tspan></g>
</svg>

After fix:

<svg height="100%" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink" style="height: 100%; width: 100%; margin: auto; cursor: default; opacity: 1; display: block;">
<g id="temperature.kitchen" class="floorplan-hover" style="cursor: pointer;">
<text><tspan x="5" y="5">21.42</tspan></text>
<title>...(removed)...</title></g>
</svg>

Branch: https://github.com/ExperienceLovelace/ha-floorplan/tree/bug/text_set_use_existing_tspan

I have also added the logics to save the x and y, if it's a single tspan. I don't know why I didn't think of that while implementing the other feature.

exetico added a commit that referenced this issue Sep 21, 2023
…ting_tspan

Bug/text set use existing tspan - fixes #358
@exetico
Copy link
Member

exetico commented Sep 21, 2023

Kindly check with: https://github.com/ExperienceLovelace/ha-floorplan/blob/dev/dist/floorplan.js

It's currently in the dev-branch.

exetico added a commit that referenced this issue Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature requests goes here waiting on review Issues which are not categorized, yet.
Projects
None yet
Development

No branches or pull requests

3 participants