@antv/component 0.8.32 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/abstract/html-component.js +1 -9
- package/esm/abstract/html-component.js.map +1 -1
- package/esm/legend/category.js +12 -3
- package/esm/legend/category.js.map +1 -1
- package/esm/slider/constant.d.ts +46 -1
- package/esm/slider/constant.js +50 -4
- package/esm/slider/constant.js.map +1 -1
- package/esm/slider/foreground.d.ts +78 -0
- package/esm/slider/foreground.js +102 -0
- package/esm/slider/foreground.js.map +1 -0
- package/esm/slider/handler.d.ts +3 -8
- package/esm/slider/handler.js +8 -15
- package/esm/slider/handler.js.map +1 -1
- package/esm/slider/slider.d.ts +29 -4
- package/esm/slider/slider.js +243 -46
- package/esm/slider/slider.js.map +1 -1
- package/esm/tooltip/css-const.d.ts +0 -1
- package/esm/tooltip/css-const.js +0 -1
- package/esm/tooltip/css-const.js.map +1 -1
- package/esm/tooltip/html-theme.d.ts +0 -22
- package/esm/tooltip/html-theme.js +0 -7
- package/esm/tooltip/html-theme.js.map +1 -1
- package/esm/tooltip/html.d.ts +0 -23
- package/esm/tooltip/html.js +11 -27
- package/esm/tooltip/html.js.map +1 -1
- package/esm/util/event.d.ts +8 -0
- package/esm/util/event.js +11 -0
- package/esm/util/event.js.map +1 -1
- package/esm/util/mask.d.ts +9 -0
- package/esm/util/mask.js +26 -0
- package/esm/util/mask.js.map +1 -0
- package/esm/util/util.d.ts +10 -0
- package/esm/util/util.js +62 -1
- package/esm/util/util.js.map +1 -1
- package/lib/abstract/html-component.js +1 -9
- package/lib/abstract/html-component.js.map +1 -1
- package/lib/legend/category.js +12 -3
- package/lib/legend/category.js.map +1 -1
- package/lib/slider/constant.d.ts +46 -1
- package/lib/slider/constant.js +51 -5
- package/lib/slider/constant.js.map +1 -1
- package/lib/slider/foreground.d.ts +78 -0
- package/lib/slider/foreground.js +105 -0
- package/lib/slider/foreground.js.map +1 -0
- package/lib/slider/handler.d.ts +3 -8
- package/lib/slider/handler.js +9 -16
- package/lib/slider/handler.js.map +1 -1
- package/lib/slider/slider.d.ts +29 -4
- package/lib/slider/slider.js +240 -43
- package/lib/slider/slider.js.map +1 -1
- package/lib/tooltip/css-const.d.ts +0 -1
- package/lib/tooltip/css-const.js +1 -2
- package/lib/tooltip/css-const.js.map +1 -1
- package/lib/tooltip/html-theme.d.ts +0 -22
- package/lib/tooltip/html-theme.js +0 -7
- package/lib/tooltip/html-theme.js.map +1 -1
- package/lib/tooltip/html.d.ts +0 -23
- package/lib/tooltip/html.js +11 -27
- package/lib/tooltip/html.js.map +1 -1
- package/lib/util/event.d.ts +8 -0
- package/lib/util/event.js +13 -1
- package/lib/util/event.js.map +1 -1
- package/lib/util/mask.d.ts +9 -0
- package/lib/util/mask.js +32 -0
- package/lib/util/mask.js.map +1 -0
- package/lib/util/util.d.ts +10 -0
- package/lib/util/util.js +64 -1
- package/lib/util/util.js.map +1 -1
- package/package.json +6 -18
- package/src/abstract/html-component.ts +1 -12
- package/src/legend/category.ts +21 -12
- package/src/slider/constant.ts +54 -4
- package/src/slider/foreground.ts +158 -0
- package/src/slider/handler.ts +10 -20
- package/src/slider/slider.ts +275 -60
- package/src/tooltip/css-const.ts +0 -1
- package/src/tooltip/html-theme.ts +0 -8
- package/src/tooltip/html.ts +11 -29
- package/src/util/event.ts +12 -0
- package/src/util/mask.ts +32 -0
- package/src/util/util.ts +67 -2
package/src/util/util.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IElement, IGroup } from '@antv/g-base';
|
|
2
|
-
import { each, isArray, isNil, isNumber } from '@antv/util';
|
|
1
|
+
import { getOffScreenContext, IElement, IGroup } from '@antv/g-base';
|
|
2
|
+
import { each, isArray, isNil, isNumber, isString } from '@antv/util';
|
|
3
3
|
import { BBox, Point, Region } from '../types';
|
|
4
4
|
|
|
5
5
|
export function formatPadding(padding: number | number[]): number[] {
|
|
@@ -235,3 +235,68 @@ export function getTextPoint(start: Point, end: Point, position: string, offset:
|
|
|
235
235
|
y: getValueByPercent(start.y, end.y, percent),
|
|
236
236
|
};
|
|
237
237
|
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 获取字体宽度
|
|
241
|
+
* @param text 文本
|
|
242
|
+
* @param font 字体
|
|
243
|
+
*/
|
|
244
|
+
export function getTextWidth(text: string, font: string) {
|
|
245
|
+
const context = getOffScreenContext(); // 获取离屏的 ctx 进行计算
|
|
246
|
+
let width = 0;
|
|
247
|
+
// null 或者 undefined 时,宽度为 0
|
|
248
|
+
if (isNil(text) || text === '') {
|
|
249
|
+
return width;
|
|
250
|
+
}
|
|
251
|
+
context.save();
|
|
252
|
+
context.font = font;
|
|
253
|
+
if (isString(text) && text.includes('\n')) {
|
|
254
|
+
const textArr = text.split('\n');
|
|
255
|
+
each(textArr, (subText) => {
|
|
256
|
+
const measureWidth = context.measureText(subText).width;
|
|
257
|
+
if (width < measureWidth) {
|
|
258
|
+
width = measureWidth;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
} else {
|
|
262
|
+
width = context.measureText(text).width;
|
|
263
|
+
}
|
|
264
|
+
context.restore();
|
|
265
|
+
return width;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @description 文字超出最大宽度时,换行处理
|
|
270
|
+
*/
|
|
271
|
+
export function clipTextTwoLines(str: string, maxWidth: number, font: string) {
|
|
272
|
+
// 日期字段根据空格拆为两组:'2022-10-12 08:23' => ['2022-10-12', '08:23']
|
|
273
|
+
if (Date.parse(str)) {
|
|
274
|
+
return str.split(' ').join('\n');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function mapStr(str: string, callback: (i: number) => void) {
|
|
278
|
+
for (let i = 0; i < str.length; i++) {
|
|
279
|
+
const curStr = str.slice(0, i + 1);
|
|
280
|
+
const curWidth = getTextWidth(curStr, font);
|
|
281
|
+
if (curWidth > maxWidth) {
|
|
282
|
+
callback(i);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
let firstStr = '';
|
|
289
|
+
let secondStr = '';
|
|
290
|
+
// 文字拆分为两组
|
|
291
|
+
mapStr(str, (i: number) => {
|
|
292
|
+
firstStr = str.slice(0, i);
|
|
293
|
+
secondStr = str.slice(i);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// 第二行超出宽度时加省略号
|
|
297
|
+
mapStr(secondStr, (i: number) => {
|
|
298
|
+
secondStr = secondStr.slice(0, i - 1) + '...';
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
return firstStr + '\n' + secondStr;
|
|
302
|
+
}
|