@visactor/vrender-components 0.20.13-alpha.3 → 0.20.14
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/cjs/data-zoom/config.js +1 -2
- package/cjs/empty-tip/empty-tip.js +2 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/label/base.js +8 -3
- package/cjs/label/base.js.map +1 -1
- package/cjs/legend/base.d.ts +1 -0
- package/cjs/legend/base.js +7 -6
- package/cjs/legend/base.js.map +1 -1
- package/cjs/legend/discrete/discrete.d.ts +8 -0
- package/cjs/legend/discrete/discrete.js +112 -29
- package/cjs/legend/discrete/discrete.js.map +1 -1
- package/cjs/legend/discrete/type.d.ts +15 -3
- package/cjs/legend/discrete/type.js.map +1 -1
- package/dist/index.es.js +195 -49
- package/es/data-zoom/config.js +1 -2
- package/es/empty-tip/empty-tip.js +2 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/label/base.js +8 -2
- package/es/label/base.js.map +1 -1
- package/es/legend/base.d.ts +1 -0
- package/es/legend/base.js +7 -5
- package/es/legend/base.js.map +1 -1
- package/es/legend/discrete/discrete.d.ts +8 -0
- package/es/legend/discrete/discrete.js +112 -30
- package/es/legend/discrete/discrete.js.map +1 -1
- package/es/legend/discrete/type.d.ts +15 -3
- package/es/legend/discrete/type.js.map +1 -1
- package/package.json +3 -3
|
@@ -8,7 +8,7 @@ var __rest = this && this.__rest || function(s, e) {
|
|
|
8
8
|
return t;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
import { merge, isEmpty, normalizePadding, get, isValid, isNil, isFunction, isArray, minInArray, throttle } from "@visactor/vutils";
|
|
11
|
+
import { merge, isEmpty, normalizePadding, get, isValid, isNil, isFunction, isArray, minInArray, throttle, isNumberClose, clamp, isObject } from "@visactor/vutils";
|
|
12
12
|
|
|
13
13
|
import { graphicCreator } from "@visactor/vrender-core";
|
|
14
14
|
|
|
@@ -38,7 +38,7 @@ export class DiscreteLegend extends LegendBase {
|
|
|
38
38
|
constructor(attributes, options) {
|
|
39
39
|
super((null == options ? void 0 : options.skipDefault) ? attributes : merge({}, DiscreteLegend.defaultAttributes, attributes)),
|
|
40
40
|
this.name = "discreteLegend", this._itemsContainer = null, this._itemHeightByUser = void 0,
|
|
41
|
-
this._itemHeight = 0, this._itemMaxWidth = 0, this._onHover = e => {
|
|
41
|
+
this._itemHeight = 0, this._itemMaxWidth = 0, this._contentMaxHeight = 0, this._onHover = e => {
|
|
42
42
|
const target = e.target;
|
|
43
43
|
if (target && target.name && target.name.startsWith(LEGEND_ELEMENT_NAME.item)) {
|
|
44
44
|
const legendItem = target.delegate;
|
|
@@ -98,7 +98,7 @@ export class DiscreteLegend extends LegendBase {
|
|
|
98
98
|
}));
|
|
99
99
|
}
|
|
100
100
|
_renderItems() {
|
|
101
|
-
const {item: itemAttrs = {}, maxCol: maxCol = 1, maxRow: maxRow = 2, maxWidth: maxWidth,
|
|
101
|
+
const {item: itemAttrs = {}, maxCol: maxCol = 1, maxRow: maxRow = 2, maxWidth: maxWidth, defaultSelected: defaultSelected, lazyload: lazyload, autoPage: autoPage} = this.attribute, {spaceCol: spaceCol = DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = DEFAULT_ITEM_SPACE_ROW} = itemAttrs, itemsContainer = this._itemsContainer, {items: legendItems, isHorizontal: isHorizontal, startIndex: startIndex, isScrollbar: isScrollbar} = this._itemContext, maxPages = isScrollbar ? 1 : isHorizontal ? maxRow : maxCol, maxHeight = this._contentMaxHeight;
|
|
102
102
|
let item, {doWrap: doWrap, maxWidthInCol: maxWidthInCol, startX: startX, startY: startY, pages: pages} = this._itemContext, lastItemWidth = 0;
|
|
103
103
|
for (let index = startIndex, len = legendItems.length; index < len && !(lazyload && pages > this._itemContext.currentPage * maxPages); index++) {
|
|
104
104
|
lazyload && (this._itemContext.startIndex = index + 1), item = legendItems[index],
|
|
@@ -127,10 +127,10 @@ export class DiscreteLegend extends LegendBase {
|
|
|
127
127
|
lazyload || (this._itemContext.startIndex = legendItems.length), this._itemContext;
|
|
128
128
|
}
|
|
129
129
|
_renderContent() {
|
|
130
|
-
const {item: item = {}, items: items, reversed: reversed, maxWidth: maxWidth} = this.attribute;
|
|
130
|
+
const {item: item = {}, items: items, reversed: reversed, maxWidth: maxWidth, maxHeight: maxHeight} = this.attribute;
|
|
131
131
|
if (!1 === item.visible || isEmpty(items)) return;
|
|
132
132
|
let legendItems = items;
|
|
133
|
-
reversed && (legendItems = null == items ? void 0 : items.reverse());
|
|
133
|
+
reversed && (legendItems = null == items ? void 0 : items.reverse()), this._contentMaxHeight = Math.max(0, maxHeight - this._parsedPadding[0] - this._parsedPadding[2]);
|
|
134
134
|
const itemsContainer = graphicCreator.group({
|
|
135
135
|
x: 0,
|
|
136
136
|
y: 0
|
|
@@ -153,7 +153,8 @@ export class DiscreteLegend extends LegendBase {
|
|
|
153
153
|
items: legendItems,
|
|
154
154
|
isHorizontal: isHorizontal,
|
|
155
155
|
totalPage: 1 / 0,
|
|
156
|
-
isScrollbar: pager && "scrollbar" === pager.type
|
|
156
|
+
isScrollbar: pager && "scrollbar" === pager.type,
|
|
157
|
+
clipContainer: void 0
|
|
157
158
|
}, this._itemContext = this._renderItems();
|
|
158
159
|
let pagerRendered = !1;
|
|
159
160
|
this._itemContext.doWrap && autoPage && this._itemContext.pages > this._itemContext.maxPages && (pagerRendered = this._renderPagerComponent()),
|
|
@@ -164,8 +165,15 @@ export class DiscreteLegend extends LegendBase {
|
|
|
164
165
|
if (this.attribute.disableTriggerEvent) return;
|
|
165
166
|
if (!this._itemsContainer) return;
|
|
166
167
|
const {hover: hover = !0, select: select = !0} = this.attribute;
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
if (hover) {
|
|
169
|
+
let trigger = "pointermove", triggerOff = "pointerleave";
|
|
170
|
+
isObject(hover) && (hover.trigger && (trigger = hover.trigger), hover.triggerOff && (triggerOff = hover.triggerOff)),
|
|
171
|
+
this._itemsContainer.addEventListener(trigger, this._onHover), this._itemsContainer.addEventListener(triggerOff, this._onUnHover);
|
|
172
|
+
}
|
|
173
|
+
if (select) {
|
|
174
|
+
let trigger = "pointerdown";
|
|
175
|
+
isObject(select) && select.trigger && (trigger = select.trigger), this._itemsContainer.addEventListener(trigger, this._onClick);
|
|
176
|
+
}
|
|
169
177
|
}
|
|
170
178
|
_autoEllipsis(autoEllipsisStrategy, layoutWidth, labelShape, valueShape) {
|
|
171
179
|
var _a, _b;
|
|
@@ -307,12 +315,12 @@ export class DiscreteLegend extends LegendBase {
|
|
|
307
315
|
direction: "horizontal",
|
|
308
316
|
disableTriggerEvent: disableTriggerEvent,
|
|
309
317
|
range: [ 0, .5 ],
|
|
310
|
-
height: 12
|
|
318
|
+
height: !1 === compStyle.visible ? 0 : 12
|
|
311
319
|
}, compStyle), {
|
|
312
320
|
width: compSize
|
|
313
321
|
})) : new ScrollBar(Object.assign(Object.assign({
|
|
314
322
|
direction: "vertical",
|
|
315
|
-
width: 12,
|
|
323
|
+
width: !1 === compStyle.visible ? 0 : 12,
|
|
316
324
|
range: [ 0, .5 ]
|
|
317
325
|
}, compStyle), {
|
|
318
326
|
height: compSize,
|
|
@@ -337,9 +345,15 @@ export class DiscreteLegend extends LegendBase {
|
|
|
337
345
|
});
|
|
338
346
|
}
|
|
339
347
|
}
|
|
348
|
+
_computeScrollbarDelta() {
|
|
349
|
+
const {isHorizontal: isHorizontal, clipContainer: clipContainer} = this._itemContext, itemContainerBounds = this._itemsContainer.AABBBounds, clipContainerBounds = clipContainer.AABBBounds;
|
|
350
|
+
let delta, innerViewSize;
|
|
351
|
+
return isHorizontal ? (innerViewSize = clipContainerBounds.width(), delta = innerViewSize / itemContainerBounds.width()) : (innerViewSize = clipContainerBounds.height(),
|
|
352
|
+
delta = innerViewSize / itemContainerBounds.height()), delta;
|
|
353
|
+
}
|
|
340
354
|
_updatePositionOfScrollbar(contentWidth, contentHeight, renderStartY) {
|
|
341
|
-
const {currentPage: currentPage, totalPage: totalPage
|
|
342
|
-
this._pagerComponent.setScrollRange([
|
|
355
|
+
const {isHorizontal: isHorizontal, currentPage: currentPage, totalPage: totalPage} = this._itemContext, start = (currentPage - 1) / totalPage;
|
|
356
|
+
this._pagerComponent.setScrollRange([ start, start + this._computeScrollbarDelta() ]),
|
|
343
357
|
isHorizontal ? this._pagerComponent.setAttributes({
|
|
344
358
|
x: 0,
|
|
345
359
|
y: renderStartY + contentHeight
|
|
@@ -352,20 +366,32 @@ export class DiscreteLegend extends LegendBase {
|
|
|
352
366
|
const pager = this.attribute.pager || {}, {animation: animation = !0, animationDuration: animationDuration = 450, animationEasing: animationEasing = "quadIn"} = pager, pageParser = this._itemContext.isScrollbar ? e => {
|
|
353
367
|
const {value: value} = e.detail;
|
|
354
368
|
let newPage;
|
|
355
|
-
return 0 === value[0] ?
|
|
356
|
-
|
|
369
|
+
return newPage = 0 === value[0] ? 1 : 1 === value[1] ? this._itemContext.totalPage : value[0] * this._itemContext.totalPage + 1,
|
|
370
|
+
newPage;
|
|
357
371
|
} : e => e.detail.current, onScroll = e => {
|
|
358
372
|
const scrollComponent = this._pagerComponent, preScrollRange = scrollComponent.getScrollRange(), {direction: direction} = scrollComponent.attribute, {width: width, height: height} = scrollComponent.getSliderRenderBounds(), currentScrollValue = "vertical" === direction ? e.deltaY / height : e.deltaX / width;
|
|
359
|
-
scrollComponent.setScrollRange([ preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue ], !0)
|
|
373
|
+
scrollComponent.setScrollRange([ preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue ], !0),
|
|
374
|
+
this.updateScrollMask();
|
|
360
375
|
}, onPaging = e => {
|
|
361
376
|
const newPage = pageParser(e);
|
|
362
377
|
if (newPage !== this._itemContext.currentPage) {
|
|
363
378
|
if (this._itemContext.currentPage = newPage, this._itemContext && this._itemContext.startIndex < this._itemContext.items.length) {
|
|
364
379
|
this._renderItems();
|
|
365
380
|
const newTotalPage = Math.ceil(this._itemContext.pages / this._itemContext.maxPages);
|
|
366
|
-
this._itemContext.totalPage = newTotalPage, this.
|
|
381
|
+
if (this._itemContext.totalPage = newTotalPage, this._itemContext.isScrollbar && this._pagerComponent) {
|
|
382
|
+
const newDelta = this._computeScrollbarDelta(), [start] = this._pagerComponent.getScrollRange();
|
|
383
|
+
this._pagerComponent.setScrollRange([ start, start + newDelta ]);
|
|
384
|
+
}
|
|
367
385
|
}
|
|
368
|
-
|
|
386
|
+
if (this._itemContext.isScrollbar) {
|
|
387
|
+
const [start] = this._pagerComponent.getScrollRange();
|
|
388
|
+
let containerSize;
|
|
389
|
+
containerSize = this._itemContext.isHorizontal ? this._itemsContainer.AABBBounds.width() : this._itemsContainer.AABBBounds.height();
|
|
390
|
+
const startOffset = containerSize * start;
|
|
391
|
+
this.updateScrollMask(), animation ? this._itemsContainer.animate().to({
|
|
392
|
+
[channel]: -startOffset
|
|
393
|
+
}, animationDuration, animationEasing) : this._itemsContainer.setAttribute(channel, -startOffset);
|
|
394
|
+
} else animation ? this._itemsContainer.animate().to({
|
|
369
395
|
[channel]: -(newPage - 1) * pageSize
|
|
370
396
|
}, animationDuration, animationEasing) : this._itemsContainer.setAttribute(channel, -(newPage - 1) * pageSize);
|
|
371
397
|
}
|
|
@@ -379,7 +405,7 @@ export class DiscreteLegend extends LegendBase {
|
|
|
379
405
|
} else this._pagerComponent.addEventListener("toPrev", onPaging), this._pagerComponent.addEventListener("toNext", onPaging);
|
|
380
406
|
}
|
|
381
407
|
_renderPager() {
|
|
382
|
-
const renderStartY = this._title ? this._title.AABBBounds.height() + get(this.attribute, "title.space", 8) : 0, {maxWidth: maxWidth,
|
|
408
|
+
const renderStartY = this._title ? this._title.AABBBounds.height() + get(this.attribute, "title.space", 8) : 0, {maxWidth: maxWidth, maxCol: maxCol = 1, maxRow: maxRow = 2, item: item = {}, pager: pager = {}} = this.attribute, {spaceCol: spaceCol = DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = DEFAULT_ITEM_SPACE_ROW} = item, itemsContainer = this._itemsContainer, {space: pagerSpace = DEFAULT_PAGER_SPACE, defaultCurrent: defaultCurrent = 1} = pager, compStyle = __rest(pager, [ "space", "defaultCurrent" ]), {isHorizontal: isHorizontal} = this._itemContext, maxHeight = this._contentMaxHeight;
|
|
383
409
|
let comp, compWidth = 0, compHeight = 0, contentWidth = 0, contentHeight = 0, startX = 0, startY = 0, pages = 1;
|
|
384
410
|
if (isHorizontal) {
|
|
385
411
|
if (compHeight = (maxRow - 1) * spaceRow + this._itemHeight * maxRow, compWidth = maxWidth,
|
|
@@ -421,18 +447,20 @@ export class DiscreteLegend extends LegendBase {
|
|
|
421
447
|
clip: !0,
|
|
422
448
|
pickable: !1
|
|
423
449
|
});
|
|
424
|
-
return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this.
|
|
450
|
+
return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this._itemContext.clipContainer = clipGroup,
|
|
451
|
+
this._bindEventsOfPager(isHorizontal ? compHeight + spaceRow : compWidth + spaceCol, isHorizontal ? "y" : "x"),
|
|
425
452
|
!0;
|
|
426
453
|
}
|
|
427
454
|
_renderScrollbar() {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
comp = this._createScrollbar(compStyle,
|
|
432
|
-
this.
|
|
433
|
-
if (
|
|
434
|
-
this.
|
|
435
|
-
contentHeight <= 0) return this._innerView.removeChild(comp),
|
|
455
|
+
var _a;
|
|
456
|
+
const renderStartY = this._title ? this._title.AABBBounds.height() + get(this.attribute, "title.space", 8) : 0, {maxWidth: maxWidth, item: item = {}, pager: pager = {}} = this.attribute, {spaceCol: spaceCol = DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = DEFAULT_ITEM_SPACE_ROW} = item, itemsContainer = this._itemsContainer, {space: pagerSpace = DEFAULT_PAGER_SPACE, defaultCurrent: defaultCurrent = 1} = pager, compStyle = __rest(pager, [ "space", "defaultCurrent" ]), {isHorizontal: isHorizontal} = this._itemContext, maxHeight = this._contentMaxHeight;
|
|
457
|
+
let comp, contentWidth = 0, contentHeight = 0, startY = 0, pages = 1;
|
|
458
|
+
if (isHorizontal) contentWidth = maxWidth, contentHeight = this._itemHeight, comp = this._createScrollbar(compStyle, contentWidth),
|
|
459
|
+
this._pagerComponent = comp, this._innerView.add(comp); else {
|
|
460
|
+
if (contentHeight = maxHeight - renderStartY, contentWidth = this._itemMaxWidth,
|
|
461
|
+
comp = this._createScrollbar(compStyle, contentHeight), this._pagerComponent = comp,
|
|
462
|
+
this._innerView.add(comp), contentHeight <= 0) return this._innerView.removeChild(comp),
|
|
463
|
+
!1;
|
|
436
464
|
const items = itemsContainer.getChildren(), itemsHeightArr = items.map((item => item.attribute.height));
|
|
437
465
|
if (1 === itemsHeightArr.length || itemsHeightArr.every((entry => entry === itemsHeightArr[0]))) {
|
|
438
466
|
const itemHeight = itemsHeightArr[0], maxContentHeight = contentHeight, pageItemsCount = Math.floor(maxContentHeight / (spaceRow + itemHeight));
|
|
@@ -443,9 +471,15 @@ export class DiscreteLegend extends LegendBase {
|
|
|
443
471
|
prePages !== pages && index === itemsContainer.getChildren().length - 1 && startY - contentHeight >= 1 / 3 * height && (contentHeight = preStartY + height,
|
|
444
472
|
pages -= 1);
|
|
445
473
|
}));
|
|
446
|
-
this._itemContext.totalPage = pages, this._itemContext.pages = pages
|
|
474
|
+
this._itemContext.totalPage = pages, this._itemContext.pages = pages;
|
|
475
|
+
}
|
|
476
|
+
if (defaultCurrent > 1) if (isHorizontal) {
|
|
477
|
+
const maxOffset = this._itemsContainer.AABBBounds.width() - contentWidth;
|
|
478
|
+
itemsContainer.setAttribute("x", -Math.min((defaultCurrent - 1) * (contentWidth + spaceCol), maxOffset));
|
|
479
|
+
} else {
|
|
480
|
+
const maxOffset = this._itemsContainer.AABBBounds.height() - contentHeight;
|
|
481
|
+
itemsContainer.setAttribute("y", -Math.min((defaultCurrent - 1) * (contentHeight + spaceRow), maxOffset));
|
|
447
482
|
}
|
|
448
|
-
defaultCurrent > 1 && (isHorizontal ? itemsContainer.setAttribute("x", -(defaultCurrent - 1) * (contentWidth + spaceCol)) : itemsContainer.setAttribute("y", -(defaultCurrent - 1) * (contentHeight + spaceRow)));
|
|
449
483
|
const clipGroup = graphicCreator.group({
|
|
450
484
|
x: 0,
|
|
451
485
|
y: renderStartY,
|
|
@@ -454,9 +488,57 @@ export class DiscreteLegend extends LegendBase {
|
|
|
454
488
|
clip: !0,
|
|
455
489
|
pickable: !1
|
|
456
490
|
});
|
|
457
|
-
return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this.
|
|
491
|
+
return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this._itemContext.clipContainer = clipGroup,
|
|
492
|
+
this._updatePositionOfScrollbar(contentWidth, contentHeight, renderStartY), (null === (_a = pager.scrollMask) || void 0 === _a ? void 0 : _a.visible) && this.renderScrollMask(clipGroup),
|
|
493
|
+
this._bindEventsOfPager(isHorizontal ? contentWidth : contentHeight, isHorizontal ? "x" : "y"),
|
|
458
494
|
!0;
|
|
459
495
|
}
|
|
496
|
+
renderScrollMask(clipGroup) {
|
|
497
|
+
const {scrollMask: scrollMask = {}} = this.attribute.pager, {visible: visible = !0, gradientLength: gradientLength = 16, gradientStops: gradientStops} = scrollMask;
|
|
498
|
+
if (!visible || !gradientStops) return;
|
|
499
|
+
const width = clipGroup.AABBBounds.width(), height = clipGroup.AABBBounds.height(), totalLength = this._itemContext.isHorizontal ? width : height, startStops = gradientStops.map((stop => ({
|
|
500
|
+
offset: gradientLength * stop.offset / totalLength,
|
|
501
|
+
color: stop.color
|
|
502
|
+
}))), endStops = gradientStops.map((stop => ({
|
|
503
|
+
offset: (totalLength - gradientLength * stop.offset) / totalLength,
|
|
504
|
+
color: stop.color
|
|
505
|
+
}))), mask = graphicCreator.rect({
|
|
506
|
+
x: 0,
|
|
507
|
+
y: 0,
|
|
508
|
+
width: width,
|
|
509
|
+
height: height
|
|
510
|
+
});
|
|
511
|
+
this._scrollMask = mask, this._scrollMaskContext = {
|
|
512
|
+
startStops: startStops,
|
|
513
|
+
endStops: endStops
|
|
514
|
+
}, this.updateScrollMask(), clipGroup.add(mask);
|
|
515
|
+
}
|
|
516
|
+
updateScrollMask() {
|
|
517
|
+
if (!this._scrollMask || !this._pagerComponent) return;
|
|
518
|
+
if (!this._itemContext.isScrollbar) return;
|
|
519
|
+
const [start, end] = this._pagerComponent.getScrollRange(), stops = [];
|
|
520
|
+
isNumberClose(clamp(end, 0, 1), 1) || stops.push(...this._scrollMaskContext.endStops),
|
|
521
|
+
isNumberClose(clamp(start, 0, 1), 0) || stops.push(...this._scrollMaskContext.startStops),
|
|
522
|
+
stops.length && (this._itemContext.isHorizontal ? this._scrollMask.setAttributes({
|
|
523
|
+
fill: {
|
|
524
|
+
gradient: "linear",
|
|
525
|
+
x0: 0,
|
|
526
|
+
y0: 0,
|
|
527
|
+
x1: 1,
|
|
528
|
+
y1: 0,
|
|
529
|
+
stops: stops
|
|
530
|
+
}
|
|
531
|
+
}) : this._scrollMask.setAttributes({
|
|
532
|
+
fill: {
|
|
533
|
+
gradient: "linear",
|
|
534
|
+
x0: 0,
|
|
535
|
+
y0: 0,
|
|
536
|
+
x1: 0,
|
|
537
|
+
y1: 1,
|
|
538
|
+
stops: stops
|
|
539
|
+
}
|
|
540
|
+
}));
|
|
541
|
+
}
|
|
460
542
|
_renderPagerComponent() {
|
|
461
543
|
return this._itemContext.isScrollbar ? this._renderScrollbar() : this._renderPager(),
|
|
462
544
|
!0;
|