SVG Creator

Sample#

Sample UI.js that uses the Section SVGCreator Package

var creator = SVGCreator;
creator.initialize({
total_height: 100,
total_width: 150,
align: 'left'
});
creator.addText({
text_value: 'TEST SVG CREATOR'
});
creator.addRect({
x: 0,
y: 20,
width: 50,
height: 40,
fill_color: 'green'
});
creator.endSVG();
var html = creator.getSVGHtml();
ui_div.outerHTML = html;

Available Methods#

MethodDescription
addMarker(marker_obj)Adds a marker to the SVG for arrows on dimension lines.
addRect(rect_obj)Creates a rectangle element in the SVG.
addPath(path_obj)Creates a path element in the SVG defined by a series of coordinates.
addCircle(circle_obj)Adds a circle element to the SVG.
addLine(line_obj)Creates a line element in the SVG with options for stroke color, width, dasharray, and marker definitions.
addText(text_obj)Adds a text element to the SVG with options for position, font family, size, and color.
addBreakLine(breakline_obj)Adds a break line to help simplfy the process of engineering drawings.
dimLineDrawer(dimline_obj)Easily add a dimension line to the creator.
endSVG()Ends the SVG structure by closing the SVG and div tags.
getSVGHtml()Returns the SVG HTML string generated by the SVGCreator object.

marker_obj

A JavaScript Object that can contain the following properties.

PropertyDescription
marker_idSpecifies the unique identifier for the marker.
marker_widthSets the width of the marker.
marker_heightSets the height of the marker.
refXDefines the x-coordinate for the reference point of the marker.
refYDefines the y-coordinate for the reference point of the marker.
marker_dimsContains an array of coordinate pairs defining the polygonal shape of the marker..
fill_colorDefines the fill color of the marker.
transformTransform string. See SVG docs

rect_obj

A JavaScript Object that can contain the following properties.

PropertyDescription
xSpecifies the x-coordinate of the upper-left corner of the rectangle.
ySpecifies the y-coordinate of the upper-left corner of the rectangle.
rxRounding of rectangle corner on x side.
ryRounding of rectangle corner on y side.
widthSets the width of the rectangle.
heightSets the height of the rectangle.
fill_colorDefines the fill color of the rectangle.
fill_opacityDefines the fill opacity of the rectangle.
strokeDefines the stroke color of the rectangle.
stroke_linejoinDefines the stroke line join of the rectangle.
stroke_widthDefines the stroke width of the rectangle.
stroke_dasharraySets the dash pattern for the line's stroke, if provided s in csv format.
stroke_opacitySets the stroke opacity of the rectangles line.
transformTransform string. See SVG docs

path_obj

A JavaScript Object that can contain the following properties.

PropertyDescription
starting_xRepresents the x-coordinate of the starting point of the path.
starting_yRepresents the y-coordinate of the starting point of the path.
dims_arrAn array containing pairs of x and y coordinates, defining the subsequent line segments of the path.
dIs the d parameter of the svg path. Overrides the dims_arr.
strokeSets the color of the path's stroke.
stroke_widthSets the width of the path's stroke.
stroke_linejoinDefines the stroke line join of the path.
stroke_dasharraySets the dash pattern for the path's stroke, if provided as a csv format.
stroke_opacityFill opacity of the stroke.
fill_colorDefines the fill color of the path.
fill_opacityFill opacity of the path.
marker_end_defSpecifies the marker definition for the end of the path, if provided.
marker_start_defSpecifies the marker definition for the start of the path, if provided.
transformTransform string. See SVG docs

circle_obj

A JavaScript Object that can contain the following properties.

PropertyDescription
center_xRepresents the x-coordinate of the circle's center.
center_yRepresents the y-coordinate of the circle's center.
radiusSets the radius of the circle.
strokeSets the color of the circle's stroke.
stroke_widthSets the stroke width of the circle's stroke.
stroke_opacitySets the stroke opacity of the circle's line.
stroke_dasharraySets the dash pattern for the circle's stroke, if provided as a csv format.
fill_colorSets the fill color of the circle.
fill_opacitySets the fill opacity of the circle.
transformTransform string. See SVG docs

line_obj

A JavaScript Object that can contain the following properties.

PropertyDescription
start_xSpecifies the x-coordinate of the starting point of the line.
start_ySpecifies the y-coordinate of the starting point of the line.
end_xSpecifies the x-coordinate of the ending point of the line.
end_ySpecifies the y-coordinate of the ending point of the line.
strokeSets the color of the line's stroke.
stroke_widthSets the width of the line's stroke, if provided.
stroke_dasharraySets the dash pattern for the line's stroke, if provided as an csv format.
stroke_linejoinSets the stroke linejoin for the line's stroke.
marker_end_defSpecifies the marker definition for the end of the line, if provided.
marker_start_defSpecifies the marker definition for the start of the line, if provided.
opacitySets the text opacity.
transformTransform string. See SVG docs

text_obj

A JavaScript Object that can contain the following properties.

PropertyDescription
xSpecifies the x-coordinate of the starting point of the text.
ySpecifies the y-coordinate of the starting point of the text.
font_familyDefines the font family of the text, defaulting to "Helvetica, Segoe UI Emoji" if not provided.
font_sizeSets the font size of the text, defaulting to "12px" if not provided.
font_weightSets the font weight of the text, defaulting to "normal" (normal, bold, bolder, lighter).
fill_colorSets the fill color of the text, defaulting to "#000000" if not provided.
text_valueContains the actual text value to be displayed.
text_decorationSets the text decoration, defaulting to "none" (underline, line-through).
text_anchorThe text anchor position. Default start.
dominant_baselineThe text dominant baseline, position. Default text-before-edge.
opacitySet the text opacity.
directionThe text direction. Default ltr.
transformTransform string. See SVG docs

breakline_obj

A JavaScript Object that can contain the following properties.

PropertyDescription
start_xSpecifies the x-coordinate of the starting point of the line.
start_ySpecifies the y-coordinate of the starting point of the line.
end_xSpecifies the x-coordinate of the ending point of the line.
end_ySpecifies the y-coordinate of the ending point of the line.
sizeSize of the break, if provided.
strokeSets the color of the line's stroke, if provided.
stroke_widthSets the width of the line's stroke, if provided.
fill_colorDefines the fill color of the path, if provided.

dimline_obj

A JavaScript Object that can contain the following properties.

PropertyDescription
x1Start x location of the line.
y1Start y location of the line.
x2End x location of the line.
y2End y location of the line.
posPosition of the text.
colorColor of the text. Default black.
textThe text.
text_sizeThe text size. Default 10.
arrow_sizeThe text. Default 4.

Example

var creator = SVGCreator;
creator.initialize({
align: 'center',
width: 500,
height: 500
});
creator.dimLineDrawer({
x1: input_json.x_1,
y1: input_json.y_1,
x2: input_json.x_2,
y2: input_json.y_2,
pos: input_json.dropdown_input,
color: "blue",
text: input_json.text_input,
text_size: input_json.text_size_input,
arrow_size: input_json.arrow_size_input
});
creator.endSVG();
var svg_html = creator.getSVGHtml();