@visactor/vchart-extension 1.13.5-alpha.1 → 1.13.5-alpha.10

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 (43) hide show
  1. package/build/index.js +701 -23
  2. package/build/index.min.js +2 -2
  3. package/cjs/charts/ranking-list/constant.d.ts +2 -0
  4. package/cjs/charts/ranking-list/constant.js +65 -0
  5. package/cjs/charts/ranking-list/constant.js.map +1 -0
  6. package/cjs/charts/ranking-list/interface.d.ts +65 -0
  7. package/cjs/charts/ranking-list/interface.js +6 -0
  8. package/cjs/charts/ranking-list/interface.js.map +1 -0
  9. package/cjs/charts/ranking-list/ranking-list-transformer.d.ts +482 -0
  10. package/cjs/charts/ranking-list/ranking-list-transformer.js +376 -0
  11. package/cjs/charts/ranking-list/ranking-list-transformer.js.map +1 -0
  12. package/cjs/charts/ranking-list/ranking-list.d.ts +16 -0
  13. package/cjs/charts/ranking-list/ranking-list.js +34 -0
  14. package/cjs/charts/ranking-list/ranking-list.js.map +1 -0
  15. package/cjs/charts/ranking-list/utils.d.ts +7 -0
  16. package/cjs/charts/ranking-list/utils.js +51 -0
  17. package/cjs/charts/ranking-list/utils.js.map +1 -0
  18. package/cjs/components/bar-link/index.js +2 -1
  19. package/cjs/components/series-label/type.js +1 -2
  20. package/cjs/index.d.ts +1 -0
  21. package/cjs/index.js +3 -3
  22. package/cjs/index.js.map +1 -1
  23. package/esm/charts/ranking-list/constant.d.ts +2 -0
  24. package/esm/charts/ranking-list/constant.js +61 -0
  25. package/esm/charts/ranking-list/constant.js.map +1 -0
  26. package/esm/charts/ranking-list/interface.d.ts +65 -0
  27. package/esm/charts/ranking-list/interface.js +2 -0
  28. package/esm/charts/ranking-list/interface.js.map +1 -0
  29. package/esm/charts/ranking-list/ranking-list-transformer.d.ts +482 -0
  30. package/esm/charts/ranking-list/ranking-list-transformer.js +376 -0
  31. package/esm/charts/ranking-list/ranking-list-transformer.js.map +1 -0
  32. package/esm/charts/ranking-list/ranking-list.d.ts +16 -0
  33. package/esm/charts/ranking-list/ranking-list.js +27 -0
  34. package/esm/charts/ranking-list/ranking-list.js.map +1 -0
  35. package/esm/charts/ranking-list/utils.d.ts +7 -0
  36. package/esm/charts/ranking-list/utils.js +41 -0
  37. package/esm/charts/ranking-list/utils.js.map +1 -0
  38. package/esm/components/bar-link/index.js +2 -1
  39. package/esm/components/series-label/type.js +1 -2
  40. package/esm/index.d.ts +1 -0
  41. package/esm/index.js +2 -0
  42. package/esm/index.js.map +1 -1
  43. package/package.json +9 -8
package/build/index.js CHANGED
@@ -338,6 +338,673 @@
338
338
  }
339
339
  };
340
340
 
341
+ const defaultSpec = {
342
+ width: 400,
343
+ height: 225,
344
+ labelLayout: 'top',
345
+ bar: {
346
+ height: 100,
347
+ style: {
348
+ cornerRadius: 5
349
+ }
350
+ },
351
+ barBackground: {
352
+ type: 'rect',
353
+ style: {
354
+ fill: 'rgba(255,255,255,0.1)',
355
+ cornerRadius: 5
356
+ }
357
+ },
358
+ rankingIcon: {
359
+ visible: true,
360
+ style: {
361
+ fill: 'rgba(253,253,253,0.5)',
362
+ size: 12
363
+ }
364
+ },
365
+ nameLabel: {
366
+ visible: true,
367
+ style: {
368
+ fontSize: 20,
369
+ fontWeight: 'normal',
370
+ fill: 'rgba(255,255,255,0.7)',
371
+ textBaseline: 'middle'
372
+ }
373
+ },
374
+ orderLabel: {
375
+ visible: true,
376
+ style: {
377
+ fontSize: 20,
378
+ fontWeight: 'normal',
379
+ fill: 'rgba(255,255,255,0.7)',
380
+ textBaseline: 'middle'
381
+ }
382
+ },
383
+ valueLabel: {
384
+ visible: true,
385
+ style: {
386
+ fontSize: 14,
387
+ fontWeight: 'normal',
388
+ fill: 'rgba(255,255,255,1)',
389
+ textBaseline: 'middle'
390
+ }
391
+ },
392
+ pageSize: 5,
393
+ scrollSize: 1,
394
+ animation: {
395
+ type: 'both',
396
+ interval: 4000,
397
+ duration: 2000,
398
+ easing: 'linear'
399
+ }
400
+ };
401
+
402
+ const applyVisible = (spec, keyList) => {
403
+ keyList.forEach(key => {
404
+ var _a, _b, _c, _d, _e, _f;
405
+ if (vutils.isArray(spec[key])) {
406
+ spec[key].forEach((s, i) => {
407
+ var _a, _b, _c;
408
+ spec[key][i] = Object.assign(Object.assign({}, s), { style: Object.assign(Object.assign({}, s === null || s === void 0 ? void 0 : s.style), { visible: (_c = (_b = (_a = s === null || s === void 0 ? void 0 : s.style) === null || _a === void 0 ? void 0 : _a.visible) !== null && _b !== void 0 ? _b : s === null || s === void 0 ? void 0 : s.visible) !== null && _c !== void 0 ? _c : true }) });
409
+ });
410
+ }
411
+ else {
412
+ spec[key] = Object.assign(Object.assign({}, spec[key]), { style: Object.assign(Object.assign({}, (_a = spec[key]) === null || _a === void 0 ? void 0 : _a.style), { visible: (_f = (_d = (_c = (_b = spec[key]) === null || _b === void 0 ? void 0 : _b.style) === null || _c === void 0 ? void 0 : _c.visible) !== null && _d !== void 0 ? _d : (_e = spec[key]) === null || _e === void 0 ? void 0 : _e.visible) !== null && _f !== void 0 ? _f : true }) });
413
+ }
414
+ });
415
+ };
416
+ const mergeObjects = (objA, objB) => {
417
+ function recursiveMerge(target, source) {
418
+ for (const key in source) {
419
+ if (typeof source[key] === 'object' && source[key] !== null) {
420
+ if (!target.hasOwnProperty(key)) {
421
+ target[key] = Array.isArray(source[key]) ? [] : {};
422
+ }
423
+ recursiveMerge(target[key], source[key]);
424
+ }
425
+ else if (!target.hasOwnProperty(key) && typeof target === 'object') {
426
+ target[key] = source[key];
427
+ }
428
+ }
429
+ return target;
430
+ }
431
+ return recursiveMerge(objA, objB);
432
+ };
433
+ const computeDataRange = (data, field) => {
434
+ let dataMin, dataMax;
435
+ const datumX = data.map(d => d[field]).filter(d => typeof d !== 'undefined' && d !== null);
436
+ if (datumX.length === 0) {
437
+ dataMin = 0;
438
+ dataMax = 1;
439
+ }
440
+ else {
441
+ dataMin = Math.min(...datumX) - (Math.max(...datumX) - Math.min(...datumX)) / 3;
442
+ dataMax = (Math.max(...datumX) - dataMin) / 0.8 + dataMin;
443
+ const delta_value = 10;
444
+ const data = dataMin;
445
+ if (dataMin === dataMax) {
446
+ dataMin = data - delta_value;
447
+ dataMax = (4 * data + delta_value) / 4;
448
+ }
449
+ }
450
+ return { min: dataMin, max: dataMax };
451
+ };
452
+
453
+ const DATA_KEY = 'dataKey';
454
+ const ORDER_KEY = 'VCHART_ORDER';
455
+ const SUPPLY_DATA_KEY = 'SUPPLY_DATA_KEY';
456
+ const NAME_LABEL_PADDING_RIGHT = 10;
457
+ const NAME_ORDER_PADDING_RIGHT = 5;
458
+ const NAME_SYMBOL_PADDING_RIGHT = 8;
459
+ const CHART_PADDING_LEFT = 5;
460
+ const CHART_PADDING_RIGHT = 5;
461
+ const VALUE_LABEL_PADDING_LEFT = 5;
462
+ const LABEL_PADDING_BOTTOM = 5;
463
+ class RankingListChartSpecTransformer extends vchart.CommonChartSpecTransformer {
464
+ constructor() {
465
+ super(...arguments);
466
+ this.formatMap = {};
467
+ this.paginateDataArr = (spec) => {
468
+ const { data: arr, scrollSize = 1, pageSize = 5 } = spec;
469
+ const result = {};
470
+ let pageOrder = 0;
471
+ for (let i = 0; i < arr.length; i += scrollSize) {
472
+ pageOrder++;
473
+ result[`page${pageOrder}`] = arr.slice(i, i + pageSize);
474
+ if (i + pageSize - 1 >= arr.length - 1) {
475
+ arr.push(...Array.from({ length: i + pageSize - arr.length }, _ => {
476
+ return {
477
+ [spec.yField]: Math.random() * 100,
478
+ [spec.xField]: null,
479
+ [SUPPLY_DATA_KEY]: true
480
+ };
481
+ }));
482
+ break;
483
+ }
484
+ }
485
+ return {
486
+ orderCount: pageOrder,
487
+ result: result
488
+ };
489
+ };
490
+ this.processRankingData = (spec) => {
491
+ const result = [];
492
+ spec.data.forEach((datum, index) => (datum[ORDER_KEY] = index + 1 < 10 ? `0${index + 1}` : index + 1));
493
+ const pagerData = this.paginateDataArr(spec).result;
494
+ const orderCount = this.paginateDataArr(spec).orderCount;
495
+ const supplyCount = spec.pageSize - pagerData[`page${orderCount}`].length;
496
+ pagerData[`page${orderCount}`].push(...Array.from({ length: supplyCount }, _ => {
497
+ return {
498
+ [spec.yField]: Math.random() * 100,
499
+ [spec.xField]: null,
500
+ [SUPPLY_DATA_KEY]: true
501
+ };
502
+ }));
503
+ Object.keys(pagerData).forEach(order => {
504
+ result.push({
505
+ data: [
506
+ {
507
+ id: 'datas',
508
+ values: pagerData[order].map((d, i) => {
509
+ return Object.assign(Object.assign({}, d), { [DATA_KEY]: order + '_' + i + '_' + new Date().getTime() });
510
+ })
511
+ },
512
+ {
513
+ id: 'order',
514
+ values: [
515
+ {
516
+ order
517
+ }
518
+ ]
519
+ }
520
+ ]
521
+ });
522
+ });
523
+ if (result.length === 1) {
524
+ result.push({
525
+ data: [
526
+ {
527
+ id: 'datas',
528
+ values: pagerData['page1'].map((d, i) => {
529
+ return Object.assign(Object.assign({}, d), { [DATA_KEY]: 'page2' + '_' + i + '_' + new Date().getTime() });
530
+ })
531
+ },
532
+ {
533
+ id: 'order',
534
+ values: [
535
+ {
536
+ order: 'page2'
537
+ }
538
+ ]
539
+ }
540
+ ]
541
+ });
542
+ }
543
+ return result;
544
+ };
545
+ }
546
+ isSpecValid(spec) {
547
+ var _a, _b, _c, _d;
548
+ const { xField, yField, data } = spec;
549
+ if (!xField || !yField) {
550
+ (_b = (_a = this._option).onError) === null || _b === void 0 ? void 0 : _b.call(_a, 'Missing Required Config: `xField`, `yField` ');
551
+ return false;
552
+ }
553
+ if (!data || data.length === 0) {
554
+ (_d = (_c = this._option).onError) === null || _d === void 0 ? void 0 : _d.call(_c, 'Data is required');
555
+ return false;
556
+ }
557
+ return true;
558
+ }
559
+ transformSpec(spec) {
560
+ var _a;
561
+ super.transformSpec(spec);
562
+ if (!this.isSpecValid(spec)) {
563
+ return;
564
+ }
565
+ this.normalizeSpec(spec);
566
+ this.upgradeTextMeasure(spec);
567
+ this.upgradeFormatMap(spec);
568
+ this.processData(spec);
569
+ this.transformBaseSpec(spec);
570
+ this.transformAnimationSpec(spec);
571
+ this.transformAxesSpec(spec);
572
+ spec.extensionMark = [
573
+ this.generateBarBackground(spec),
574
+ ...this.generateDecorateHaloIcons(spec),
575
+ this.generateRankingIcon(spec),
576
+ this.generateNameLabel(spec),
577
+ this.generateOrderLabel(spec),
578
+ this.generateValueLabel(spec)
579
+ ];
580
+ this.transformPaddingSpec(spec);
581
+ (_a = spec.customTransformSpec) === null || _a === void 0 ? void 0 : _a.call(spec, spec);
582
+ super.transformSpec(spec);
583
+ }
584
+ normalizeSpec(spec) {
585
+ mergeObjects(spec, defaultSpec);
586
+ applyVisible(spec, [
587
+ 'barBackground',
588
+ 'rankingIcon',
589
+ 'decorateHaloIcons',
590
+ 'orderLabel',
591
+ 'nameLabel',
592
+ 'valueLabel'
593
+ ]);
594
+ }
595
+ upgradeTextMeasure(spec) {
596
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
597
+ (_a = this.nameLabelTextMeasure) === null || _a === void 0 ? void 0 : _a.release();
598
+ (_b = this.valueLabelTextMeasure) === null || _b === void 0 ? void 0 : _b.release();
599
+ (_c = this.orderLabelTextMeasure) === null || _c === void 0 ? void 0 : _c.release();
600
+ this.nameLabelTextMeasure = new vutils.TextMeasure({
601
+ defaultFontParams: (_e = (_d = spec.nameLabel) === null || _d === void 0 ? void 0 : _d.style) !== null && _e !== void 0 ? _e : {}
602
+ });
603
+ this.valueLabelTextMeasure = new vutils.TextMeasure({
604
+ defaultFontParams: (_g = (_f = spec.valueLabel) === null || _f === void 0 ? void 0 : _f.style) !== null && _g !== void 0 ? _g : {}
605
+ });
606
+ this.orderLabelTextMeasure = new vutils.TextMeasure({
607
+ defaultFontParams: (_j = (_h = spec.orderLabel) === null || _h === void 0 ? void 0 : _h.style) !== null && _j !== void 0 ? _j : {}
608
+ });
609
+ }
610
+ upgradeFormatMap(spec) {
611
+ this.formatMap[spec.yField] = spec.nameLabel.formatMethod;
612
+ this.formatMap[spec.xField] = spec.valueLabel.formatMethod;
613
+ this.formatMap[ORDER_KEY] = spec.orderLabel.formatMethod;
614
+ }
615
+ processData(spec) {
616
+ var _a;
617
+ if (!((_a = spec.data[0]) === null || _a === void 0 ? void 0 : _a.values)) {
618
+ this.dataSpecs = this.processRankingData(spec);
619
+ this.originalData = spec.data;
620
+ spec.data = this.dataSpecs[0].data;
621
+ }
622
+ }
623
+ transformBaseSpec(spec) {
624
+ var _a, _b, _c;
625
+ spec.type = 'common';
626
+ spec.dataKey = DATA_KEY;
627
+ spec.series = [
628
+ {
629
+ type: 'bar',
630
+ direction: 'horizontal',
631
+ xField: spec.xField,
632
+ yField: spec.yField,
633
+ barWidth: (_b = (_a = spec.bar) === null || _a === void 0 ? void 0 : _a.height) !== null && _b !== void 0 ? _b : 10,
634
+ bar: Object.assign(Object.assign({}, spec.bar), { style: Object.assign(Object.assign({}, (_c = spec.bar) === null || _c === void 0 ? void 0 : _c.style), { x1: 0, visible: (datum) => {
635
+ var _a, _b;
636
+ if (datum[SUPPLY_DATA_KEY]) {
637
+ return false;
638
+ }
639
+ return (_b = (_a = spec.bar) === null || _a === void 0 ? void 0 : _a.style) !== null && _b !== void 0 ? _b : true;
640
+ } }) })
641
+ }
642
+ ];
643
+ }
644
+ transformAnimationSpec(spec) {
645
+ const totalDuration = spec.animation.duration;
646
+ if (spec.animation) {
647
+ spec.player = Object.assign(Object.assign({}, spec.player), { specs: this.dataSpecs, auto: true, visible: false, interval: spec.animation.interval + spec.animation.duration / 2, loop: true });
648
+ spec.animationExit = this.getAnimationExit(spec, totalDuration);
649
+ spec.animationAppear = this.getAnimationEnter(spec, 'rect', totalDuration);
650
+ spec.animationEnter = this.getAnimationEnter(spec, 'rect', totalDuration);
651
+ }
652
+ }
653
+ transformAxesSpec(spec) {
654
+ const { min, max } = computeDataRange(this.originalData, spec.xField);
655
+ spec.axes = [
656
+ {
657
+ orient: 'left',
658
+ type: 'band',
659
+ visible: false,
660
+ inverse: true
661
+ },
662
+ {
663
+ orient: 'bottom',
664
+ label: { visible: true },
665
+ type: 'linear',
666
+ visible: false,
667
+ min,
668
+ max
669
+ }
670
+ ];
671
+ }
672
+ generateBarBackground(spec) {
673
+ var _a;
674
+ const totalDuration = spec.animation.duration;
675
+ return {
676
+ type: spec.barBackground.type,
677
+ dataId: 'data',
678
+ visible: true,
679
+ dataKey: DATA_KEY,
680
+ zIndex: -99,
681
+ state: (_a = spec.barBackground) === null || _a === void 0 ? void 0 : _a.state,
682
+ style: Object.assign(Object.assign({ x: (datum, ctx) => spec.barBackground.type === 'symbol' ? ctx.getRegion().getLayoutRect().width / 2 : 0, y: (datum, ctx) => {
683
+ return (ctx.valueToY([datum[spec.yField]]) +
684
+ ctx.yBandwidth() / 2 -
685
+ (spec.barBackground.type === 'symbol' ? 0 : spec.bar.height / 2));
686
+ }, size: (datum, ctx) => [ctx.getRegion().getLayoutRect().width, spec.bar.height], width: (datum, ctx) => ctx.getRegion().getLayoutRect().width, height: spec.bar.height }, spec.barBackground.style), { visible: (datum) => {
687
+ if (datum[SUPPLY_DATA_KEY]) {
688
+ return false;
689
+ }
690
+ return spec.barBackground.style.visible;
691
+ } }),
692
+ animation: Boolean(spec.animation),
693
+ animationEnter: this.getAnimationEnter(spec, 'barBack', totalDuration),
694
+ animationExit: this.getAnimationExit(spec, totalDuration),
695
+ animationAppear: this.getAnimationEnter(spec, 'barBack', totalDuration)
696
+ };
697
+ }
698
+ generateDecorateHaloIcons(spec) {
699
+ var _a;
700
+ const totalDuration = spec.animation.duration;
701
+ return (_a = spec.decorateHaloIcons) === null || _a === void 0 ? void 0 : _a.map((decorateHaloIcon) => {
702
+ return {
703
+ type: 'symbol',
704
+ dataId: 'data',
705
+ visible: true,
706
+ dataKey: DATA_KEY,
707
+ state: decorateHaloIcon === null || decorateHaloIcon === void 0 ? void 0 : decorateHaloIcon.state,
708
+ style: Object.assign(Object.assign({ x: (datum, ctx) => {
709
+ if (datum[spec.xField] === undefined || datum[spec.xField] === null) {
710
+ return undefined;
711
+ }
712
+ return ctx.valueToX([datum[spec.xField]]);
713
+ }, y: (datum, ctx) => {
714
+ return ctx.valueToY([datum[spec.yField]]) + ctx.yBandwidth() / 2;
715
+ } }, decorateHaloIcon.style), { visible: (datum) => {
716
+ if (datum[SUPPLY_DATA_KEY]) {
717
+ return false;
718
+ }
719
+ return decorateHaloIcon.style.visible;
720
+ } }),
721
+ animation: Boolean(spec.animation),
722
+ animationEnter: this.getAnimationEnter(spec, 'symbol', totalDuration),
723
+ animationExit: this.getAnimationExit(spec, totalDuration),
724
+ animationAppear: this.getAnimationEnter(spec, 'symbol', totalDuration)
725
+ };
726
+ });
727
+ }
728
+ generateRankingIcon(spec) {
729
+ const totalDuration = spec.animation.duration;
730
+ return {
731
+ type: 'symbol',
732
+ dataId: 'data',
733
+ visible: true,
734
+ dataKey: DATA_KEY,
735
+ state: spec.rankingIcon.state,
736
+ style: Object.assign(Object.assign({ x: (datum) => {
737
+ if (spec.labelLayout === 'bothEnd') {
738
+ return -(NAME_LABEL_PADDING_RIGHT +
739
+ this.nameLabelTextMeasure.fullMeasure(this.formatDatum(spec.yField, datum)).width +
740
+ (spec.orderLabel.style.visible
741
+ ? NAME_ORDER_PADDING_RIGHT +
742
+ this.orderLabelTextMeasure.fullMeasure(this.formatDatum(ORDER_KEY, datum)).width
743
+ : 0) +
744
+ NAME_SYMBOL_PADDING_RIGHT);
745
+ }
746
+ return CHART_PADDING_LEFT;
747
+ }, y: (datum, ctx) => {
748
+ if (spec.labelLayout === 'bothEnd') {
749
+ return ctx.valueToY([datum[spec.yField]]) + ctx.yBandwidth() / 2;
750
+ }
751
+ return (ctx.valueToY([datum[spec.yField]]) +
752
+ ctx.yBandwidth() / 2 -
753
+ spec.bar.height / 2 -
754
+ LABEL_PADDING_BOTTOM -
755
+ Math.max(this.nameLabelTextMeasure.fullMeasure(this.formatDatum(spec.yField, datum)).height, this.orderLabelTextMeasure.fullMeasure(this.formatDatum(ORDER_KEY, datum)).height) /
756
+ 2);
757
+ } }, spec.rankingIcon.style), { lineWidth: 0, stroke: null, visible: (datum) => {
758
+ if (datum[SUPPLY_DATA_KEY]) {
759
+ return false;
760
+ }
761
+ return spec.rankingIcon.style.visible;
762
+ } }),
763
+ animation: Boolean(spec.animation),
764
+ animationEnter: this.getAnimationEnter(spec, 'text', totalDuration),
765
+ animationExit: this.getAnimationExit(spec, totalDuration),
766
+ animationAppear: this.getAnimationEnter(spec, 'text', totalDuration)
767
+ };
768
+ }
769
+ generateNameLabel(spec) {
770
+ var _a;
771
+ const totalDuration = spec.animation.duration;
772
+ return {
773
+ type: 'text',
774
+ dataId: 'data',
775
+ dataKey: DATA_KEY,
776
+ state: (_a = spec.nameLabel) === null || _a === void 0 ? void 0 : _a.state,
777
+ style: Object.assign(Object.assign({ text: (datum) => this.formatDatum(spec.yField, datum), x: () => {
778
+ var _a;
779
+ if (spec.labelLayout === 'bothEnd') {
780
+ return -NAME_LABEL_PADDING_RIGHT;
781
+ }
782
+ return ((spec.rankingIcon.style.visible ? NAME_SYMBOL_PADDING_RIGHT + ((_a = spec.rankingIcon.style.size) !== null && _a !== void 0 ? _a : 10) : 0) +
783
+ (spec.orderLabel.style.visible
784
+ ? NAME_ORDER_PADDING_RIGHT + this.getMaxDataLabelLens(spec, ORDER_KEY, this.orderLabelTextMeasure)
785
+ : 0));
786
+ }, y: (datum, ctx) => {
787
+ if (spec.labelLayout === 'bothEnd') {
788
+ return ctx.valueToY([datum[spec.yField]]) + ctx.yBandwidth() / 2;
789
+ }
790
+ return ctx.valueToY([datum[spec.yField]]) + ctx.yBandwidth() / 2 - spec.bar.height / 2 - LABEL_PADDING_BOTTOM;
791
+ } }, spec.nameLabel.style), { textAlign: spec.labelLayout === 'bothEnd' ? 'right' : 'left', textBaseline: spec.labelLayout === 'bothEnd' ? 'middle' : 'bottom', visible: (datum) => {
792
+ if (datum[SUPPLY_DATA_KEY]) {
793
+ return false;
794
+ }
795
+ return spec.nameLabel.style.visible;
796
+ } }),
797
+ animation: Boolean(spec.animation),
798
+ animationEnter: this.getAnimationEnter(spec, 'text', totalDuration),
799
+ animationExit: this.getAnimationExit(spec, totalDuration),
800
+ animationAppear: this.getAnimationEnter(spec, 'text', totalDuration)
801
+ };
802
+ }
803
+ generateOrderLabel(spec) {
804
+ var _a;
805
+ const totalDuration = spec.animation.duration;
806
+ return {
807
+ type: 'text',
808
+ dataId: 'data',
809
+ dataKey: DATA_KEY,
810
+ state: (_a = spec.orderLabel) === null || _a === void 0 ? void 0 : _a.state,
811
+ style: Object.assign(Object.assign({ text: (datum) => this.formatDatum(ORDER_KEY, datum), x: (datum) => {
812
+ var _a;
813
+ if (spec.labelLayout === 'bothEnd') {
814
+ return -(NAME_LABEL_PADDING_RIGHT +
815
+ this.nameLabelTextMeasure.fullMeasure(this.formatDatum(spec.yField, datum)).width +
816
+ NAME_ORDER_PADDING_RIGHT);
817
+ }
818
+ else {
819
+ return spec.rankingIcon.style.visible ? NAME_SYMBOL_PADDING_RIGHT + ((_a = spec.rankingIcon.style.size) !== null && _a !== void 0 ? _a : 10) : 0;
820
+ }
821
+ }, y: (datum, ctx) => {
822
+ if (spec.labelLayout === 'bothEnd') {
823
+ return ctx.valueToY([datum[spec.yField]]) + ctx.yBandwidth() / 2;
824
+ }
825
+ return ctx.valueToY([datum[spec.yField]]) + ctx.yBandwidth() / 2 - spec.bar.height / 2 - LABEL_PADDING_BOTTOM;
826
+ } }, spec.orderLabel.style), { textAlign: spec.labelLayout === 'bothEnd' ? 'right' : 'left', textBaseline: spec.labelLayout === 'bothEnd' ? 'middle' : 'bottom', visible: (datum) => {
827
+ if (datum[SUPPLY_DATA_KEY]) {
828
+ return false;
829
+ }
830
+ return spec.orderLabel.style.visible;
831
+ } }),
832
+ animation: Boolean(spec.animation),
833
+ animationEnter: this.getAnimationEnter(spec, 'text', totalDuration),
834
+ animationExit: this.getAnimationExit(spec, totalDuration),
835
+ animationAppear: this.getAnimationEnter(spec, 'text', totalDuration)
836
+ };
837
+ }
838
+ generateValueLabel(spec) {
839
+ const totalDuration = spec.animation.duration;
840
+ return {
841
+ type: 'text',
842
+ dataId: 'data',
843
+ visible: true,
844
+ dataKey: DATA_KEY,
845
+ state: {
846
+ blur: {
847
+ opacity: 0.2
848
+ }
849
+ },
850
+ style: Object.assign(Object.assign({ text: (datum) => this.formatDatum(spec.xField, datum), x: (datum, ctx) => {
851
+ if (spec.labelLayout === 'bothEnd') {
852
+ return (ctx.getRegion().getLayoutRect().width +
853
+ this.getMaxDataLabelLens(spec, spec.xField, this.nameLabelTextMeasure) +
854
+ VALUE_LABEL_PADDING_LEFT);
855
+ }
856
+ else {
857
+ return ctx.getRegion().getLayoutRect().width;
858
+ }
859
+ }, y: (datum, ctx) => {
860
+ if (spec.labelLayout === 'bothEnd') {
861
+ return ctx.valueToY([datum[spec.yField]]) + ctx.yBandwidth() / 2;
862
+ }
863
+ return ctx.valueToY([datum[spec.yField]]) + ctx.yBandwidth() / 2 - spec.bar.height / 2 - LABEL_PADDING_BOTTOM;
864
+ } }, spec.valueLabel.style), { textAlign: spec.labelLayout === 'bothEnd' ? 'left' : 'right', textBaseline: spec.labelLayout === 'bothEnd' ? 'middle' : 'bottom', visible: (datum) => {
865
+ if (datum[SUPPLY_DATA_KEY]) {
866
+ return false;
867
+ }
868
+ return spec.valueLabel.style.visible;
869
+ } }),
870
+ animation: Boolean(spec.animation),
871
+ animationEnter: this.getAnimationEnter(spec, 'text', totalDuration),
872
+ animationExit: this.getAnimationExit(spec, totalDuration),
873
+ animationAppear: this.getAnimationEnter(spec, 'text', totalDuration)
874
+ };
875
+ }
876
+ transformPaddingSpec(spec) {
877
+ var _a;
878
+ const maxHaloIconSize = spec.decorateHaloIcons.length > 0
879
+ ? Math.max(...spec.decorateHaloIcons.map((icon) => { var _a, _b; return (_b = (_a = icon.style) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 18; }))
880
+ : 0;
881
+ spec.padding = Object.assign({ left: spec.labelLayout === 'bothEnd'
882
+ ? NAME_LABEL_PADDING_RIGHT +
883
+ this.getMaxDataLabelLens(spec, spec.yField, this.nameLabelTextMeasure) +
884
+ (spec.orderLabel.style.visible
885
+ ? NAME_ORDER_PADDING_RIGHT + this.getMaxDataLabelLens(spec, ORDER_KEY, this.orderLabelTextMeasure)
886
+ : 0) +
887
+ (spec.rankingIcon.style.visible ? NAME_SYMBOL_PADDING_RIGHT + ((_a = spec.rankingIcon.style.size) !== null && _a !== void 0 ? _a : 10) : 0) +
888
+ CHART_PADDING_LEFT
889
+ : CHART_PADDING_LEFT + maxHaloIconSize / 2, right: spec.labelLayout === 'bothEnd'
890
+ ? VALUE_LABEL_PADDING_LEFT +
891
+ this.getMaxDataLabelLens(spec, spec.yField, this.valueLabelTextMeasure) +
892
+ CHART_PADDING_RIGHT
893
+ : CHART_PADDING_RIGHT + 10, top: 0, bottom: 0 }, spec.padding);
894
+ }
895
+ getMaxDataLabelLens(spec, field, textMeasure) {
896
+ const textWidths = this.originalData.map(datum => datum[SUPPLY_DATA_KEY] ? 0 : textMeasure.fullMeasure(this.formatDatum(field, datum)).width);
897
+ return Math.max(...textWidths);
898
+ }
899
+ formatDatum(field, datum) {
900
+ var _a;
901
+ if ((_a = this.formatMap) === null || _a === void 0 ? void 0 : _a[field]) {
902
+ return this.formatMap[field](datum[field], datum);
903
+ }
904
+ else {
905
+ return datum[field];
906
+ }
907
+ }
908
+ getLabelWidth(padding, width) {
909
+ return width + padding;
910
+ }
911
+ getAnimationExit(spec, duration) {
912
+ if (spec.animation.type === 'grow') {
913
+ return {};
914
+ }
915
+ return {
916
+ type: 'moveOut',
917
+ options: {
918
+ direction: 'y',
919
+ orient: 'negative',
920
+ point: (datum, element, opt) => {
921
+ const channelAttr = element.getGraphicAttribute('y');
922
+ const barSpace = (spec.height / spec.pageSize - spec.bar.height) / 2;
923
+ return { y: channelAttr - opt.height + barSpace };
924
+ }
925
+ },
926
+ duration: spec.animation.type === 'both' ? duration / 2 : duration,
927
+ easing: spec.animation.easing
928
+ };
929
+ }
930
+ getAnimationEnter(spec, markType, totalDuration) {
931
+ const { animation } = spec;
932
+ const { type: animationType, easing } = animation;
933
+ const scrollDuration = animationType === 'both' ? totalDuration / 2 : totalDuration;
934
+ const growDuration = animationType === 'grow' ? totalDuration : totalDuration / 2;
935
+ const result = [];
936
+ if (animationType === 'scroll' || animationType === 'both') {
937
+ result.push({
938
+ type: 'moveIn',
939
+ options: {
940
+ direction: 'y',
941
+ orient: 'negative',
942
+ excludeChannels: ['y'],
943
+ point: (datum, element, opt) => {
944
+ const channelAttr = element.getGraphicAttribute('y');
945
+ const barSpace = (spec.height / spec.pageSize - spec.bar.height) / 2;
946
+ return { y: channelAttr + opt.height - barSpace };
947
+ }
948
+ },
949
+ duration: scrollDuration,
950
+ easing
951
+ });
952
+ }
953
+ if ((animationType === 'grow' || animationType === 'both') && markType !== 'text' && markType !== 'barBack') {
954
+ result.push({
955
+ channel: {
956
+ x: {
957
+ from: 0,
958
+ to: (datum, element) => {
959
+ return element.getGraphicItem().attribute.x;
960
+ }
961
+ }
962
+ },
963
+ duration: growDuration,
964
+ delay: animationType === 'both' ? scrollDuration : 0,
965
+ easing
966
+ });
967
+ }
968
+ return result;
969
+ }
970
+ }
971
+
972
+ class RankingList extends vchart.BaseChart {
973
+ constructor() {
974
+ super(...arguments);
975
+ this.type = 'rankingList';
976
+ this.transformerConstructor = RankingListChartSpecTransformer;
977
+ }
978
+ init() {
979
+ if (!this.isValid()) {
980
+ return;
981
+ }
982
+ super.init();
983
+ }
984
+ isValid() {
985
+ var _a, _b, _c, _d;
986
+ const { xField, yField, data } = this._spec;
987
+ if (!xField || !yField) {
988
+ (_b = (_a = this._option).onError) === null || _b === void 0 ? void 0 : _b.call(_a, 'Missing Required Config: `xField`, `yField` ');
989
+ return false;
990
+ }
991
+ if (!data || data.length === 0) {
992
+ (_d = (_c = this._option).onError) === null || _d === void 0 ? void 0 : _d.call(_c, 'Data is required');
993
+ return false;
994
+ }
995
+ return true;
996
+ }
997
+ }
998
+ RankingList.type = 'rankingList';
999
+ RankingList.view = 'singleDefault';
1000
+ RankingList.transformerConstructor = RankingListChartSpecTransformer;
1001
+ const registerRankingList = (option) => {
1002
+ const vchartConstructor = (option === null || option === void 0 ? void 0 : option.VChart) || vchart.VChart;
1003
+ if (vchartConstructor) {
1004
+ vchartConstructor.useChart([RankingList, vchart.BarChart]);
1005
+ }
1006
+ };
1007
+
341
1008
  const fields = (data, options) => {
342
1009
  var _a, _b;
343
1010
  if (!(null == options ? void 0 : options.fields)) return data;
@@ -2237,7 +2904,7 @@
2237
2904
  default:
2238
2905
  if (this._t <= 0) this.context.lineTo(this._x, y, !1 !== this._lastDefined && !1 !== p.defined, this.lastPoint), this.context.lineTo(x, y, !1 !== this._lastDefined && !1 !== p.defined, p);else {
2239
2906
  const x1 = this._x * (1 - this._t) + x * this._t;
2240
- .5 === this._t ? this.context.lineTo(x1, this._y, !1 !== this._lastDefined, this.lastPoint) : this.context.lineTo(x1, this._y, !1 !== this._lastDefined && !1 !== p.defined, this.lastPoint), this.context.lineTo(x1, y, !1 !== this._lastDefined && !1 !== p.defined, p);
2907
+ this.context.lineTo(x1, this._y, !1 !== this._lastDefined && !1 !== p.defined, this.lastPoint), this.context.lineTo(x1, y, !1 !== this._lastDefined && !1 !== p.defined, p);
2241
2908
  }
2242
2909
  }
2243
2910
  this._lastDefined = p.defined, this._x = x, this._y = y, this.lastPoint = p;
@@ -3827,7 +4494,7 @@
3827
4494
  let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Generator.GenAutoIncrementId();
3828
4495
  let timeline = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultTimeline;
3829
4496
  let slience = arguments.length > 2 ? arguments[2] : undefined;
3830
- this.id = id, this.timeline = timeline || defaultTimeline, this.status = AnimateStatus.INITIAL, this.tailAnimate = new SubAnimate(this), this.subAnimates = [this.tailAnimate], this.timeScale = 1, this.rawPosition = -1, this._startTime = 0, this._duringTime = 0, this.timeline.addAnimate(this), this.slience = slience;
4497
+ this.id = id, this.timeline = timeline, this.status = AnimateStatus.INITIAL, this.tailAnimate = new SubAnimate(this), this.subAnimates = [this.tailAnimate], this.timeScale = 1, this.rawPosition = -1, this._startTime = 0, this._duringTime = 0, this.timeline.addAnimate(this), this.slience = slience;
3831
4498
  }
