@visactor/vrender-components 0.12.1 → 0.12.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.
Files changed (45) hide show
  1. package/cjs/axis/base.d.ts +5 -5
  2. package/cjs/axis/base.js +1 -2
  3. package/cjs/axis/base.js.map +1 -1
  4. package/cjs/axis/circle.d.ts +5 -5
  5. package/cjs/axis/circle.js +2 -2
  6. package/cjs/axis/circle.js.map +1 -1
  7. package/cjs/axis/line.d.ts +5 -6
  8. package/cjs/axis/line.js +3 -2
  9. package/cjs/axis/line.js.map +1 -1
  10. package/cjs/index.d.ts +1 -1
  11. package/cjs/index.js +1 -1
  12. package/cjs/index.js.map +1 -1
  13. package/cjs/legend/discrete/discrete.d.ts +1 -1
  14. package/cjs/legend/discrete/discrete.js +54 -41
  15. package/cjs/legend/discrete/discrete.js.map +1 -1
  16. package/cjs/pager/pager.d.ts +2 -2
  17. package/cjs/pager/pager.js +4 -2
  18. package/cjs/pager/pager.js.map +1 -1
  19. package/cjs/util/matrix.d.ts +5 -2
  20. package/cjs/util/matrix.js +24 -11
  21. package/cjs/util/matrix.js.map +1 -1
  22. package/dist/index.js +53 -147
  23. package/dist/index.min.js +1 -1
  24. package/es/axis/base.d.ts +5 -5
  25. package/es/axis/base.js +1 -2
  26. package/es/axis/base.js.map +1 -1
  27. package/es/axis/circle.d.ts +5 -5
  28. package/es/axis/circle.js +2 -3
  29. package/es/axis/circle.js.map +1 -1
  30. package/es/axis/line.d.ts +5 -6
  31. package/es/axis/line.js +3 -3
  32. package/es/axis/line.js.map +1 -1
  33. package/es/index.d.ts +1 -1
  34. package/es/index.js +1 -1
  35. package/es/index.js.map +1 -1
  36. package/es/legend/discrete/discrete.d.ts +1 -1
  37. package/es/legend/discrete/discrete.js +54 -41
  38. package/es/legend/discrete/discrete.js.map +1 -1
  39. package/es/pager/pager.d.ts +2 -2
  40. package/es/pager/pager.js +4 -2
  41. package/es/pager/pager.js.map +1 -1
  42. package/es/util/matrix.d.ts +5 -2
  43. package/es/util/matrix.js +19 -3
  44. package/es/util/matrix.js.map +1 -1
  45. package/package.json +5 -6
package/dist/index.js CHANGED
@@ -436,143 +436,28 @@
436
436
  return '#' + vutils.ColorUtil.rgbToHex(r, g, b);
437
437
  }
438
438
 
439
- /**
440
- * Common utilities
441
- * @module glMatrix
442
- */
443
- var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
444
- if (!Math.hypot) Math.hypot = function () {
445
- var y = 0,
446
- i = arguments.length;
447
- while (i--) {
448
- y += arguments[i] * arguments[i];
449
- }
450
- return Math.sqrt(y);
451
- };
452
-
453
- /**
454
- * 2 Dimensional Vector
455
- * @module vec2
456
- */
457
-
458
- /**
459
- * Creates a new, empty vec2
460
- *
461
- * @returns {vec2} a new 2D vector
462
- */
463
-
464
- function create() {
465
- var out = new ARRAY_TYPE(2);
466
- if (ARRAY_TYPE != Float32Array) {
467
- out[0] = 0;
468
- out[1] = 0;
469
- }
470
- return out;
439
+ function scale(vector, scale) {
440
+ return [vector[0] * scale, vector[1] * scale];
471
441
  }
472
- /**
473
- * Scales a vec2 by a scalar number
474
- *
475
- * @param {vec2} out the receiving vector
476
- * @param {ReadonlyVec2} a the vector to scale
477
- * @param {Number} b amount to scale the vector by
478
- * @returns {vec2} out
479
- */
480
-
481
- function scale(out, a, b) {
482
- out[0] = a[0] * b;
483
- out[1] = a[1] * b;
484
- return out;
485
- }
486
- /**
487
- * Calculates the length of a vec2
488
- *
489
- * @param {ReadonlyVec2} a vector to calculate length of
490
- * @returns {Number} length of a
491
- */
492
-
493
- function length(a) {
494
- var x = a[0],
495
- y = a[1];
496
- return Math.hypot(x, y);
442
+ function length(vector) {
443
+ const [x, y] = vector;
444
+ return Math.sqrt(x * x + y * y);
497
445
  }
498
- /**
499
- * Normalize a vec2
500
- *
501
- * @param {vec2} out the receiving vector
502
- * @param {ReadonlyVec2} a vector to normalize
503
- * @returns {vec2} out
504
- */
505
-
506
- function normalize(out, a) {
507
- var x = a[0],
508
- y = a[1];
509
- var len = x * x + y * y;
510
- if (len > 0) {
511
- //TODO: evaluate use of glm_invsqrt here?
512
- len = 1 / Math.sqrt(len);
513
- }
514
- out[0] = a[0] * len;
515
- out[1] = a[1] * len;
516
- return out;
446
+ function normalize(vector) {
447
+ const [x, y] = vector;
448
+ let len = x * x + y * y;
449
+ if (len > 0) {
450
+ len = 1 / Math.sqrt(len);
451
+ }
452
+ return [vector[0] * len, vector[1] * len];
517
453
  }
518
- /**
519
- * Get the angle between two 2D vectors
520
- * @param {ReadonlyVec2} a The first operand
521
- * @param {ReadonlyVec2} b The second operand
522
- * @returns {Number} The angle in radians
523
- */
524
-
525
- function angle(a, b) {
526
- var x1 = a[0],
527
- y1 = a[1],
528
- x2 = b[0],
529
- y2 = b[1],
530
- // mag is the product of the magnitudes of a and b
531
- mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),
532
- // mag &&.. short circuits if mag == 0
533
- cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1
534
-
535
- return Math.acos(Math.min(Math.max(cosine, -1), 1));
454
+ function angle(vector1, vector2) {
455
+ const [x1, y1] = vector1;
456
+ const [x2, y2] = vector2;
457
+ const mag = Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2));
458
+ const cosine = mag && (x1 * x2 + y1 * y2) / mag;
459
+ return Math.acos(Math.min(Math.max(cosine, -1), 1));
536
460
  }
537
- /**
538
- * Perform some operation over an array of vec2s.
539
- *
540
- * @param {Array} a the array of vectors to iterate over
541
- * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
542
- * @param {Number} offset Number of elements to skip at the beginning of the array
543
- * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
544
- * @param {Function} fn Function to call for each vector in the array
545
- * @param {Object} [arg] additional argument to pass to fn
546
- * @returns {Array} a
547
- * @function
548
- */
549
-
550
- (function () {
551
- var vec = create();
552
- return function (a, stride, offset, count, fn, arg) {
553
- var i, l;
554
- if (!stride) {
555
- stride = 2;
556
- }
557
- if (!offset) {
558
- offset = 0;
559
- }
560
- if (count) {
561
- l = Math.min(count * stride + offset, a.length);
562
- } else {
563
- l = a.length;
564
- }
565
- for (i = offset; i < l; i += stride) {
566
- vec[0] = a[i];
567
- vec[1] = a[i + 1];
568
- fn(vec, vec, arg);
569
- a[i] = vec[0];
570
- a[i + 1] = vec[1];
571
- }
572
- return a;
573
- };
574
- })();
575
-
576
461
  function direction(v1, v2) {
577
462
  return v1[0] * v2[1] - v2[0] * v1[1];
578
463
  }
@@ -2525,11 +2410,11 @@
2525
2410
  container.add(axisTitle);
2526
2411
  }
2527
2412
  renderGrid(container) {
2528
- this._renderGridByType('grid', container);
2529
2413
  const { visible } = this.attribute.subGrid || {};
2530
2414
  if (visible) {
2531
2415
  this._renderGridByType('subGrid', container);
2532
2416
  }
2417
+ this._renderGridByType('grid', container);
2533
2418
  }
