js2flowchart
Version:
> Why? While I've been working on [Under-the-hood-ReactJS](https://github.com/Bogdan-Lyashenko/Under-the-hood-ReactJS) I spent enormous amount of time on creating schemes. Each change in code or flowchart affects all entire scheme instantly, forcing you t
43 lines • 1.73 kB
JavaScript
import { calculateShapesBoundaries } from 'shared/utils/geometry';
export var SVGBase = function SVGBase() {
var state = {
shapes: [],
arrowConnections: []
};
return {
getShapes: function getShapes() {
return state.shapes;
},
addShapes: function addShapes(shapes) {
state.shapes = state.shapes.concat(shapes);
return this;
},
addArrowConnections: function addArrowConnections(arrowConnections) {
state.arrowConnections = state.arrowConnections.concat(arrowConnections);
return this;
},
printChildren: function printChildren(config) {
var svgString = "";
[].concat(state.shapes, state.arrowConnections).forEach(function (node) {
svgString += node.print(config);
});
return svgString;
},
calculateDimensions: function calculateDimensions() {
var boundaries = calculateShapesBoundaries(state.shapes.map(function (item) {
return item.getBoundaries();
})),
padding = 25;
return {
w: Math.ceil(boundaries.max.x) + padding,
h: Math.ceil(boundaries.max.y) + padding
};
},
print: function print(config) {
var _this$calculateDimens = this.calculateDimensions(),
w = _this$calculateDimens.w,
h = _this$calculateDimens.h;
return "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n width=\"".concat(w, "\" height=\"").concat(h, "\" shape-rendering=\"optimizeSpeed\">\n ").concat(this.printChildren(config), "\n </svg>");
}
};
};