MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / fittingString

Function fittingString

frontend/packages/common/src/utils/systemRunning.ts:105–123  ·  view source on GitHub ↗
(str: string, maxWidth: number, fontSize: number)

Source from the content-addressed store, hash-verified

103 * @returns
104 */
105export const fittingString = (str: string, maxWidth: number, fontSize: number) => {
106 const ellipsis = '...'
107 const ellipsisLength = G6.Util.getTextSize(ellipsis, fontSize)[0]
108 let currentWidth = 0
109 let res = str
110 const pattern = new RegExp('[\u4E00-\u9FA5]+')
111 str.split('').forEach((letter, i) => {
112 if (currentWidth > maxWidth - ellipsisLength) return
113 if (pattern.test(letter)) {
114 currentWidth += fontSize
115 } else {
116 currentWidth += G6.Util.getLetterWidth(letter, fontSize)
117 }
118 if (currentWidth > maxWidth - ellipsisLength) {
119 res = `${str.substr(0, i)}${ellipsis}`
120 }
121 })
122 return res
123}
124
125/**
126 * 动态获取节点距离

Callers 1

nodesFormatterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected