Skip to content

Commit

Permalink
Add svgRect rx and ry options
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Nov 8, 2024
1 parent 4417b4d commit 7809e58
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Encodes an array of XY ordinates as an SVG `polygon`.
* `y` - Y location of bottom-left corner
* `width` - rectangle width
* `height` - rectangle height
* `rx` - *[optional]* corner radius X dimension
* `ry` - *[optional]* corner radius Y dimension
* `class` - *[optional]* class attribute
* `id` - *[optional]* id attribute
* `style` - *[optional]* style attribute value
Expand Down
8 changes: 6 additions & 2 deletions pg-svg-lib.sql
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ CREATE OR REPLACE FUNCTION svgRect(
y float8,
width float8,
height float8,
rx float8 DEFAULT 0.0,
ry float8 DEFAULT 0.0,
class text DEFAULT '',
id text DEFAULT '',
style text DEFAULT '',
Expand All @@ -284,8 +286,10 @@ DECLARE
BEGIN
svg := '<rect '
|| _svgAttr( class, id, style, attr)
|| ' x="' || x || '" y="' || y
|| '" width="' || width || '" height="' || height
|| ' x="' || x || '" y="' || y || '"'
|| CASE WHEN rx = 0.0 THEN '' ELSE ' rx="' || rx || '"' END
|| CASE WHEN ry = 0.0 THEN '' ELSE ' ry="' || rx || '"' END
|| ' width="' || width || '" height="' || height
|| '" />';

IF title <> '' THEN
Expand Down
12 changes: 12 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# API Testing

These SQL scripts test the API for function SQL definitions
and SVG handling.

```
psql -At -o test-api.svg < test-api.sql
```

```
psql -At -o geomtype.svg < geomtype-svg.sql
```
3 changes: 2 additions & 1 deletion test/test-api.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

WITH shapes(svg) AS (VALUES
( svgRect(0, 50, 20, 40,
style => svgStyleProp(stroke => svgRGB(200, 0, 100),
rx => 5, ry => 2,
style => svgStyleProp(stroke => svgRGB(200, 0, 100),
strokewidth => '10',
fill => svgHSL(125, 80, 40),
fillopacity => '0.5'
Expand Down

0 comments on commit 7809e58

Please sign in to comment.