3832
4499
  setTimeline(timeline) {
3833
4500
  timeline !== this.timeline && (this.timeline.removeAnimate(this, !1), timeline.addAnimate(this));
@@ -4361,7 +5028,7 @@
4361
5028
  }
4362
5029
  static GetFile(url, type) {
4363
5030
  let data = ResourceLoader.cache.get(url);
4364
- return data ? "fail" === data.loadState ? Promise.reject() : "init" === data.loadState || "loading" === data.loadState ? data.dataPromise.then(data => data.data) : Promise.resolve(data.data) : (data = {
5031
+ return data ? "init" === data.loadState || "fail" === data.loadState ? Promise.reject() : "loading" === data.loadState ? data.dataPromise.then(data => data.data) : Promise.resolve(data.data) : (data = {
4365
5032
  type: type,
4366
5033
  loadState: "init"
4367
5034
  }, ResourceLoader.cache.set(url, data), "arrayBuffer" === type ? data.dataPromise = application.global.loadArrayBuffer(url) : "blob" === type ? data.dataPromise = application.global.loadBlob(url) : "json" === type && (data.dataPromise = application.global.loadJson(url)), data.dataPromise.then(data => data.data));
@@ -6453,7 +7120,7 @@
6453
7120
  this._draw(line, lineAttribute, !1, drawContext, params);
6454
7121
  }
6455
7122
  drawSegmentItem(context, cache, fill, stroke, fillOpacity, strokeOpacity, attribute, defaultAttribute, clipRange, clipRangeByDimension, offsetX, offsetY, line, fillCb, strokeCb) {
6456
- var _a;
7123
+ var _a, _b, _c, _d, _e;
6457
7124
  if (!cache) return;
6458
7125
  context.beginPath();
6459
7126
  const z = null !== (_a = this.z) && void 0 !== _a ? _a : 0;
@@ -6466,7 +7133,27 @@
6466
7133
  x: originX = 0,
6467
7134
  x: originY = 0
6468
7135
  } = attribute;
6469
- return !1 !== fill && (fillCb ? fillCb(context, attribute, defaultAttribute) : fillOpacity && (context.setCommonStyle(line, attribute, originX - offsetX, originY - offsetY, defaultAttribute), context.fill())), !1 !== stroke && (strokeCb ? strokeCb(context, attribute, defaultAttribute) : strokeOpacity && (context.setStrokeStyle(line, attribute, originX - offsetX, originY - offsetY, defaultAttribute), context.stroke())), !1;
7136
+ !1 !== fill && (fillCb ? fillCb(context, attribute, defaultAttribute) : fillOpacity && (context.setCommonStyle(line, attribute, originX - offsetX, originY - offsetY, defaultAttribute), context.fill())), !1 !== stroke && (strokeCb ? strokeCb(context, attribute, defaultAttribute) : strokeOpacity && (context.setStrokeStyle(line, attribute, originX - offsetX, originY - offsetY, defaultAttribute), context.stroke()));
7137
+ let {
7138
+ connectedType: connectedType,
7139
+ connectedX: connectedX,
7140
+ connectedY: connectedY,
7141
+ connectedStyle: connectedStyle
7142
+ } = attribute;
7143
+ if (vutils.isArray(defaultAttribute) ? (connectedType = null !== (_b = null != connectedType ? connectedType : defaultAttribute[0].connectedType) && void 0 !== _b ? _b : defaultAttribute[1].connectedType, connectedX = null !== (_c = null != connectedX ? connectedX : defaultAttribute[0].connectedX) && void 0 !== _c ? _c : defaultAttribute[1].connectedX, connectedY = null !== (_d = null != connectedY ? connectedY : defaultAttribute[0].connectedY) && void 0 !== _d ? _d : defaultAttribute[1].connectedY, connectedStyle = null !== (_e = null != connectedStyle ? connectedStyle : defaultAttribute[0].connectedStyle) && void 0 !== _e ? _e : defaultAttribute[1].connectedStyle) : (connectedType = null != connectedType ? connectedType : defaultAttribute.connectedType, connectedX = null != connectedX ? connectedX : defaultAttribute.connectedX, connectedY = null != connectedY ? connectedY : defaultAttribute.connectedY, connectedStyle = null != connectedStyle ? connectedStyle : defaultAttribute.connectedStyle), "connect" !== connectedType && "zero" !== connectedType && (connectedType = "none"), "none" !== connectedType) {
7144
+ context.beginPath(), drawSegments(context.camera ? context : context.nativeContext, cache, clipRange, clipRangeByDimension, {
7145
+ offsetX: offsetX,
7146
+ offsetY: offsetY,
7147
+ offsetZ: z,
7148
+ drawConnect: !0,
7149
+ mode: connectedType,
7150
+ zeroX: connectedX,
7151
+ zeroY: connectedY
7152
+ });
7153
+ const da = [];
7154
+ vutils.isArray(defaultAttribute) ? defaultAttribute.forEach(i => da.push(i)) : da.push(defaultAttribute), da.push(attribute), !1 !== fill && (fillCb ? fillCb(context, attribute, defaultAttribute) : fillOpacity && (context.setCommonStyle(line, connectedStyle, originX - offsetX, originY - offsetY, da), context.fill())), !1 !== stroke && (strokeCb ? strokeCb(context, attribute, defaultAttribute) : strokeOpacity && (context.setStrokeStyle(line, connectedStyle, originX - offsetX, originY - offsetY, da), context.stroke()));
7155
+ }
7156
+ return !1;
6470
7157
  }
6471
7158
  drawLinearLineHighPerformance(line, context, fill, stroke, fillOpacity, strokeOpacity, offsetX, offsetY, lineAttribute, drawContext, params, fillCb, strokeCb) {
6472
7159
  var _a;
@@ -6498,8 +7185,7 @@
6498
7185
  segments: segments,
6499
7186
  points: points,
6500
7187
  closePath: closePath,
6501
- curveTension = lineAttribute.curveTension,
6502
- connectedType = lineAttribute.connectedType
7188
+ curveTension = lineAttribute.curveTension
6503
7189
  } = line.attribute;
6504
7190
  if (!this.valid(line, lineAttribute, fillCb, strokeCb)) return;
6505
7191
  let {
@@ -6511,9 +7197,6 @@
6511
7197
  clipRangeByDimension = lineAttribute.clipRangeByDimension
6512
7198
  } = line.attribute;
6513
7199
  if (1 === clipRange && !segments && !points.some(p => !1 === p.defined) && "linear" === curveType) return this.drawLinearLineHighPerformance(line, context, !!fill, !!stroke, fillOpacity, strokeOpacity, x, y, lineAttribute, drawContext, params, fillCb, strokeCb);
6514
- function parsePoint(points, connectedType) {
6515
- return "none" === connectedType ? points : points.filter(p => !1 !== p.defined);
6516
- }
6517
7200
  if (line.shouldUpdateShape()) {
6518
7201
  const {
6519
7202
  points: points,
@@ -6535,7 +7218,7 @@
6535
7218
  y: lastSeg.endY,
6536
7219
  defined: lastSeg.curves[lastSeg.curves.length - 1].defined
6537
7220
  } : index > 1 && (startPoint.x = lastSeg.endX, startPoint.y = lastSeg.endY, startPoint.defined = lastSeg.curves[lastSeg.curves.length - 1].defined);
6538
- const data = calcLineCache(parsePoint(seg.points, connectedType), curveType, {
7221
+ const data = calcLineCache(seg.points, curveType, {
6539
7222
  startPoint: startPoint,
6540
7223
  curveTension: curveTension
6541
7224
  });
@@ -6554,7 +7237,7 @@
6554
7237
  }
6555
7238
  } else {
6556
7239
  if (!points || !points.length) return line.cache = null, void line.clearUpdateShapeTag();
6557
- line.cache = calcLineCache(parsePoint(_points, connectedType), curveType, {
7240
+ line.cache = calcLineCache(_points, curveType, {
6558
7241
  curveTension: curveTension
6559
7242
  });
6560
7243
  }
@@ -7974,7 +8657,7 @@
7974
8657
  } = attribute,
7975
8658
  b = aabbBounds;
7976
8659
  return points.forEach(p => {
7977
- !1 === p.defined && "connect" !== connectedType || b.add(p.x, p.y);
8660
+ !1 === p.defined && "zero" !== connectedType && "connect" !== connectedType || b.add(p.x, p.y);
7978
8661
  }), b;
7979
8662
  }
7980
8663
  updateLineAABBBoundsBySegments(attribute, lineTheme, aabbBounds, graphic) {
@@ -7985,7 +8668,7 @@
7985
8668
  b = aabbBounds;
7986
8669
  return segments.forEach(s => {
7987
8670
  s.points.forEach(p => {
7988
- !1 === p.defined && "connect" !== connectedType || b.add(p.x, p.y);
8671
+ !1 === p.defined && "zero" !== connectedType && "connect" !== connectedType || b.add(p.x, p.y);
7989
8672
  });
7990
8673
  }), b;
7991
8674
  }
@@ -8365,17 +9048,10 @@
8365
9048
  this.render(), this.bindEvents();
8366
9049
  });
