Reference:
import {walk, ...} from 'simple-mind-map/src/utils'
v0.6.5+
width: The original width of the image
height:The original height of the image
newWidth:Width to zoom in to
newHeight:Height to zoom in to
Scale the image proportionally. Zoom to the specified size of newWidth and newHeight while maintaining the original aspect ratio of the image.
Depth-first traversal of a tree
root: the root node of the tree to be traversed
parent: parent node
beforeCallback: preorder traversal callback function, callback parameters are:
root, parent, isRoot, layerIndex, index
afterCallback: postorder traversal callback function, callback parameters are:
root, parent, isRoot, layerIndex, index
isRoot: whether it is the root node
layerIndex: node level
index: index of the node among its siblings
Example:
walk(tree, null, () => {}, () => {}, false, 0, 0);
Breadth-first traversal of a tree
Resize image size
width: original width of the image
height: original height of the image
maxWidth: the width to resize to
maxHeight: the height to resize to
maxWidth and maxHeight can both be passed, or only one of them can be passed
Resize image, internally loads the image first, then calls the resizeImgSize
method, and returns a promise
Extremely simple deep copy method, can only be used for objects that are all basic data, otherwise it will throw an error
Copy render tree data, example:
copyRenderTree({}, this.mindMap.renderer.renderTree);
removeActiveState: Boolean, default is false, Whether to remove the active state of the node
removeId:v0.7.3-fix.1+, Is remove the uid from the node data, default is true
keepId: (Original fourth parameter) v0.4.6+,Boolean, default isfalse, Whether to retain theidof the replicated node will be deleted by default to prevent duplicate nodeid. However, for mobile node scenarios, the originalidof the node needs to be retained
Copy node tree data, mainly eliminating the reference node instance _node
and copying the data of the data object, example:
copyNodeTree({}, node);
Convert image to dataURL
Download file
Throttle function
Run tasks in task list asynchronously, tasks are run synchronously without order
v0.2.24+
Angle to radian
v0.2.24+
CamelCase to hyphen
v0.3.4+
Join the font attribute value of the css font
v0.3.4+
Measure the width and height of the text, return value:
{ width, height }
Extract plain text content from an HTML string.
v0.5.9+
Convert blob data to data:url data.
v0.6.6+
Parse data:url data, return:
{
type,// file type of data
base64// base64 data
}
v0.6.6+
src: The url of imgGet the size of image, return:
{
width,
height
}
v0.6.8+
imgFile: File object of image typeLoad image, return:
{
url,// DataUrl
size// { width, height } width and height of image
}
v0.6.9+
Get the type of a data, such as Boolean、Array.
v0.6.10+
Remove the inline style of nodes in the HTML string.
v0.6.10+
Add inline styles to the specified tags in the HTML tag.
v0.6.10+
Check if a string is a rich text character.
v0.6.11+
Determine whether a color is white.
v0.6.11+
Determine whether a color is transparent.
v0.6.12+
Convert the rich text content of nodes in the form of <p><span></span><p> into text wrapped in \n.
v0.6.12+
Convert the wrapped text of <br> into node rich text content in the form of <p><span></span><p>.
v0.6.13+
Determine if it is a mobile environment.
v0.7.2+
list: Arrray, Node instance list.Find the top-level node list from the node instance list.
v0.7.2+
The parameter is the position of two rectangles.
Determine if two rectangles overlap.
v0.7.2+
el: DOM nodes, elements that can be focused, typically input box elements.Focus on the specified input box.
v0.7.2+
el: DOM nodes, elements that can be focused, typically input box elements.Focus and select all specified input boxes.
v0.7.2+
appointNodes:Node instance list, array type.
data:The data to be attached to all nodes in the specified node instance list tree.
Adding additional data to the specified node list tree data will modify the original data.
v0.7.2+
appointNodes:Node instance list, array type.
createNewId:v0.7.3-fix.1+, Boolean, default is false, If the node does not have a 'uid', a new 'uid' will be created. If 'true' is passed, a new 'uid' will be created regardless of whether the node data originally exists or not`
Adding a uid to the specified node list tree data (if the uid does not exist) will modify the original data.
v0.7.2+
node:Node instance.Gets the position index of a node within its peers.
v0.7.2+
list:The array of node icons to be merged into the library.// const data = [
// { type: 'priority', name: '优先级图标', list: [{ name: '1', icon: 'a' }, { name: 2, icon: 'b' }] },
// { type: 'priority', name: '优先级图标', list: [{ name: '2', icon: 'c' }, { name: 3, icon: 'd' }] },
// ];
// mergerIconList(data) result:
// [
// { type: 'priority', name: '优先级图标', list: [{ name: '1', icon: 'a' }, { name: 2, icon: 'c' }, { name: 3, icon: 'd' }] },
// ]
Merge icon arrays.
v0.7.2+
str:String.Escape the incoming string, currently escaping the following three characters:
& -> &
< -> <
> -> >
v0.7.2+
str:String.Generate colors based on incoming content, and the same content will generate the same color.
v0.7.3+
a、b: Object | Array, Two objects to compareDetermine whether two objects are the same, only handling objects or arrays.
Import:
import drawBackgroundImageToCanvas from 'simple-mind-map/src/utils/simulateCSSBackgroundInCanvas'
Usage:
let width = 500
let height = 500
let img = '/1.jpg'
let canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
drawBackgroundImageToCanvas(ctx, width, height, img, {
backgroundRepeat: 'repeat-y',
backgroundSize: '60%',
backgroundPosition: 'center center'
}, (err) => {
if (err) {
// fail
} else {
// success
}
})
v0.5.10+
Import:
import Lru from 'simple-mind-map/src/utils/Lru.js'
let lru = new Lru(max)
max: Specify the maximum number of caches.
The current number of caches.
Get cache pool.
Add cache.
Delete cache.
Check if a cache exists.
Gets the value of a cache.