|
| 1 | +html-lines |
| 2 | +========== |
| 3 | + |
| 4 | +Draw a line using an HTML element between two existing elements. Lines can easily be made to work responsively when attaching the `redraw` method to the window.resize event. Use CSS to control line styles and animation. Use the LINES API to manipulate the lines. |
| 5 | + |
| 6 | +LINES |
| 7 | +----- |
| 8 | +This is the global object created when loading html-lines.js. |
| 9 | +```html |
| 10 | +<script src="html-lines.js"></script> |
| 11 | +``` |
| 12 | + |
| 13 | +If using CommonJS, **LINES** would be created by requiring. |
| 14 | +```js |
| 15 | +var LINES = require('html-lines'); |
| 16 | +``` |
| 17 | + |
| 18 | +### LINES.setOptions |
| 19 | +@param - {Object} |
| 20 | +Change the default options. |
| 21 | +```js |
| 22 | +LINES.setOptions({ |
| 23 | + lineElementType: {String}, |
| 24 | + nameAttribute: {String}, |
| 25 | + stateAttribute: {String} |
| 26 | +}); |
| 27 | + |
| 28 | +// defaults |
| 29 | +{ |
| 30 | + lineElementType: 'div', |
| 31 | + nameAttribute: 'data-line', |
| 32 | + stateAttribute: 'data-line-state' |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +### LINES.createAnchor |
| 37 | +@param - {Object} |
| 38 | +@return - {Object} instance of Anchor |
| 39 | +```js |
| 40 | +var anchor = LINES.createAnchor({ |
| 41 | + el: {HTMLElement or querySelector String}, |
| 42 | + xOffset: {Number}, |
| 43 | + yOffset: {Number}, |
| 44 | + xOrigin: {'center' or 'left' or 'right'}, |
| 45 | + yOrigin: {'center' or 'top' or 'left'} |
| 46 | +}) |
| 47 | + |
| 48 | +// defaults |
| 49 | +{ |
| 50 | + el: document.body, |
| 51 | + xOffset: 0, |
| 52 | + yOffset: 0, |
| 53 | + xOrigin: 'center', |
| 54 | + yOrigin: 'center' |
| 55 | +} |
| 56 | +``` |
| 57 | +*Anchors don't add anything to the DOM.* |
| 58 | + |
| 59 | +### LINES.createLine |
| 60 | +@param - {Object} instance of Anchor |
| 61 | +@param - {Object} instance of Anchor |
| 62 | +@param - {Object} |
| 63 | +@return - {Object} instance of Line |
| 64 | +```js |
| 65 | +LINES.createLine(anchor1, anchor2, { |
| 66 | + name: {String}, |
| 67 | + state: {String} |
| 68 | +}) |
| 69 | + |
| 70 | +// defaults |
| 71 | +{ |
| 72 | + name: '', |
| 73 | + state: '' |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +### LINES.redraw |
| 78 | +Recalculates anchor positions and changes line position and size and angle |
| 79 | +```js |
| 80 | +LINES.redraw(); |
| 81 | +``` |
| 82 | + |
| 83 | +### LINES.getAnchors |
| 84 | +@return - {Array} |
| 85 | +```js |
| 86 | +var anchors = LINES.getAnchors(); |
| 87 | +``` |
| 88 | + |
| 89 | +### LINES.getLines |
| 90 | +@return - {Array} |
| 91 | +```js |
| 92 | +var lines = LINES.getLines(); |
| 93 | +``` |
| 94 | + |
| 95 | +### LINES.destroyAll |
| 96 | +```js |
| 97 | +LINES.destroyAll(); |
| 98 | +``` |
| 99 | + |
| 100 | +Instance of Anchor |
| 101 | +------------------ |
| 102 | + |
| 103 | +```js |
| 104 | +var anchor = LINES.createAnchor(...); |
| 105 | +``` |
| 106 | + |
| 107 | +### anchor.destory |
| 108 | +```js |
| 109 | +anchor.destory(); |
| 110 | +``` |
| 111 | +*Any lines attached to this anchor will also be destoryed.* |
| 112 | + |
| 113 | +Instance of Line |
| 114 | +---------------- |
| 115 | + |
| 116 | +```js |
| 117 | +var line = LINES.createLine(...); |
| 118 | +``` |
| 119 | + |
| 120 | +### line.name |
| 121 | +@param - {String} |
| 122 | +@return - {String} |
| 123 | +```js |
| 124 | +line.name('newName'); |
| 125 | +// or |
| 126 | +var name = line.name(); // newName |
| 127 | +``` |
| 128 | + |
| 129 | +### line.state |
| 130 | +@param - {String} |
| 131 | +@return - {String} |
| 132 | +```js |
| 133 | +line.state('newState'); |
| 134 | +// or |
| 135 | +var state = line.state(); // newState |
| 136 | +``` |
| 137 | + |
| 138 | +### line.destory |
| 139 | +```js |
| 140 | +line.destory(); |
| 141 | +``` |
0 commit comments