bartbutenaers / node-red-contrib-ui-svg

A Node-RED widget node to show interactive SVG (vector graphics) in the dashboard
Apache License 2.0
94 stars 27 forks source link

Handle empty or non-valid SVG #15

Closed bartbutenaers closed 4 years ago

bartbutenaers commented 5 years ago

When no valid svg element can be found, we will have a null-reference:

$scope.svg = $scope.rootDiv.querySelector("svg");

Handle this properly

Steve-Mcl commented 5 years ago

My thoughts...

  1. Default it to <svg /> Or
  2. Ignore it / do nothing. Or
  3. Create a Node configuration error if SVG is empty or doesn't have svg root element?
bartbutenaers commented 5 years ago

@Steve-Mcl , Or perhaps display an svg containing a text-element “no drawing has been specified” …

Steve-Mcl commented 5 years ago

Or perhaps display an svg containing a text-element “no drawing has been specified” ...

Yeah, thats seems reasonable

image

<svg width="200" height="50" xmlns="http://www.w3.org/2000/svg"> 
 <g>
  <rect stroke="#000000" id="svg_2" height="50" width="200" y="2.73322" x="2.00563" stroke-width="5" fill="#ff0000"/>
  <text font-weight="bold" stroke="#000000" xml:space="preserve" text-anchor="middle" font-family="Sans-serif" font-size="24" id="svg_1" y="35.85669" x="100" stroke-width="0" fill="#000000">SVG is empty</text>
 </g>
</svg>
bartbutenaers commented 4 years ago

Implemented