Skip to content

Commit

Permalink
Merge branch 'lindsvg-1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Amphiluke committed Jan 19, 2020
2 parents 853d444 + 312d68e commit 161d3ca
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 47 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ let lsParams = {

// Output SVG parameters (all of them are optional)
let svgParams = {
width: 600, // Desired SVG element width
height: 600, // Desired SVG element height
padding: 5, // Additional space to extend the viewBox
fill: "none", // Value of the “fill” attribute on the “path” element
stroke: "green" // Value of the “stroke” attribute on the “path” element
width: 600, // Desired SVG element width
height: 600, // Desired SVG element height
padding: 5, // Additional space to extend the viewBox
pathAttributes: { // Name to value map for the “path” element attributes
stroke: "green",
"stroke-width": "2px"
}
};

// Get ready-to-render L-system’s SVG code as a string
Expand Down
29 changes: 18 additions & 11 deletions dist/lindsvg.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
lindsvg v1.1.0
lindsvg v1.2.0
https://amphiluke.github.io/l-systems/
(c) 2020 Amphiluke
*/
Expand Down Expand Up @@ -265,17 +265,24 @@ function getSVGData(lsParams) {
*/
function getSVGCode(lsParams, svgParams) {
let {pathData, minX, minY, width, height} = getSVGData(lsParams);
svgParams = {
width,
height,
padding: 0,
fill: "none",
stroke: "#000",
...svgParams
let svgConfig = {
width: svgParams.width || width,
height: svgParams.height || height,
padding: svgParams.padding || 0,
pathAttributes: {
// for backward compatibility with v1.1.0, also check fill and stroke as direct props of svgParams
fill: svgParams.fill || "none",
stroke: svgParams.stroke || "#000",
...svgParams.pathAttributes
}
};
let {padding} = svgParams;
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${minX - padding} ${minY - padding} ${width + 2 * padding} ${height + 2 * padding}" height="${svgParams.height}" width="${svgParams.width}">
<path d="${pathData}" fill="${svgParams.fill}" stroke="${svgParams.stroke}"></path>
let {padding} = svgConfig;
let pathAttrStr = Object.entries(svgConfig.pathAttributes).reduce((accumulator, [name, value]) => {
value = value.replace(/"/g, "&quot;");
return `${accumulator} ${name}="${value}"`;
}, "");
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${minX - padding} ${minY - padding} ${width + 2 * padding} ${height + 2 * padding}" height="${svgConfig.height}" width="${svgConfig.width}">
<path d="${pathData}"${pathAttrStr}></path>
</svg>`;
}

Expand Down
4 changes: 2 additions & 2 deletions dist/lindsvg.esm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 18 additions & 11 deletions dist/lindsvg.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
lindsvg v1.1.0
lindsvg v1.2.0
https://amphiluke.github.io/l-systems/
(c) 2020 Amphiluke
*/
Expand Down Expand Up @@ -271,17 +271,24 @@ https://amphiluke.github.io/l-systems/
*/
function getSVGCode(lsParams, svgParams) {
let {pathData, minX, minY, width, height} = getSVGData(lsParams);
svgParams = {
width,
height,
padding: 0,
fill: "none",
stroke: "#000",
...svgParams
let svgConfig = {
width: svgParams.width || width,
height: svgParams.height || height,
padding: svgParams.padding || 0,
pathAttributes: {
// for backward compatibility with v1.1.0, also check fill and stroke as direct props of svgParams
fill: svgParams.fill || "none",
stroke: svgParams.stroke || "#000",
...svgParams.pathAttributes
}
};
let {padding} = svgParams;
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${minX - padding} ${minY - padding} ${width + 2 * padding} ${height + 2 * padding}" height="${svgParams.height}" width="${svgParams.width}">
<path d="${pathData}" fill="${svgParams.fill}" stroke="${svgParams.stroke}"></path>
let {padding} = svgConfig;
let pathAttrStr = Object.entries(svgConfig.pathAttributes).reduce((accumulator, [name, value]) => {
value = value.replace(/"/g, "&quot;");
return `${accumulator} ${name}="${value}"`;
}, "");
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${minX - padding} ${minY - padding} ${width + 2 * padding} ${height + 2 * padding}" height="${svgConfig.height}" width="${svgConfig.width}">
<path d="${pathData}"${pathAttrStr}></path>
</svg>`;
}

Expand Down
4 changes: 2 additions & 2 deletions dist/lindsvg.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lindsvg",
"version": "1.1.0",
"version": "1.2.0",
"description": "Lindenmayer System [Scalable] Vector Graphics",
"main": "dist/lindsvg.js",
"module": "dist/lindsvg.esm.js",
Expand Down
4 changes: 2 additions & 2 deletions src/lindsvg.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* @typedef {Object} SVGParams
* @property {Number} [width] - Desired SVG width
* @property {Number} [height] - Desired SVG height
* @property {String} [fill="none"] - Value of the “fill” attribute on the “path” element
* @property {String} [stroke="#000"] - Value of the “stroke” attribute on the “path” element
* @property {Number} [padding=0] - Additional space to extend the viewBox
* @property {Object} [pathAttributes={fill:"none",stroke:"#000"}] - Name to value map for the “path” element attributes
*/


Expand Down
Loading

0 comments on commit 161d3ca

Please sign in to comment.