billboard.js 3.6.0-next.2 → 3.6.0
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/dist/billboard.css +1 -1
- package/dist/billboard.js +424 -237
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +538 -351
- package/dist/billboard.pkgd.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +116 -116
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +116 -116
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +116 -116
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +116 -116
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +116 -116
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist-esm/billboard.js +342 -168
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
- package/package.json +5 -5
- package/src/ChartInternal/internals/color.ts +50 -0
- package/src/ChartInternal/internals/legend.ts +246 -145
- package/src/ChartInternal/shape/area.ts +9 -38
- package/src/ChartInternal/shape/bar.ts +20 -3
- package/src/config/Options/common/legend.ts +18 -3
- package/src/config/Options/shape/bar.ts +32 -0
- package/types/options.d.ts +23 -4
|
@@ -11,6 +11,22 @@ import {$FOCUS, $GAUGE, $LEGEND} from "../../config/classes";
|
|
|
11
11
|
import {KEY} from "../../module/Cache";
|
|
12
12
|
import {callFn, isDefined, getOption, isEmpty, isFunction, notEmpty, tplProcess} from "../../module/util";
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Get color string for given data id
|
|
16
|
+
* @param {string} id Data id
|
|
17
|
+
* @returns {string} Color string
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
function getLegendColor(id: string): string {
|
|
21
|
+
const $$ = this;
|
|
22
|
+
const data = $$.getDataById(id);
|
|
23
|
+
const color = $$.levelColor ?
|
|
24
|
+
$$.levelColor(data.values[0].value) :
|
|
25
|
+
$$.color(data);
|
|
26
|
+
|
|
27
|
+
return color;
|
|
28
|
+
}
|
|
29
|
+
|
|
14
30
|
export default {
|
|
15
31
|
/**
|
|
16
32
|
* Initialize the legend.
|
|
@@ -101,7 +117,7 @@ export default {
|
|
|
101
117
|
|
|
102
118
|
if (!wrapper.empty()) {
|
|
103
119
|
const targets = $$.mapToIds($$.data.targets);
|
|
104
|
-
const ids:
|
|
120
|
+
const ids: string[] = [];
|
|
105
121
|
let html = "";
|
|
106
122
|
|
|
107
123
|
targets.forEach(v => {
|
|
@@ -454,38 +470,142 @@ export default {
|
|
|
454
470
|
updateLegendElement(targetIds: string[], options): void {
|
|
455
471
|
const $$ = this;
|
|
456
472
|
const {config, state, $el: {legend}, $T} = $$;
|
|
457
|
-
const
|
|
458
|
-
const
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
473
|
+
const legendType = config.legend_item_tile_type;
|
|
474
|
+
const isRectangle = legendType !== "circle";
|
|
475
|
+
const legendItemR = config.legend_item_tile_r;
|
|
476
|
+
|
|
477
|
+
const itemTileSize = {
|
|
478
|
+
width: isRectangle ? config.legend_item_tile_width : legendItemR * 2,
|
|
479
|
+
height: isRectangle ? config.legend_item_tile_height : legendItemR * 2
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
const dimension = {
|
|
483
|
+
padding: {
|
|
484
|
+
top: 4,
|
|
485
|
+
right: 10
|
|
486
|
+
},
|
|
487
|
+
max: {
|
|
488
|
+
width: 0,
|
|
489
|
+
height: 0
|
|
490
|
+
},
|
|
491
|
+
posMin: 10,
|
|
492
|
+
step: 0,
|
|
493
|
+
tileWidth: itemTileSize.width + 5,
|
|
494
|
+
totalLength: 0
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
const sizes = {
|
|
498
|
+
offsets: {},
|
|
499
|
+
widths: {},
|
|
500
|
+
heights: {},
|
|
501
|
+
margins: [0],
|
|
502
|
+
steps: {}
|
|
503
|
+
};
|
|
504
|
+
|
|
463
505
|
let xForLegend;
|
|
464
506
|
let yForLegend;
|
|
465
|
-
let totalLength = 0;
|
|
466
|
-
const offsets = {};
|
|
467
|
-
const widths = {};
|
|
468
|
-
const heights = {};
|
|
469
|
-
const margins = [0];
|
|
470
|
-
const steps = {};
|
|
471
|
-
let step = 0;
|
|
472
507
|
let background;
|
|
473
|
-
const isLegendRightOrInset = state.isLegendRight || state.isLegendInset;
|
|
474
508
|
|
|
475
509
|
// Skip elements when their name is set to null
|
|
476
510
|
const targetIdz = targetIds
|
|
477
511
|
.filter(id => !isDefined(config.data_names[id]) || config.data_names[id] !== null);
|
|
478
512
|
|
|
479
513
|
const withTransition = options.withTransition;
|
|
514
|
+
const updatePositions = $$.getUpdateLegendPositions(targetIdz, dimension, sizes);
|
|
515
|
+
|
|
516
|
+
if (state.isLegendInset) {
|
|
517
|
+
dimension.step = config.legend_inset_step ? config.legend_inset_step : targetIdz.length;
|
|
518
|
+
$$.updateLegendStep(dimension.step);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (state.isLegendRight) {
|
|
522
|
+
xForLegend = id => dimension.max.width * sizes.steps[id];
|
|
523
|
+
yForLegend = id => sizes.margins[sizes.steps[id]] + sizes.offsets[id];
|
|
524
|
+
} else if (state.isLegendInset) {
|
|
525
|
+
xForLegend = id => dimension.max.width * sizes.steps[id] + 10;
|
|
526
|
+
yForLegend = id => sizes.margins[sizes.steps[id]] + sizes.offsets[id];
|
|
527
|
+
} else {
|
|
528
|
+
xForLegend = id => sizes.margins[sizes.steps[id]] + sizes.offsets[id];
|
|
529
|
+
yForLegend = id => dimension.max.height * sizes.steps[id];
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const posFn = {
|
|
533
|
+
xText: (id, i?: number) => xForLegend(id, i) + 4 + itemTileSize.width,
|
|
534
|
+
xRect: (id, i?: number) => xForLegend(id, i),
|
|
535
|
+
x1Tile: (id, i?: number) => xForLegend(id, i) - 2,
|
|
536
|
+
x2Tile: (id, i?: number) => xForLegend(id, i) - 2 + itemTileSize.width,
|
|
537
|
+
yText: (id, i?: number) => yForLegend(id, i) + 9,
|
|
538
|
+
yRect: (id, i?: number) => yForLegend(id, i) - 5,
|
|
539
|
+
yTile: (id, i?: number) => yForLegend(id, i) + 4
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
$$.generateLegendItem(targetIdz, itemTileSize, updatePositions, posFn);
|
|
543
|
+
|
|
544
|
+
// Set background for inset legend
|
|
545
|
+
background = legend.select(`.${$LEGEND.legendBackground} rect`);
|
|
546
|
+
|
|
547
|
+
if (state.isLegendInset && dimension.max.width > 0 && background.size() === 0) {
|
|
548
|
+
background = legend.insert("g", `.${$LEGEND.legendItem}`)
|
|
549
|
+
.attr("class", $LEGEND.legendBackground)
|
|
550
|
+
.append("rect");
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
const texts = legend.selectAll("text")
|
|
554
|
+
.data(targetIdz)
|
|
555
|
+
.text(id => (isDefined(config.data_names[id]) ? config.data_names[id] : id)) // MEMO: needed for update
|
|
556
|
+
.each(function(id, i) {
|
|
557
|
+
updatePositions(this, id, i);
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
$T(texts, withTransition)
|
|
561
|
+
.attr("x", posFn.xText)
|
|
562
|
+
.attr("y", posFn.yText);
|
|
563
|
+
|
|
564
|
+
const rects = legend.selectAll(`rect.${$LEGEND.legendItemEvent}`)
|
|
565
|
+
.data(targetIdz);
|
|
566
|
+
|
|
567
|
+
$T(rects, withTransition)
|
|
568
|
+
.attr("width", id => sizes.widths[id])
|
|
569
|
+
.attr("height", id => sizes.heights[id])
|
|
570
|
+
.attr("x", posFn.xRect)
|
|
571
|
+
.attr("y", posFn.yRect);
|
|
572
|
+
|
|
573
|
+
// update legend items position
|
|
574
|
+
$$.updateLegendItemPos(targetIdz, withTransition, posFn);
|
|
575
|
+
|
|
576
|
+
if (background) {
|
|
577
|
+
$T(background, withTransition)
|
|
578
|
+
.attr("height", $$.getLegendHeight() - 12)
|
|
579
|
+
.attr("width", dimension.max.width * (dimension.step + 1) + 10);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// Update all to reflect change of legend
|
|
583
|
+
$$.updateLegendItemWidth(dimension.max.width);
|
|
584
|
+
$$.updateLegendItemHeight(dimension.max.height);
|
|
585
|
+
$$.updateLegendStep(dimension.step);
|
|
586
|
+
},
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Get position update function
|
|
590
|
+
* @param {Array} targetIdz Data ids
|
|
591
|
+
* @param {object} dimension Dimension object
|
|
592
|
+
* @param {object} sizes Size object
|
|
593
|
+
* @returns {Function} Update position function
|
|
594
|
+
* @private
|
|
595
|
+
*/
|
|
596
|
+
getUpdateLegendPositions(targetIdz, dimension, sizes) {
|
|
597
|
+
const $$ = this;
|
|
598
|
+
const {config, state} = $$;
|
|
599
|
+
const isLegendRightOrInset = state.isLegendRight || state.isLegendInset;
|
|
480
600
|
|
|
481
|
-
|
|
601
|
+
return function(textElement, id, index) {
|
|
482
602
|
const reset = index === 0;
|
|
483
603
|
const isLast = index === targetIdz.length - 1;
|
|
484
604
|
const box = $$.getLegendItemTextBox(id, textElement);
|
|
485
605
|
|
|
486
|
-
const itemWidth = box.width + tileWidth +
|
|
487
|
-
(isLast && !isLegendRightOrInset ? 0 :
|
|
488
|
-
const itemHeight = box.height +
|
|
606
|
+
const itemWidth = box.width + dimension.tileWidth +
|
|
607
|
+
(isLast && !isLegendRightOrInset ? 0 : dimension.padding.right) + config.legend_padding;
|
|
608
|
+
const itemHeight = box.height + dimension.padding.top;
|
|
489
609
|
const itemLength = isLegendRightOrInset ? itemHeight : itemWidth;
|
|
490
610
|
const areaLength = isLegendRightOrInset ? $$.getLegendHeight() : $$.getLegendWidth();
|
|
491
611
|
let margin;
|
|
@@ -493,58 +613,58 @@ export default {
|
|
|
493
613
|
// MEMO: care about condifion of step, totalLength
|
|
494
614
|
const updateValues = function(id2, withoutStep?: boolean) {
|
|
495
615
|
if (!withoutStep) {
|
|
496
|
-
margin = (areaLength - totalLength - itemLength) / 2;
|
|
616
|
+
margin = (areaLength - dimension.totalLength - itemLength) / 2;
|
|
497
617
|
|
|
498
|
-
if (margin < posMin) {
|
|
618
|
+
if (margin < dimension.posMin) {
|
|
499
619
|
margin = (areaLength - itemLength) / 2;
|
|
500
|
-
totalLength = 0;
|
|
501
|
-
step++;
|
|
620
|
+
dimension.totalLength = 0;
|
|
621
|
+
dimension.step++;
|
|
502
622
|
}
|
|
503
623
|
}
|
|
504
624
|
|
|
505
|
-
steps[id2] = step;
|
|
506
|
-
margins[step] = state.isLegendInset ? 10 : margin;
|
|
507
|
-
offsets[id2] = totalLength;
|
|
508
|
-
totalLength += itemLength;
|
|
625
|
+
sizes.steps[id2] = dimension.step;
|
|
626
|
+
sizes.margins[dimension.step] = state.isLegendInset ? 10 : margin;
|
|
627
|
+
sizes.offsets[id2] = dimension.totalLength;
|
|
628
|
+
dimension.totalLength += itemLength;
|
|
509
629
|
};
|
|
510
630
|
|
|
511
631
|
if (reset) {
|
|
512
|
-
totalLength = 0;
|
|
513
|
-
step = 0;
|
|
514
|
-
|
|
515
|
-
|
|
632
|
+
dimension.totalLength = 0;
|
|
633
|
+
dimension.step = 0;
|
|
634
|
+
dimension.max.width = 0;
|
|
635
|
+
dimension.max.height = 0;
|
|
516
636
|
}
|
|
517
637
|
|
|
518
638
|
if (config.legend_show && !$$.isLegendToShow(id)) {
|
|
519
|
-
widths[id] = 0;
|
|
520
|
-
heights[id] = 0;
|
|
521
|
-
steps[id] = 0;
|
|
522
|
-
offsets[id] = 0;
|
|
639
|
+
sizes.widths[id] = 0;
|
|
640
|
+
sizes.heights[id] = 0;
|
|
641
|
+
sizes.steps[id] = 0;
|
|
642
|
+
sizes.offsets[id] = 0;
|
|
523
643
|
|
|
524
644
|
return;
|
|
525
645
|
}
|
|
526
646
|
|
|
527
|
-
widths[id] = itemWidth;
|
|
528
|
-
heights[id] = itemHeight;
|
|
647
|
+
sizes.widths[id] = itemWidth;
|
|
648
|
+
sizes.heights[id] = itemHeight;
|
|
529
649
|
|
|
530
|
-
if (!
|
|
531
|
-
|
|
650
|
+
if (!dimension.max.width || itemWidth >= dimension.max.width) {
|
|
651
|
+
dimension.max.width = itemWidth;
|
|
532
652
|
}
|
|
533
653
|
|
|
534
|
-
if (!
|
|
535
|
-
|
|
654
|
+
if (!dimension.max.height || itemHeight >= dimension.max.height) {
|
|
655
|
+
dimension.max.height = itemHeight;
|
|
536
656
|
}
|
|
537
657
|
|
|
538
|
-
const maxLength = isLegendRightOrInset ?
|
|
658
|
+
const maxLength = isLegendRightOrInset ? dimension.max.height : dimension.max.width;
|
|
539
659
|
|
|
540
660
|
if (config.legend_equally) {
|
|
541
|
-
Object.keys(widths).forEach(id2 => (widths[id2] =
|
|
542
|
-
Object.keys(heights).forEach(id2 => (heights[id2] =
|
|
661
|
+
Object.keys(sizes.widths).forEach(id2 => (sizes.widths[id2] = dimension.max.width));
|
|
662
|
+
Object.keys(sizes.heights).forEach(id2 => (sizes.heights[id2] = dimension.max.height));
|
|
543
663
|
margin = (areaLength - maxLength * targetIdz.length) / 2;
|
|
544
664
|
|
|
545
|
-
if (margin < posMin) {
|
|
546
|
-
totalLength = 0;
|
|
547
|
-
step = 0;
|
|
665
|
+
if (margin < dimension.posMin) {
|
|
666
|
+
dimension.totalLength = 0;
|
|
667
|
+
dimension.step = 0;
|
|
548
668
|
targetIdz.forEach(id2 => updateValues(id2));
|
|
549
669
|
} else {
|
|
550
670
|
updateValues(id, true);
|
|
@@ -553,31 +673,24 @@ export default {
|
|
|
553
673
|
updateValues(id);
|
|
554
674
|
}
|
|
555
675
|
};
|
|
676
|
+
},
|
|
556
677
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
const xForLegendText = (id, i?: number) => xForLegend(id, i) + 4 + config.legend_item_tile_width;
|
|
574
|
-
const xForLegendRect = (id, i?: number) => xForLegend(id, i);
|
|
575
|
-
const x1ForLegendTile = (id, i?: number) => xForLegend(id, i) - 2;
|
|
576
|
-
const x2ForLegendTile = (id, i?: number) => xForLegend(id, i) - 2 + config.legend_item_tile_width;
|
|
577
|
-
|
|
578
|
-
const yForLegendText = (id, i?: number) => yForLegend(id, i) + 9;
|
|
579
|
-
const yForLegendRect = (id, i?: number) => yForLegend(id, i) - 5;
|
|
580
|
-
const yForLegendTile = (id, i?: number) => yForLegend(id, i) + 4;
|
|
678
|
+
/**
|
|
679
|
+
* Generate legend item elements
|
|
680
|
+
* @param {Array} targetIdz Data ids
|
|
681
|
+
* @param {object} itemTileSize Item tile size {width, height}
|
|
682
|
+
* @param {Function} updatePositions Update position function
|
|
683
|
+
* @param {object} posFn Position functions
|
|
684
|
+
* @private
|
|
685
|
+
*/
|
|
686
|
+
generateLegendItem(targetIdz, itemTileSize, updatePositions, posFn) {
|
|
687
|
+
const $$ = this;
|
|
688
|
+
const {config, state, $el: {legend}} = $$;
|
|
689
|
+
const usePoint = config.legend_usePoint;
|
|
690
|
+
const legendItemR = config.legend_item_tile_r;
|
|
691
|
+
const legendType = config.legend_item_tile_type;
|
|
692
|
+
const isRectangle = legendType !== "circle";
|
|
693
|
+
const isLegendRightOrInset = state.isLegendRight || state.isLegendInset;
|
|
581
694
|
|
|
582
695
|
const pos = -200;
|
|
583
696
|
|
|
@@ -595,28 +708,17 @@ export default {
|
|
|
595
708
|
updatePositions(this, id, i);
|
|
596
709
|
})
|
|
597
710
|
.style("pointer-events", $$.getStylePropValue("none"))
|
|
598
|
-
.attr("x", isLegendRightOrInset ?
|
|
599
|
-
.attr("y", isLegendRightOrInset ? pos :
|
|
711
|
+
.attr("x", isLegendRightOrInset ? posFn.xText : pos)
|
|
712
|
+
.attr("y", isLegendRightOrInset ? pos : posFn.yText);
|
|
600
713
|
|
|
601
714
|
l.append("rect")
|
|
602
715
|
.attr("class", $LEGEND.legendItemEvent)
|
|
603
716
|
.style("fill-opacity", $$.getStylePropValue("0"))
|
|
604
|
-
.attr("x", isLegendRightOrInset ?
|
|
605
|
-
.attr("y", isLegendRightOrInset ? pos :
|
|
606
|
-
|
|
607
|
-
const getColor = id => {
|
|
608
|
-
const data = $$.getDataById(id);
|
|
609
|
-
const color = $$.levelColor ?
|
|
610
|
-
$$.levelColor(data.values[0].value) :
|
|
611
|
-
$$.color(data);
|
|
612
|
-
|
|
613
|
-
return color;
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
const usePoint = config.legend_usePoint;
|
|
717
|
+
.attr("x", isLegendRightOrInset ? posFn.xRect : pos)
|
|
718
|
+
.attr("y", isLegendRightOrInset ? pos : posFn.yRect);
|
|
617
719
|
|
|
618
720
|
if (usePoint) {
|
|
619
|
-
const ids:
|
|
721
|
+
const ids: string[] = [];
|
|
620
722
|
|
|
621
723
|
l.append(d => {
|
|
622
724
|
const pattern = notEmpty(config.point_pattern) ?
|
|
@@ -633,7 +735,7 @@ export default {
|
|
|
633
735
|
return document.createElementNS(d3Namespaces.svg, ("hasValidPointType" in $$) && $$.hasValidPointType(point) ? point : "use");
|
|
634
736
|
})
|
|
635
737
|
.attr("class", $LEGEND.legendItemPoint)
|
|
636
|
-
.style("fill",
|
|
738
|
+
.style("fill", getLegendColor.bind($$))
|
|
637
739
|
.style("pointer-events", $$.getStylePropValue("none"))
|
|
638
740
|
.attr("href", (data, idx, selection) => {
|
|
639
741
|
const node = selection[idx];
|
|
@@ -643,45 +745,42 @@ export default {
|
|
|
643
745
|
return nodeName === "use" ? `#${state.datetimeId}-point${id}` : undefined;
|
|
644
746
|
});
|
|
645
747
|
} else {
|
|
646
|
-
l.append("line")
|
|
748
|
+
l.append(isRectangle ? "line" : legendType)
|
|
647
749
|
.attr("class", $LEGEND.legendItemTile)
|
|
648
|
-
.style("stroke",
|
|
750
|
+
.style("stroke", getLegendColor.bind($$))
|
|
649
751
|
.style("pointer-events", $$.getStylePropValue("none"))
|
|
650
|
-
.
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
752
|
+
.call(selection => {
|
|
753
|
+
if (legendType === "circle") {
|
|
754
|
+
selection
|
|
755
|
+
.attr("r", legendItemR)
|
|
756
|
+
.style("fill", getLegendColor.bind($$))
|
|
757
|
+
.attr("cx", isLegendRightOrInset ? posFn.x2Tile : pos)
|
|
758
|
+
.attr("cy", isLegendRightOrInset ? pos : posFn.yTile);
|
|
759
|
+
} else if (isRectangle) {
|
|
760
|
+
selection
|
|
761
|
+
.attr("stroke-width", itemTileSize.height)
|
|
762
|
+
.attr("x1", isLegendRightOrInset ? posFn.x1Tile : pos)
|
|
763
|
+
.attr("y1", isLegendRightOrInset ? pos : posFn.yTile)
|
|
764
|
+
.attr("x2", isLegendRightOrInset ? posFn.x2Tile : pos)
|
|
765
|
+
.attr("y2", isLegendRightOrInset ? pos : posFn.yTile);
|
|
766
|
+
}
|
|
767
|
+
});
|
|
664
768
|
}
|
|
769
|
+
},
|
|
665
770
|
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
const
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
$T(rects, withTransition)
|
|
681
|
-
.attr("width", id => widths[id])
|
|
682
|
-
.attr("height", id => heights[id])
|
|
683
|
-
.attr("x", xForLegendRect)
|
|
684
|
-
.attr("y", yForLegendRect);
|
|
771
|
+
/**
|
|
772
|
+
* Update legend item position
|
|
773
|
+
* @param {Array} targetIdz Data ids
|
|
774
|
+
* @param {boolean} withTransition Whether or not to apply transition
|
|
775
|
+
* @param {object} posFn Position functions
|
|
776
|
+
* @private
|
|
777
|
+
*/
|
|
778
|
+
updateLegendItemPos(targetIdz: string[], withTransition: boolean, posFn): void {
|
|
779
|
+
const $$ = this;
|
|
780
|
+
const {config, $el: {legend}, $T} = $$;
|
|
781
|
+
const usePoint = config.legend_usePoint;
|
|
782
|
+
const legendType = config.legend_item_tile_type;
|
|
783
|
+
const isRectangle = legendType !== "circle";
|
|
685
784
|
|
|
686
785
|
if (usePoint) {
|
|
687
786
|
const tiles = legend.selectAll(`.${$LEGEND.legendItemPoint}`)
|
|
@@ -695,9 +794,9 @@ export default {
|
|
|
695
794
|
let y = "y";
|
|
696
795
|
let xOffset = 2;
|
|
697
796
|
let yOffset = 2.5;
|
|
698
|
-
let radius;
|
|
699
|
-
let width;
|
|
700
|
-
let height;
|
|
797
|
+
let radius = null;
|
|
798
|
+
let width = <number|null>null;
|
|
799
|
+
let height = <number|null>null;
|
|
701
800
|
|
|
702
801
|
if (nodeName === "circle") {
|
|
703
802
|
const size = pointR * 0.2;
|
|
@@ -716,33 +815,35 @@ export default {
|
|
|
716
815
|
}
|
|
717
816
|
|
|
718
817
|
d3Select(this)
|
|
719
|
-
.attr(x, d =>
|
|
720
|
-
.attr(y, d =>
|
|
818
|
+
.attr(x, d => posFn.x1Tile(d) + xOffset)
|
|
819
|
+
.attr(y, d => posFn.yTile(d) - yOffset)
|
|
721
820
|
.attr("r", radius)
|
|
722
821
|
.attr("width", width)
|
|
723
822
|
.attr("height", height);
|
|
724
823
|
});
|
|
725
824
|
} else {
|
|
726
|
-
const tiles = legend.selectAll(
|
|
825
|
+
const tiles = legend.selectAll(`.${$LEGEND.legendItemTile}`)
|
|
727
826
|
.data(targetIdz);
|
|
728
827
|
|
|
729
828
|
$T(tiles, withTransition)
|
|
730
|
-
.style("stroke",
|
|
731
|
-
.
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
829
|
+
.style("stroke", getLegendColor.bind($$))
|
|
830
|
+
.call(selection => {
|
|
831
|
+
if (legendType === "circle") {
|
|
832
|
+
selection
|
|
833
|
+
.attr("cx", d => {
|
|
834
|
+
const x2 = posFn.x2Tile(d);
|
|
835
|
+
|
|
836
|
+
return x2 - ((x2 - posFn.x1Tile(d)) / 2);
|
|
837
|
+
})
|
|
838
|
+
.attr("cy", posFn.yTile);
|
|
839
|
+
} else if (isRectangle) {
|
|
840
|
+
selection
|
|
841
|
+
.attr("x1", posFn.x1Tile)
|
|
842
|
+
.attr("y1", posFn.yTile)
|
|
843
|
+
.attr("x2", posFn.x2Tile)
|
|
844
|
+
.attr("y2", posFn.yTile);
|
|
845
|
+
}
|
|
846
|
+
});
|
|
741
847
|
}
|
|
742
|
-
|
|
743
|
-
// Update all to reflect change of legend
|
|
744
|
-
$$.updateLegendItemWidth(maxWidth);
|
|
745
|
-
$$.updateLegendItemHeight(maxHeight);
|
|
746
|
-
$$.updateLegendStep(step);
|
|
747
848
|
}
|
|
748
849
|
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import {area as d3Area} from "d3-shape";
|
|
6
6
|
import {select as d3Select} from "d3-selection";
|
|
7
7
|
import {$AREA, $CIRCLE, $LINE} from "../../config/classes";
|
|
8
|
-
import {getRandom
|
|
8
|
+
import {getRandom} from "../../module/util";
|
|
9
9
|
import type {IData, IDataRow} from "../data/IData";
|
|
10
10
|
import {d3Selection} from "../../../types";
|
|
11
11
|
|
|
@@ -21,46 +21,17 @@ export default {
|
|
|
21
21
|
.attr("class", $$.getClass("areas", true));
|
|
22
22
|
},
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if ($$.isAreaType(d) && defs.select(`#${id}`).empty()) {
|
|
32
|
-
const color = $$.color(d);
|
|
33
|
-
const {
|
|
34
|
-
x = [0, 0],
|
|
35
|
-
y = [0, 1],
|
|
36
|
-
stops = [[0, color, 1], [1, color, 0]]
|
|
37
|
-
} = config.area_linearGradient;
|
|
38
|
-
|
|
39
|
-
const linearGradient = defs.append("linearGradient")
|
|
40
|
-
.attr("id", `${id}`)
|
|
41
|
-
.attr("x1", x[0])
|
|
42
|
-
.attr("x2", x[1])
|
|
43
|
-
.attr("y1", y[0])
|
|
44
|
-
.attr("y2", y[1]);
|
|
45
|
-
|
|
46
|
-
stops.forEach(v => {
|
|
47
|
-
const stopColor = isFunction(v[1]) ? v[1].bind($$.api)(d.id) : v[1];
|
|
48
|
-
|
|
49
|
-
linearGradient.append("stop")
|
|
50
|
-
.attr("offset", v[0])
|
|
51
|
-
.attr("stop-color", stopColor || color)
|
|
52
|
-
.attr("stop-opacity", v[2]);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Update area color
|
|
26
|
+
* @param {object} d Data object
|
|
27
|
+
* @returns {string} Color string
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
58
30
|
updateAreaColor(d: IDataRow): string {
|
|
59
31
|
const $$ = this;
|
|
60
32
|
|
|
61
33
|
return $$.config.area_linearGradient ?
|
|
62
|
-
|
|
63
|
-
$$.color(d);
|
|
34
|
+
$$.getGradienColortUrl(d.id) : $$.color(d);
|
|
64
35
|
},
|
|
65
36
|
|
|
66
37
|
/**
|
|
@@ -74,7 +45,7 @@ export default {
|
|
|
74
45
|
const {config, state, $el, $T} = $$;
|
|
75
46
|
const $root = isSub ? $el.subchart : $el;
|
|
76
47
|
|
|
77
|
-
config.area_linearGradient && $$.
|
|
48
|
+
config.area_linearGradient && $$.updateLinearGradient();
|
|
78
49
|
|
|
79
50
|
const area = $root.main.selectAll(`.${$AREA.areas}`)
|
|
80
51
|
.selectAll(`.${$AREA.area}`)
|
|
@@ -71,11 +71,13 @@ export default {
|
|
|
71
71
|
*/
|
|
72
72
|
updateBar(withTransition: boolean, isSub = false): void {
|
|
73
73
|
const $$ = this;
|
|
74
|
-
const {$el, $T} = $$;
|
|
74
|
+
const {config, $el, $T} = $$;
|
|
75
75
|
const $root = isSub ? $el.subchart : $el;
|
|
76
76
|
const classBar = $$.getClass("bar", true);
|
|
77
77
|
const initialOpacity = $$.initialOpacity.bind($$);
|
|
78
78
|
|
|
79
|
+
config.bar_linearGradient && $$.updateLinearGradient();
|
|
80
|
+
|
|
79
81
|
const bar = $root.main.selectAll(`.${$BAR.bars}`)
|
|
80
82
|
.selectAll(`.${$BAR.bar}`)
|
|
81
83
|
.data($$.labelishData.bind($$));
|
|
@@ -86,17 +88,32 @@ export default {
|
|
|
86
88
|
|
|
87
89
|
$root.bar = bar.enter().append("path")
|
|
88
90
|
.attr("class", classBar)
|
|
89
|
-
.style("fill", $$.
|
|
91
|
+
.style("fill", $$.updateBarColor.bind($$))
|
|
90
92
|
.merge(bar)
|
|
91
93
|
.style("opacity", initialOpacity);
|
|
92
94
|
},
|
|
93
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Update bar color
|
|
98
|
+
* @param {object} d Data object
|
|
99
|
+
* @returns {string} Color string
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
102
|
+
updateBarColor(d: IDataRow): string {
|
|
103
|
+
const $$ = this;
|
|
104
|
+
const fn = $$.getStylePropValue($$.color);
|
|
105
|
+
|
|
106
|
+
return $$.config.bar_linearGradient ?
|
|
107
|
+
$$.getGradienColortUrl(d.id) : (fn ? fn(d) : null);
|
|
108
|
+
},
|
|
109
|
+
|
|
94
110
|
/**
|
|
95
111
|
* Redraw function
|
|
96
112
|
* @param {Function} drawFn Retuned function from .getDrawShape() => .generateDrawBar()
|
|
97
113
|
* @param {boolean} withTransition With or without transition
|
|
98
114
|
* @param {boolean} isSub Subchart draw
|
|
99
115
|
* @returns {Array}
|
|
116
|
+
* @private
|
|
100
117
|
*/
|
|
101
118
|
redrawBar(drawFn, withTransition?: boolean, isSub = false) {
|
|
102
119
|
const $$ = this;
|
|
@@ -105,7 +122,7 @@ export default {
|
|
|
105
122
|
return [
|
|
106
123
|
$$.$T(bar, withTransition, getRandom())
|
|
107
124
|
.attr("d", d => (isNumber(d.value) || $$.isBarRangeType(d)) && drawFn(d))
|
|
108
|
-
.style("fill", $$.
|
|
125
|
+
.style("fill", $$.updateBarColor.bind($$))
|
|
109
126
|
.style("opacity", null)
|
|
110
127
|
];
|
|
111
128
|
},
|