semtonotes-utils v0.2.2
SemToNotes Utils
- Installation Browser Node.JS / CommonJS
- Load in Browser
- Debugging
- API
XrxUtils
applyStyle(shapes, styleDef)ExamplecreateDrawing(elem, width, height)createShape(shapeType, drawing, options)drawFromSvg(svgString, drawing, options)svgFromShapes(shapes, options)shapesFromSvg(svg, drawing, options)svgFromDrawing(drawing, options)navigationThumb(thumb, image, style={})angleFromMatrix(m00, m01)boundingBox(drawingOrGroupOrShape)abs2rel(coords, absval)rel2abs(coords, val)*isRectangle(c) - Authors
Installation
Browser
webpack -pThen include the built library in ./dist and semtonotes as window.xrx,
either with the official release or a suitable version of semtonotes-client:
Versions compatibility table
| s…-utils | s…-client |
|---|---|
| 0.2.1 to current | ^0.2.3 |
| 0.0.1 — 0.2.0 | see peerDependencies |
Node.JS / CommonJS
npm install semtonotes-utilsLoad in Browser
<!-- semtonotes must be loaded before, e.g.
<script src="https://unpkg.com/semtonotes-client@0.2.0"></script>
-->
<script src="path/to/xrx-utils.js"></script>Or via unpkg's cdn:
<script src="https://unpkg.com/semtonotes-client@0.2.0"></script>
<script src="https://unpkg.com/semtonotes-utils@0.1.7"></script>Debugging
Set window.XRX_DEBUG = true before loading the library to see debug messages.
API
XrxUtils
applyStyle(shapes, styleDef)
Apply a set of styles to one or more stylable elements.
@param {Array|Shape-Like} shapesStylable SemToNotes elements (shapes, groups...)@param {object} styleDefis an object of key-value pairs which map to xrx.shape.Style methods
Example
xrxUtils.applyStyle(rect1, {fillColor: '#aa9900'})createDrawing(elem, width, height)
Create a drawing in DOMElement elem. Overrides goog.style.getSize with
width/height for non-visible elements.
createShape(shapeType, drawing, options)
Options:
@param string shapeTypeShape Type, one ofRectanglePolygonCircleEllipseLinePolyline
@param xrx.drawing.Drawing drawingthe SemToNotes canvas to create the shape in@param Object optionsOptions that are interpreted as setter calls, c.f. applyStyle
drawFromSvg(svgString, drawing, options)
Translate svgString, a string containing SVG, to shapes and draw them
in drawing.
@param string svgStringSVG as a string@param xrx.drawing.Drawing drawingthe drawing to create the group in@param Object optionsAll options from shapesFromSvg.
svgFromShapes(shapes, options)
Generate SVG from a list of shapes or a shapeGroup.
@param {Shape|Array<Shape>|ShapeGroup} shapes@param Object options@param Object options.absoluteAssume SVG coordinates to be equal to image dimensions. Default:false@param Boolean options.scaleXFixed scale factor to scale x-coordinates by. Calculated unless provided. Falls back to1if not possible (i.e. absolute coords)@param Boolean options.scaleYFixed scale factor to scale y-coordinates by. Falls back to scaleX.@param Boolean options.svgWidthProvide the width of the SVG context to scale coordinates by.@param Boolean options.svgWidthditto height@param Boolean options.imgWidthOverride the width determined by the background image of the canvas.@param Boolean options.imgWidthditto height@param Boolean options.skipHeightWhether height should not be stored in SVG
shapesFromSvg(svg, drawing, options)
Create a ShapeGroup from the rect/polygon of an SVG.
@param string svgStringSVG as a string@param xrx.drawing.Drawing drawingthe drawing to create the group in@param Object options@param Boolean options.groupedCreate a new ShapeGroup with the shapes. Defaulttrue@param Boolean options.absoluteForce absolute coordinates. Default:false@param Boolean options.scaleXFixed scale factor to scale x-coordinates by. Calculated unless provided. Falls back to1if not possible (i.e. absolute coords)@param Boolean options.scaleYFixed scale factor to scale y-coordinates by. Falls back to scaleX.@param Boolean options.svgWidthProvide the width of the SVG context to scale coordinates by.@param Boolean options.svgWidthditto height@param Boolean options.imgWidthOverride the width determined by the background image of the canvas.@param Boolean options.imgWidthditto height@returns xrx.shape.ShapeGroup
svgFromDrawing(drawing, options)
Generate SVG from all shapes in a drawing.
@param {Shape|Array<Shape>|ShapeGroup} shapes@param Object optionsSeesvgFromShapes
navigationThumb(thumb, image, style={})
Show the viewbox of image as a rectangle in thumb
angleFromMatrix(m00, m01)
Calculate the angle between two matrices.
boundingBox(drawingOrGroupOrShape)
TODO groups
abs2rel(coords, absval)
coords is a list of float tuples. Multiply every float with 1000 and divide by absval
rel2abs(coords, val)
coords is a list of float tuples. Multiply every float with val and divide by 1000
isRectangle(c)
Determine whether an array of coordinates is a rectangle.
Authors
- Konstantin Baierer
- Jochen Barth
- Leonhard Maylein
- Dulip Withanage
4 years ago
4 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago