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
keepId: v0.4.6+, Boolean, default is false, Whether to retain the id of the replicated node will be deleted by default to prevent duplicate node id. However, for mobile node scenarios, the original id of 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.
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.