2534
2419
  getVerticalCoord(point, offset, inside) {
2535
2420
  const vector = this.getVerticalVector(offset, inside, point);
@@ -2773,9 +2658,9 @@
2773
2658
  getVerticalVector(offset, inside = false) {
2774
2659
  const { verticalFactor = 1 } = this.attribute;
2775
2660
  const axisVector = this.getRelativeVector();
2776
- const normalize$1 = normalize([0, 0], axisVector);
2777
- const verticalVector = [normalize$1[1], normalize$1[0] * -1];
2778
- return scale([0, 0], verticalVector, offset * (inside ? 1 : -1) * verticalFactor);
2661
+ const normalizedAxisVector = normalize(axisVector);
2662
+ const verticalVector = [normalizedAxisVector[1], normalizedAxisVector[0] * -1];
2663
+ return scale(verticalVector, offset * (inside ? 1 : -1) * verticalFactor);
2779
2664
  }
2780
2665
  getTitleAttribute() {
2781
2666
  const { position = 'middle', space = 4, textStyle = {}, autoRotate = true, shape, background, state, ...restAttrs } = this.attribute.title;
@@ -3072,8 +2957,7 @@
3072
2957
  const { inside: axisInside = false } = this.attribute;
3073
2958
  const { center } = this.attribute;
3074
2959
  const vector = [point.x - center.x, point.y - center.y];
3075
- scale(vector, vector, ((inside ? -1 : 1) * (axisInside ? -1 : 1) * offset) / length(vector));
3076
- return vector;
2960
+ return scale(vector, ((inside ? -1 : 1) * (axisInside ? -1 : 1) * offset) / length(vector));
3077
2961
  }
3078
2962
  getRelativeVector(point) {
3079
2963
  const { center } = this.attribute;
@@ -4930,6 +4814,7 @@
4930
4814
  }
4931
4815
  const preHandler = vrender.createSymbol({
4932
4816
  strokeBoundsBuffer: 0,
4817
+ pickMode: 'imprecise',
4933
4818
  ...handlerStyle,
4934
4819
  x: 0,
4935
4820
  y: 0,
@@ -4960,6 +4845,7 @@
4960
4845
  container.add(text);
4961
4846
  const nextHandler = vrender.createSymbol({
4962
4847
  strokeBoundsBuffer: 0,
4848
+ pickMode: 'imprecise',
4963
4849
  ...handlerStyle,
4964
4850
  x: isHorizontal ? handlerSizeX + handlerSpace * 2 + maxTextWidth : 0,
4965
4851
  y: isHorizontal ? 0 : handlerSizeY + handlerSpace * 2 + maxTextHeight,
@@ -5343,11 +5229,21 @@
5343
5229
  this._itemMaxWidth = Math.max(itemWidth, this._itemMaxWidth);
5344
5230
  if (isHorizontal) {
5345
5231
  maxPages = maxRow;
5346
- if (vutils.isValid(maxWidth) && maxWidth < startX + itemWidth) {
5347
- doWrap = true;
5348
- startX = 0;
5349
- startY += itemHeight + spaceRow;
5350
- pages += 1;
5232
+ if (vutils.isValid(maxWidth)) {
5233
+ if (itemWidth >= maxWidth) {
5234
+ doWrap = true;
5235
+ if (index > 0) {
5236
+ startX = 0;
5237
+ startY += itemHeight + spaceRow;
5238
+ pages += 1;
5239
+ }
5240
+ }
5241
+ else if (maxWidth < startX + itemWidth) {
5242
+ doWrap = true;
5243
+ startX = 0;
5244
+ startY += itemHeight + spaceRow;
5245
+ pages += 1;
5246
+ }
5351
5247
  }
5352
5248
  if (index > 0) {
5353
5249
  itemGroup.setAttributes({
@@ -5376,10 +5272,11 @@
5376
5272
  }
5377
5273
  itemsContainer.add(itemGroup);
5378
5274
  });
5275
+ let pagerRendered = false;
5379
5276
  if (doWrap && autoPage && pages > maxPages) {
5380
- this._renderPager(isHorizontal);
5277
+ pagerRendered = this._renderPager(isHorizontal);
5381
5278
  }
5382
- else {
5279
+ if (!pagerRendered) {
5383
5280
  itemsContainer.setAttribute('y', this._title ? this._title.AABBBounds.height() + vutils.get(this.attribute, 'title.space', 8) : 0);
5384
5281
  this._innerView.add(itemsContainer);
5385
5282
  }
@@ -5555,6 +5452,10 @@
5555
5452
  this._innerView.add(pagerComp);
5556
5453
  pageHeight = (maxRow - 1) * spaceRow + this._itemHeight * maxRow;
5557
5454
  pageWidth = maxWidth - pagerComp.AABBBounds.width() - pagerSpace;
5455
+ if (pageWidth <= 0) {
5456
+ this._innerView.removeChild(pagerComp);
5457
+ return false;
5458
+ }
5558
5459
  itemsContainer.getChildren().forEach((item, index) => {
5559
5460
  const { width, height } = item.attribute;
5560
5461
  if (pageWidth < startX + width) {
@@ -5586,6 +5487,10 @@
5586
5487
  this._innerView.add(pagerComp);
5587
5488
  pageWidth = this._itemMaxWidth * maxCol + (maxCol - 1) * spaceCol;
5588
5489
  pageHeight = maxHeight - pagerComp.AABBBounds.height() - pagerSpace - renderStartY;
5490
+ if (pageHeight <= 0) {
5491
+ this._innerView.removeChild(pagerComp);
5492
+ return false;
5493
+ }
5589
5494
  itemsContainer.getChildren().forEach((item, index) => {
5590
5495
  const { height } = item.attribute;
5591
5496
  if (pageHeight < startY + height) {
@@ -5645,6 +5550,7 @@
5645
5550
  };
5646
5551
  this._pager.addEventListener('toPrev', onPaging);
5647
5552
  this._pager.addEventListener('toNext', onPaging);
5553
+ return true;
5648
5554
  }
5649
5555
  _onHover = (e) => {
5650
5556
  const target = e.target;
@@ -8718,7 +8624,7 @@
8718
8624
  }
8719
8625
  }
8720
8626
 
8721
- const version = "0.12.1";
8627
+ const version = "0.12.2";
8722
8628
 
8723
8629
  exports.AbstractComponent = AbstractComponent;
8724
8630
  exports.BasePlayer = BasePlayer;