@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.
@@ -28,7 +28,7 @@ class DiscreteLegend extends base_1.LegendBase {
28
28
  constructor(attributes, options) {
29
29
  super((null == options ? void 0 : options.skipDefault) ? attributes : (0, vutils_1.merge)({}, DiscreteLegend.defaultAttributes, attributes)),
30
30
  this.name = "discreteLegend", this._itemsContainer = null, this._itemHeightByUser = void 0,
31
- this._itemHeight = 0, this._itemMaxWidth = 0, this._onHover = e => {
31
+ this._itemHeight = 0, this._itemMaxWidth = 0, this._contentMaxHeight = 0, this._onHover = e => {
32
32
  const target = e.target;
33
33
  if (target && target.name && target.name.startsWith(constant_1.LEGEND_ELEMENT_NAME.item)) {
34
34
  const legendItem = target.delegate;
@@ -90,7 +90,7 @@ class DiscreteLegend extends base_1.LegendBase {
90
90
  }));
91
91
  }
92
92
  _renderItems() {
93
- const {item: itemAttrs = {}, maxCol: maxCol = 1, maxRow: maxRow = 2, maxWidth: maxWidth, maxHeight: maxHeight, defaultSelected: defaultSelected, lazyload: lazyload, autoPage: autoPage} = this.attribute, {spaceCol: spaceCol = constant_1.DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = constant_1.DEFAULT_ITEM_SPACE_ROW} = itemAttrs, itemsContainer = this._itemsContainer, {items: legendItems, isHorizontal: isHorizontal, startIndex: startIndex, isScrollbar: isScrollbar} = this._itemContext, maxPages = isScrollbar ? 1 : isHorizontal ? maxRow : maxCol;
93
+ const {item: itemAttrs = {}, maxCol: maxCol = 1, maxRow: maxRow = 2, maxWidth: maxWidth, defaultSelected: defaultSelected, lazyload: lazyload, autoPage: autoPage} = this.attribute, {spaceCol: spaceCol = constant_1.DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = constant_1.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;
94
94
  let item, {doWrap: doWrap, maxWidthInCol: maxWidthInCol, startX: startX, startY: startY, pages: pages} = this._itemContext, lastItemWidth = 0;
95
95
  for (let index = startIndex, len = legendItems.length; index < len && !(lazyload && pages > this._itemContext.currentPage * maxPages); index++) {
96
96
  lazyload && (this._itemContext.startIndex = index + 1), item = legendItems[index],
@@ -120,10 +120,10 @@ class DiscreteLegend extends base_1.LegendBase {
120
120
  lazyload || (this._itemContext.startIndex = legendItems.length), this._itemContext;
121
121
  }
122
122
  _renderContent() {
123
- const {item: item = {}, items: items, reversed: reversed, maxWidth: maxWidth} = this.attribute;
123
+ const {item: item = {}, items: items, reversed: reversed, maxWidth: maxWidth, maxHeight: maxHeight} = this.attribute;
124
124
  if (!1 === item.visible || (0, vutils_1.isEmpty)(items)) return;
125
125
  let legendItems = items;
126
- reversed && (legendItems = null == items ? void 0 : items.reverse());
126
+ reversed && (legendItems = null == items ? void 0 : items.reverse()), this._contentMaxHeight = Math.max(0, maxHeight - this._parsedPadding[0] - this._parsedPadding[2]);
127
127
  const itemsContainer = vrender_core_1.graphicCreator.group({
128
128
  x: 0,
129
129
  y: 0
@@ -146,7 +146,8 @@ class DiscreteLegend extends base_1.LegendBase {
146
146
  items: legendItems,
147
147
  isHorizontal: isHorizontal,
148
148
  totalPage: 1 / 0,
149
- isScrollbar: pager && "scrollbar" === pager.type
149
+ isScrollbar: pager && "scrollbar" === pager.type,
150
+ clipContainer: void 0
150
151
  }, this._itemContext = this._renderItems();
151
152
  let pagerRendered = !1;
152
153
  this._itemContext.doWrap && autoPage && this._itemContext.pages > this._itemContext.maxPages && (pagerRendered = this._renderPagerComponent()),
@@ -157,8 +158,16 @@ class DiscreteLegend extends base_1.LegendBase {
157
158
  if (this.attribute.disableTriggerEvent) return;
158
159
  if (!this._itemsContainer) return;
159
160
  const {hover: hover = !0, select: select = !0} = this.attribute;
160
- hover && (this._itemsContainer.addEventListener("pointermove", this._onHover), this._itemsContainer.addEventListener("pointerleave", this._onUnHover)),
161
- select && this._itemsContainer.addEventListener("pointerdown", this._onClick);
161
+ if (hover) {
162
+ let trigger = "pointermove", triggerOff = "pointerleave";
163
+ (0, vutils_1.isObject)(hover) && (hover.trigger && (trigger = hover.trigger), hover.triggerOff && (triggerOff = hover.triggerOff)),
164
+ this._itemsContainer.addEventListener(trigger, this._onHover), this._itemsContainer.addEventListener(triggerOff, this._onUnHover);
165
+ }
166
+ if (select) {
167
+ let trigger = "pointerdown";
168
+ (0, vutils_1.isObject)(select) && select.trigger && (trigger = select.trigger),
169
+ this._itemsContainer.addEventListener(trigger, this._onClick);
170
+ }
162
171
  }
163
172
  _autoEllipsis(autoEllipsisStrategy, layoutWidth, labelShape, valueShape) {
164
173
  var _a, _b;
@@ -301,12 +310,12 @@ class DiscreteLegend extends base_1.LegendBase {
301
310
  direction: "horizontal",
302
311
  disableTriggerEvent: disableTriggerEvent,
303
312
  range: [ 0, .5 ],
304
- height: 12
313
+ height: !1 === compStyle.visible ? 0 : 12
305
314
  }, compStyle), {
306
315
  width: compSize
307
316
  })) : new scrollbar_1.ScrollBar(Object.assign(Object.assign({
308
317
  direction: "vertical",
309
- width: 12,
318
+ width: !1 === compStyle.visible ? 0 : 12,
310
319
  range: [ 0, .5 ]
311
320
  }, compStyle), {
312
321
  height: compSize,
@@ -331,9 +340,15 @@ class DiscreteLegend extends base_1.LegendBase {
331
340
  });
332
341
  }
333
342
  }
343
+ _computeScrollbarDelta() {
344
+ const {isHorizontal: isHorizontal, clipContainer: clipContainer} = this._itemContext, itemContainerBounds = this._itemsContainer.AABBBounds, clipContainerBounds = clipContainer.AABBBounds;
345
+ let delta, innerViewSize;
346
+ return isHorizontal ? (innerViewSize = clipContainerBounds.width(), delta = innerViewSize / itemContainerBounds.width()) : (innerViewSize = clipContainerBounds.height(),
347
+ delta = innerViewSize / itemContainerBounds.height()), delta;
348
+ }
334
349
  _updatePositionOfScrollbar(contentWidth, contentHeight, renderStartY) {
335
- const {currentPage: currentPage, totalPage: totalPage, isHorizontal: isHorizontal} = this._itemContext;
336
- this._pagerComponent.setScrollRange([ (currentPage - 1) / totalPage, currentPage / totalPage ]),
350
+ const {isHorizontal: isHorizontal, currentPage: currentPage, totalPage: totalPage} = this._itemContext, start = (currentPage - 1) / totalPage;
351
+ this._pagerComponent.setScrollRange([ start, start + this._computeScrollbarDelta() ]),
337
352
  isHorizontal ? this._pagerComponent.setAttributes({
338
353
  x: 0,
339
354
  y: renderStartY + contentHeight
@@ -346,20 +361,32 @@ class DiscreteLegend extends base_1.LegendBase {
346
361
  const pager = this.attribute.pager || {}, {animation: animation = !0, animationDuration: animationDuration = 450, animationEasing: animationEasing = "quadIn"} = pager, pageParser = this._itemContext.isScrollbar ? e => {
347
362
  const {value: value} = e.detail;
348
363
  let newPage;
349
- return 0 === value[0] ? newPage = 1 : 1 === value[1] ? newPage = this._itemContext.totalPage : (newPage = value[0] * this._itemContext.totalPage,
350
- pager.scrollByPosition ? newPage += 1 : newPage = Math.floor(newPage) + 1), newPage;
364
+ return newPage = 0 === value[0] ? 1 : 1 === value[1] ? this._itemContext.totalPage : value[0] * this._itemContext.totalPage + 1,
365
+ newPage;
351
366
  } : e => e.detail.current, onScroll = e => {
352
367
  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;
353
- scrollComponent.setScrollRange([ preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue ], !0);
368
+ scrollComponent.setScrollRange([ preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue ], !0),
369
+ this.updateScrollMask();
354
370
  }, onPaging = e => {
355
371
  const newPage = pageParser(e);
356
372
  if (newPage !== this._itemContext.currentPage) {
357
373
  if (this._itemContext.currentPage = newPage, this._itemContext && this._itemContext.startIndex < this._itemContext.items.length) {
358
374
  this._renderItems();
359
375
  const newTotalPage = Math.ceil(this._itemContext.pages / this._itemContext.maxPages);
360
- this._itemContext.totalPage = newTotalPage, this._pagerComponent.setScrollRange([ (newPage - 1) / newTotalPage, newPage / newTotalPage ]);
376
+ if (this._itemContext.totalPage = newTotalPage, this._itemContext.isScrollbar && this._pagerComponent) {
377
+ const newDelta = this._computeScrollbarDelta(), [start] = this._pagerComponent.getScrollRange();
378
+ this._pagerComponent.setScrollRange([ start, start + newDelta ]);
379
+ }
361
380
  }
362
- animation ? this._itemsContainer.animate().to({
381
+ if (this._itemContext.isScrollbar) {
382
+ const [start] = this._pagerComponent.getScrollRange();
383
+ let containerSize;
384
+ containerSize = this._itemContext.isHorizontal ? this._itemsContainer.AABBBounds.width() : this._itemsContainer.AABBBounds.height();
385
+ const startOffset = containerSize * start;
386
+ this.updateScrollMask(), animation ? this._itemsContainer.animate().to({
387
+ [channel]: -startOffset
388
+ }, animationDuration, animationEasing) : this._itemsContainer.setAttribute(channel, -startOffset);
389
+ } else animation ? this._itemsContainer.animate().to({
363
390
  [channel]: -(newPage - 1) * pageSize
364
391
  }, animationDuration, animationEasing) : this._itemsContainer.setAttribute(channel, -(newPage - 1) * pageSize);
365
392
  }
@@ -374,7 +401,7 @@ class DiscreteLegend extends base_1.LegendBase {
374
401
  } else this._pagerComponent.addEventListener("toPrev", onPaging), this._pagerComponent.addEventListener("toNext", onPaging);
375
402
  }
376
403
  _renderPager() {
377
- const renderStartY = this._title ? this._title.AABBBounds.height() + (0, vutils_1.get)(this.attribute, "title.space", 8) : 0, {maxWidth: maxWidth, maxHeight: maxHeight, maxCol: maxCol = 1, maxRow: maxRow = 2, item: item = {}, pager: pager = {}} = this.attribute, {spaceCol: spaceCol = constant_1.DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = constant_1.DEFAULT_ITEM_SPACE_ROW} = item, itemsContainer = this._itemsContainer, {space: pagerSpace = constant_1.DEFAULT_PAGER_SPACE, defaultCurrent: defaultCurrent = 1} = pager, compStyle = __rest(pager, [ "space", "defaultCurrent" ]), {isHorizontal: isHorizontal} = this._itemContext;
404
+ const renderStartY = this._title ? this._title.AABBBounds.height() + (0, vutils_1.get)(this.attribute, "title.space", 8) : 0, {maxWidth: maxWidth, maxCol: maxCol = 1, maxRow: maxRow = 2, item: item = {}, pager: pager = {}} = this.attribute, {spaceCol: spaceCol = constant_1.DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = constant_1.DEFAULT_ITEM_SPACE_ROW} = item, itemsContainer = this._itemsContainer, {space: pagerSpace = constant_1.DEFAULT_PAGER_SPACE, defaultCurrent: defaultCurrent = 1} = pager, compStyle = __rest(pager, [ "space", "defaultCurrent" ]), {isHorizontal: isHorizontal} = this._itemContext, maxHeight = this._contentMaxHeight;
378
405
  let comp, compWidth = 0, compHeight = 0, contentWidth = 0, contentHeight = 0, startX = 0, startY = 0, pages = 1;
379
406
  if (isHorizontal) {
380
407
  if (compHeight = (maxRow - 1) * spaceRow + this._itemHeight * maxRow, compWidth = maxWidth,
@@ -416,18 +443,20 @@ class DiscreteLegend extends base_1.LegendBase {
416
443
  clip: !0,
417
444
  pickable: !1
418
445
  });
419
- return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this._bindEventsOfPager(isHorizontal ? compHeight + spaceRow : compWidth + spaceCol, isHorizontal ? "y" : "x"),
446
+ return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this._itemContext.clipContainer = clipGroup,
447
+ this._bindEventsOfPager(isHorizontal ? compHeight + spaceRow : compWidth + spaceCol, isHorizontal ? "y" : "x"),
420
448
  !0;
421
449
  }
422
450
  _renderScrollbar() {
423
- const renderStartY = this._title ? this._title.AABBBounds.height() + (0, vutils_1.get)(this.attribute, "title.space", 8) : 0, {maxWidth: maxWidth, maxHeight: maxHeight, item: item = {}, pager: pager = {}} = this.attribute, {spaceCol: spaceCol = constant_1.DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = constant_1.DEFAULT_ITEM_SPACE_ROW} = item, itemsContainer = this._itemsContainer, {space: pagerSpace = constant_1.DEFAULT_PAGER_SPACE, defaultCurrent: defaultCurrent = 1} = pager, compStyle = __rest(pager, [ "space", "defaultCurrent" ]), {isHorizontal: isHorizontal} = this._itemContext;
424
- let comp, compSize = 0, contentWidth = 0, contentHeight = 0, startY = 0, pages = 1;
425
- if (isHorizontal) compSize = maxWidth, contentWidth = maxWidth, contentHeight = this._itemHeight,
426
- comp = this._createScrollbar(compStyle, compSize), this._pagerComponent = comp,
427
- this._innerView.add(comp), this._updatePositionOfScrollbar(contentWidth, contentHeight, renderStartY); else {
428
- if (compSize = maxHeight, comp = this._createScrollbar(compStyle, compSize), this._pagerComponent = comp,
429
- this._innerView.add(comp), contentHeight = maxHeight - renderStartY, contentWidth = this._itemMaxWidth,
430
- contentHeight <= 0) return this._innerView.removeChild(comp), !1;
451
+ var _a;
452
+ const renderStartY = this._title ? this._title.AABBBounds.height() + (0, vutils_1.get)(this.attribute, "title.space", 8) : 0, {maxWidth: maxWidth, item: item = {}, pager: pager = {}} = this.attribute, {spaceCol: spaceCol = constant_1.DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = constant_1.DEFAULT_ITEM_SPACE_ROW} = item, itemsContainer = this._itemsContainer, {space: pagerSpace = constant_1.DEFAULT_PAGER_SPACE, defaultCurrent: defaultCurrent = 1} = pager, compStyle = __rest(pager, [ "space", "defaultCurrent" ]), {isHorizontal: isHorizontal} = this._itemContext, maxHeight = this._contentMaxHeight;
453
+ let comp, contentWidth = 0, contentHeight = 0, startY = 0, pages = 1;
454
+ if (isHorizontal) contentWidth = maxWidth, contentHeight = this._itemHeight, comp = this._createScrollbar(compStyle, contentWidth),
455
+ this._pagerComponent = comp, this._innerView.add(comp); else {
456
+ if (contentHeight = maxHeight - renderStartY, contentWidth = this._itemMaxWidth,
457
+ comp = this._createScrollbar(compStyle, contentHeight), this._pagerComponent = comp,
458
+ this._innerView.add(comp), contentHeight <= 0) return this._innerView.removeChild(comp),
459
+ !1;
431
460
  const items = itemsContainer.getChildren(), itemsHeightArr = items.map((item => item.attribute.height));
432
461
  if (1 === itemsHeightArr.length || itemsHeightArr.every((entry => entry === itemsHeightArr[0]))) {
433
462
  const itemHeight = itemsHeightArr[0], maxContentHeight = contentHeight, pageItemsCount = Math.floor(maxContentHeight / (spaceRow + itemHeight));
@@ -438,9 +467,15 @@ class DiscreteLegend extends base_1.LegendBase {
438
467
  prePages !== pages && index === itemsContainer.getChildren().length - 1 && startY - contentHeight >= 1 / 3 * height && (contentHeight = preStartY + height,
439
468
  pages -= 1);
440
469
  }));
441
- this._itemContext.totalPage = pages, this._itemContext.pages = pages, this._updatePositionOfScrollbar(contentWidth, contentHeight, renderStartY);
470
+ this._itemContext.totalPage = pages, this._itemContext.pages = pages;
471
+ }
472
+ if (defaultCurrent > 1) if (isHorizontal) {
473
+ const maxOffset = this._itemsContainer.AABBBounds.width() - contentWidth;
474
+ itemsContainer.setAttribute("x", -Math.min((defaultCurrent - 1) * (contentWidth + spaceCol), maxOffset));
475
+ } else {
476
+ const maxOffset = this._itemsContainer.AABBBounds.height() - contentHeight;
477
+ itemsContainer.setAttribute("y", -Math.min((defaultCurrent - 1) * (contentHeight + spaceRow), maxOffset));
442
478
  }
443
- defaultCurrent > 1 && (isHorizontal ? itemsContainer.setAttribute("x", -(defaultCurrent - 1) * (contentWidth + spaceCol)) : itemsContainer.setAttribute("y", -(defaultCurrent - 1) * (contentHeight + spaceRow)));
444
479
  const clipGroup = vrender_core_1.graphicCreator.group({
445
480
  x: 0,
446
481
  y: renderStartY,
@@ -449,9 +484,57 @@ class DiscreteLegend extends base_1.LegendBase {
449
484
  clip: !0,
450
485
  pickable: !1
451
486
  });
452
- return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this._bindEventsOfPager(isHorizontal ? contentWidth : contentHeight, isHorizontal ? "x" : "y"),
487
+ return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this._itemContext.clipContainer = clipGroup,
488
+ this._updatePositionOfScrollbar(contentWidth, contentHeight, renderStartY), (null === (_a = pager.scrollMask) || void 0 === _a ? void 0 : _a.visible) && this.renderScrollMask(clipGroup),
489
+ this._bindEventsOfPager(isHorizontal ? contentWidth : contentHeight, isHorizontal ? "x" : "y"),
453
490
  !0;
454
491
  }
492
+ renderScrollMask(clipGroup) {
493
+ const {scrollMask: scrollMask = {}} = this.attribute.pager, {visible: visible = !0, gradientLength: gradientLength = 16, gradientStops: gradientStops} = scrollMask;
494
+ if (!visible || !gradientStops) return;
495
+ const width = clipGroup.AABBBounds.width(), height = clipGroup.AABBBounds.height(), totalLength = this._itemContext.isHorizontal ? width : height, startStops = gradientStops.map((stop => ({
496
+ offset: gradientLength * stop.offset / totalLength,
497
+ color: stop.color
498
+ }))), endStops = gradientStops.map((stop => ({
499
+ offset: (totalLength - gradientLength * stop.offset) / totalLength,
500
+ color: stop.color
501
+ }))), mask = vrender_core_1.graphicCreator.rect({
502
+ x: 0,
503
+ y: 0,
504
+ width: width,
505
+ height: height
506
+ });
507
+ this._scrollMask = mask, this._scrollMaskContext = {
508
+ startStops: startStops,
509
+ endStops: endStops
510
+ }, this.updateScrollMask(), clipGroup.add(mask);
511
+ }
512
+ updateScrollMask() {
513
+ if (!this._scrollMask || !this._pagerComponent) return;
514
+ if (!this._itemContext.isScrollbar) return;
515
+ const [start, end] = this._pagerComponent.getScrollRange(), stops = [];
516
+ (0, vutils_1.isNumberClose)((0, vutils_1.clamp)(end, 0, 1), 1) || stops.push(...this._scrollMaskContext.endStops),
517
+ (0, vutils_1.isNumberClose)((0, vutils_1.clamp)(start, 0, 1), 0) || stops.push(...this._scrollMaskContext.startStops),
518
+ stops.length && (this._itemContext.isHorizontal ? this._scrollMask.setAttributes({
519
+ fill: {
520
+ gradient: "linear",
521
+ x0: 0,
522
+ y0: 0,
523
+ x1: 1,
524
+ y1: 0,
525
+ stops: stops
526
+ }
527
+ }) : this._scrollMask.setAttributes({
528
+ fill: {
529
+ gradient: "linear",
530
+ x0: 0,
531
+ y0: 0,
532
+ x1: 0,
533
+ y1: 1,
534
+ stops: stops
535
+ }
536
+ }));
537
+ }
455
538
  _renderPagerComponent() {
456
539
  return this._itemContext.isScrollbar ? this._renderScrollbar() : this._renderPager(),
457
540
  !0;