8367
9050
  }
8368
- setAttribute(key, value, forceUpdateTag, context) {
8369
- const params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate({
8370
- [key]: value
8371
- }, this.attribute, key, context);
8372
- if (params) return this._setAttributes(params, forceUpdateTag);
9051
+ setAttribute(key, value, forceUpdateTag) {
8373
9052
  vutils.isPlainObject(this.attribute[key]) && vutils.isPlainObject(value) && !vutils.isFunction(this.attribute[key]) && !vutils.isFunction(value) ? vutils.merge(this.attribute[key], value) : this.attribute[key] = value, GROUP_ATTRIBUTES.includes(key) || this.render(), this.valid = this.isValid(), this.updateShapeAndBoundsTagSetted() || !forceUpdateTag && !this.needUpdateTag(key) ? this.addUpdateBoundTag() : this.addUpdateShapeAndBoundsTag(), this.addUpdatePositionTag(), this.onAttributeUpdate();
8374
9053
  }
8375
- setAttributes(params, forceUpdateTag, context) {
8376
- return params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(params, this.attribute, null, context) || params, this._setAttributes(params, forceUpdateTag);
8377
- }
8378
- _setAttributes(params, forceUpdateTag) {
9054
+ setAttributes(params, forceUpdateTag) {
8379
9055
  const keys = Object.keys(params);
8380
9056
  this._mergeAttributes(params, keys), keys.every(key => GROUP_ATTRIBUTES.includes(key)) || this.render(), this.valid = this.isValid(), this.updateShapeAndBoundsTagSetted() || !forceUpdateTag && !this.needUpdateTags(keys) ? this.addUpdateBoundTag() : this.addUpdateShapeAndBoundsTag(), this.addUpdatePositionTag(), this.onAttributeUpdate();
8381
9057
  }
@@ -10166,6 +10842,7 @@
10166
10842
  exports.DEFAULT_ARROW_TEXT_MARK_STYLE = DEFAULT_ARROW_TEXT_MARK_STYLE;
10167
10843
  exports.DEFAULT_FUNNEL_BACKGROUND_MARK_STYLE = DEFAULT_FUNNEL_BACKGROUND_MARK_STYLE;
10168
10844
  exports.RankingBar = RankingBar;
10845
+ exports.RankingList = RankingList;
10169
10846
  exports.SERIES_BREAK = SERIES_BREAK;
10170
10847
  exports.SeriesBreakComponent = SeriesBreakComponent;
10171
10848
  exports.SeriesLabelComponent = SeriesLabelComponent;
@@ -10178,6 +10855,7 @@
10178
10855
  exports.registerBarLink = registerBarLink;
10179
10856
  exports.registerConversionFunnelChart = registerConversionFunnelChart;
10180
10857
  exports.registerRankingBarChart = registerRankingBarChart;
10858
+ exports.registerRankingList = registerRankingList;
10181
10859
  exports.registerSeriesBreak = registerSeriesBreak;
10182
10860
  exports.registerSeriesLabel = registerSeriesLabel;
10183
10861