Commit 52b23c2b58f33287479fa1c942dac27c0de7e24e
1 parent
eeaa9c0c
闵行公交公司用的公交电子站牌页面组件
1、修正mhgj-eBusStop-line-chart组件bug(part没有正确的删除更新,主要修正model的generateSvgData方法,添加svgD3PartKey,svgPartIndex辅助d3绘制svg)
Showing
4 changed files
with
346 additions
and
145 deletions
front-end/h5/src/components/core/plugins/bsth/mhgj/chart/css/mhgj-eBusStop-line-chart.css
| ... | ... | @@ -31,6 +31,7 @@ svg.mhgj-eBusStop-line-chart { |
| 31 | 31 | font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | +/** 每个part对应一个g,和rect */ | |
| 34 | 35 | svg.mhgj-eBusStop-line-chart g.part { |
| 35 | 36 | } |
| 36 | 37 | svg.mhgj-eBusStop-line-chart g.part rect.main { |
| ... | ... | @@ -39,6 +40,7 @@ svg.mhgj-eBusStop-line-chart g.part rect.main { |
| 39 | 40 | stroke-width: 1; |
| 40 | 41 | Pointer-events: none; |
| 41 | 42 | } |
| 43 | +/** 每个part上部title相关 */ | |
| 42 | 44 | svg.mhgj-eBusStop-line-chart g.part rect.titleBackground { |
| 43 | 45 | fill: #7dc6fe; |
| 44 | 46 | stroke-width: 0; |
| ... | ... | @@ -46,12 +48,6 @@ svg.mhgj-eBusStop-line-chart g.part rect.titleBackground { |
| 46 | 48 | } |
| 47 | 49 | svg.mhgj-eBusStop-line-chart g.part g.titleBound { |
| 48 | 50 | } |
| 49 | -svg.mhgj-eBusStop-line-chart g.part g.titleBound image.CarIcon { /* 这个会先添加,之后被g.CarIcon替换,具体参见代码 */ | |
| 50 | - /** 第一个part内部会使用 */ | |
| 51 | -} | |
| 52 | -svg.mhgj-eBusStop-line-chart g.part g.titleBound g.CarIcon { /* 和carSvgComp.js里的属性对应 */ | |
| 53 | - /** 第一个part内部会使用 */ | |
| 54 | -} | |
| 55 | 51 | svg.mhgj-eBusStop-line-chart g.part g.titleBound text.title { |
| 56 | 52 | font-size: 60px; |
| 57 | 53 | font-weight: 900; |
| ... | ... | @@ -60,8 +56,15 @@ svg.mhgj-eBusStop-line-chart g.part g.titleBound text.title { |
| 60 | 56 | Pointer-events: none; |
| 61 | 57 | } |
| 62 | 58 | |
| 63 | -/** 每个part的下半部分差异较大,分开css */ | |
| 64 | -/** part1用 */ | |
| 59 | +/** part1 */ | |
| 60 | +/** part1相对于其他part,上部分title多了图标 */ | |
| 61 | +svg.mhgj-eBusStop-line-chart g.part g.titleBound image.part1.CarIcon { /* 这个会先添加,之后被g.CarIcon替换,具体参见代码 */ | |
| 62 | + /** 第一个part内部会使用 */ | |
| 63 | +} | |
| 64 | +svg.mhgj-eBusStop-line-chart g.part g.titleBound g.part1.CarIcon { /* 和carSvgComp.js里的属性对应 */ | |
| 65 | + /** 第一个part内部会使用 */ | |
| 66 | +} | |
| 67 | + | |
| 65 | 68 | svg.mhgj-eBusStop-line-chart g.part g.content1Bound { |
| 66 | 69 | } |
| 67 | 70 | svg.mhgj-eBusStop-line-chart g.part g.content1Bound text.content1 { |
| ... | ... | @@ -80,7 +83,8 @@ svg.mhgj-eBusStop-line-chart g.part g.content2Bound text.content2 { |
| 80 | 83 | text-shadow: 0 0 2px #dadada; |
| 81 | 84 | Pointer-events: none; |
| 82 | 85 | } |
| 83 | -/** part2用 */ | |
| 86 | + | |
| 87 | +/** part2 */ | |
| 84 | 88 | svg.mhgj-eBusStop-line-chart g.part path.bound { |
| 85 | 89 | stroke: rgb(0, 0, 0); |
| 86 | 90 | stroke-width: 1; |
| ... | ... | @@ -170,8 +174,7 @@ svg.mhgj-eBusStop-line-chart g.part g.content7Bound2 text.content7_2_right { |
| 170 | 174 | text-shadow: 0 0 2px #dadada; |
| 171 | 175 | Pointer-events: none; |
| 172 | 176 | } |
| 173 | - | |
| 174 | -/** part3用 */ | |
| 177 | +/** part3 */ | |
| 175 | 178 | svg.mhgj-eBusStop-line-chart g.part g.contentAllBound { |
| 176 | 179 | } |
| 177 | 180 | svg.mhgj-eBusStop-line-chart g.part g.contentAllBound text.content { | ... | ... |
front-end/h5/src/components/core/plugins/bsth/mhgj/chart/mhgj-eBusStop-line-chart.js
| 1 | -/** | |
| 2 | - * 自定义线路模拟图组件(闵行公交电子站牌使用) | |
| 3 | - */ | |
| 4 | 1 | import Vue from 'vue' |
| 5 | 2 | |
| 6 | 3 | import moment from 'moment' |
| ... | ... | @@ -288,6 +285,7 @@ export default { |
| 288 | 285 | // if (!Utils.objectEquals(currentVal, oldVal)) { |
| 289 | 286 | // self.refreshSvg() |
| 290 | 287 | // } |
| 288 | + console.log('refreshSvg()') | |
| 291 | 289 | self.refreshSvg() |
| 292 | 290 | }, |
| 293 | 291 | deep: true |
| ... | ... | @@ -609,10 +607,10 @@ export default { |
| 609 | 607 | .domain([0, 1]) // 定义域 |
| 610 | 608 | .range([partUpPadding, height - partDownPadding]) // 值域 |
| 611 | 609 | |
| 612 | - // ------------ 1、添加g元素 ----------------// | |
| 610 | + // ------------ 1、添加g元素 ---------------- // | |
| 613 | 611 | let itemsUpdate = svg.selectAll('g.part') |
| 614 | 612 | .data(svgData, function (d) { |
| 615 | - return d.text1 | |
| 613 | + return d.svgD3PartKey | |
| 616 | 614 | }) |
| 617 | 615 | let itemsEnter = itemsUpdate |
| 618 | 616 | let itemsExit = itemsUpdate.exit() |
| ... | ... | @@ -620,69 +618,68 @@ export default { |
| 620 | 618 | itemsExit.remove() |
| 621 | 619 | itemsEnter = itemsEnter.enter().append('g') |
| 622 | 620 | .classed('part', true) |
| 623 | - .attr('transform', function (d, i) { | |
| 621 | + .attr('transform', function (d) { | |
| 624 | 622 | let x, y |
| 625 | - if (i === 0) { // part1 | |
| 623 | + if (d.svgPartIndex === 1) { // part1 | |
| 626 | 624 | x = xScale(0) |
| 627 | - } else if (i === 1) { // part2 | |
| 625 | + } else if (d.svgPartIndex === 2) { // part2 | |
| 628 | 626 | x = xScale(0) + partWidth + partBetweenPadding |
| 629 | - } else if (i === 2) { // part3 | |
| 627 | + } else if (d.svgPartIndex === 3) { // part3 | |
| 630 | 628 | x = xScale(0) + partWidth * 2 + partBetweenPadding * 2 |
| 631 | 629 | } |
| 632 | 630 | y = yScale(0) |
| 633 | 631 | return `translate(${x}, ${y})` |
| 634 | 632 | }) |
| 635 | 633 | itemsUpdate |
| 636 | - .attr('transform', function (d, i) { | |
| 634 | + .attr('transform', function (d) { | |
| 637 | 635 | let x, y |
| 638 | - if (i === 0) { // part1 | |
| 636 | + if (d.svgPartIndex === 1) { // part1 | |
| 639 | 637 | x = xScale(0) |
| 640 | - } else if (i === 1) { // part2 | |
| 638 | + } else if (d.svgPartIndex === 2) { // part2 | |
| 641 | 639 | x = xScale(0) + partWidth + partBetweenPadding |
| 642 | - } else if (i === 2) { // part3 | |
| 640 | + } else if (d.svgPartIndex === 3) { // part3 | |
| 643 | 641 | x = xScale(0) + partWidth * 2 + partBetweenPadding * 2 |
| 644 | 642 | } |
| 645 | 643 | y = yScale(0) |
| 646 | 644 | return `translate(${x}, ${y})` |
| 647 | 645 | }) |
| 648 | 646 | |
| 649 | - // ------------ 2、添加各个part的上半部分 ----------------// | |
| 650 | - // ------------- 2-1、添加每个part最外部的rect(以下)------------// | |
| 647 | + // ------------ 1-1、添加g rect.main 元素 ---------------- // | |
| 651 | 648 | itemsEnter.append('rect') |
| 652 | 649 | .classed('main', true) |
| 653 | - .style('fill', function (d, i) { | |
| 654 | - if (i === 0) { | |
| 650 | + .style('fill', function (d) { | |
| 651 | + if (d.svgPartIndex === 1) { | |
| 655 | 652 | return self.part1_background_color |
| 656 | - } else if (i === 1) { | |
| 653 | + } else if (d.svgPartIndex === 2) { | |
| 657 | 654 | return self.part2_background_color |
| 658 | - } else if (i === 2) { | |
| 655 | + } else if (d.svgPartIndex === 3) { | |
| 659 | 656 | return self.part3_background_color |
| 660 | 657 | } else { |
| 661 | 658 | return '#FFFFFF' |
| 662 | 659 | } |
| 663 | 660 | }) |
| 664 | - .style('stroke-width', function (d, i) { | |
| 665 | - if (i === 0) { // part1没有边框 | |
| 661 | + .style('stroke-width', function (d) { | |
| 662 | + if (d.svgPartIndex === 1) { // part1没有边框 | |
| 666 | 663 | return self.part1_border_size |
| 667 | - } else if (i === 1) { | |
| 664 | + } else if (d.svgPartIndex === 2) { | |
| 668 | 665 | return self.part2_border_size |
| 669 | - } else if (i === 2) { | |
| 666 | + } else if (d.svgPartIndex === 3) { | |
| 670 | 667 | return self.part3_border_size |
| 671 | 668 | } else { |
| 672 | 669 | return 0 |
| 673 | 670 | } |
| 674 | 671 | }) |
| 675 | - .attr('stroke-dasharray', function (d, i) { | |
| 676 | - if (i === 0) { // part1没有边框 | |
| 672 | + .attr('stroke-dasharray', function (d) { | |
| 673 | + if (d.svgPartIndex === 1) { // part1没有边框 | |
| 677 | 674 | return null |
| 678 | 675 | } else { // part2、part3的边框样式为虚线 |
| 679 | 676 | return "4,2" |
| 680 | 677 | } |
| 681 | 678 | }) |
| 682 | - .attr('width', function (d, i) { | |
| 679 | + .attr('width', function (d) { | |
| 683 | 680 | // 三个part都存在,同宽度,part3不存在时,part2占用2个宽度 |
| 684 | 681 | // 宽度计算参考 0、前置计算准备 |
| 685 | - if (i === 1 ) { // part2 | |
| 682 | + if (d.svgPartIndex === 2 ) { // part2 | |
| 686 | 683 | if (showType === 0 || showType === 1) { |
| 687 | 684 | return partWidth |
| 688 | 685 | } else if (showType === 2 || showType === 3) { |
| ... | ... | @@ -696,8 +693,8 @@ export default { |
| 696 | 693 | }) |
| 697 | 694 | .attr('height', partHeight + 'px') |
| 698 | 695 | itemsUpdate.select('rect.main') |
| 699 | - .attr('width', function (d, i) { | |
| 700 | - if (i === 1 ) { // part2 | |
| 696 | + .attr('width', function (d) { | |
| 697 | + if (d.svgPartIndex === 2) { // part2 | |
| 701 | 698 | if (showType === 0 || showType === 1) { |
| 702 | 699 | return partWidth |
| 703 | 700 | } else if (showType === 2 || showType === 3) { |
| ... | ... | @@ -710,13 +707,13 @@ export default { |
| 710 | 707 | } |
| 711 | 708 | }) |
| 712 | 709 | .attr('height', partHeight + 'px') |
| 713 | - // ------------- 2-1、添加每个part最外部的rect(以上)------------// | |
| 714 | 710 | |
| 711 | + // ------------ 2、添加各个part的上半部分 ----------------// | |
| 715 | 712 | // ------------- 2-1、添加每个part上部放置title的外部rect(以下)------------// |
| 716 | 713 | itemsEnter.append('rect') |
| 717 | 714 | .classed('titleBackground', true) |
| 718 | - .attr('width', function (d, i) { | |
| 719 | - if (i === 1) { | |
| 715 | + .attr('width', function (d) { | |
| 716 | + if (d.svgPartIndex === 2) { // part2 | |
| 720 | 717 | if (showType === 0 || showType === 1) { |
| 721 | 718 | return partWidth - 2 |
| 722 | 719 | } else if (showType === 2 || showType === 3) { |
| ... | ... | @@ -728,27 +725,27 @@ export default { |
| 728 | 725 | return partWidth - 2 |
| 729 | 726 | } |
| 730 | 727 | }) |
| 731 | - .attr('height', function (d, i) { | |
| 732 | - if (i === 0) { // part1的title外部不需要rect | |
| 728 | + .attr('height', function (d) { | |
| 729 | + if (d.svgPartIndex === 1) { // part1的title外部不需要rect | |
| 733 | 730 | return 0 |
| 734 | 731 | } else { |
| 735 | 732 | return partTitleRectHeight |
| 736 | 733 | } |
| 737 | 734 | }) |
| 738 | - .style('fill', function (d, i) { | |
| 739 | - if (i === 0) { | |
| 735 | + .style('fill', function (d) { | |
| 736 | + if (d.svgPartIndex === 1) { | |
| 740 | 737 | return self.part1_background_color |
| 741 | - } else if (i === 1) { | |
| 738 | + } else if (d.svgPartIndex === 2) { | |
| 742 | 739 | return self.part2_title1_background_color |
| 743 | - } else if (i === 2) { | |
| 740 | + } else if (d.svgPartIndex === 3) { | |
| 744 | 741 | return self.part3_title1_background_color |
| 745 | 742 | } |
| 746 | 743 | }) |
| 747 | 744 | .attr('x', 1) |
| 748 | 745 | .attr('y', 1) |
| 749 | 746 | itemsUpdate.select('rect.titleBackground') |
| 750 | - .attr('width', function (d, i) { | |
| 751 | - if (i === 1) { | |
| 747 | + .attr('width', function (d) { | |
| 748 | + if (d.svgPartIndex === 2) { // part2 | |
| 752 | 749 | if (showType === 0 || showType === 1) { |
| 753 | 750 | return partWidth - 2 |
| 754 | 751 | } else if (showType === 2 || showType === 3) { |
| ... | ... | @@ -767,8 +764,9 @@ export default { |
| 767 | 764 | .classed('titleBound', true) |
| 768 | 765 | .attr('transform', 'translate(10, 10)') |
| 769 | 766 | itemsEnter.select('g.titleBound') // 添加part1上部分title中的图标 |
| 770 | - .select(function (d, i) {return i === 0 ? this : null}) | |
| 767 | + .select(function (d) {return d.svgPartIndex === 1 ? this : null}) | |
| 771 | 768 | .append('image') |
| 769 | + .classed('part1', true) | |
| 772 | 770 | .classed('CarIcon', true) |
| 773 | 771 | // 需要将svg图标代码嵌入组件代码中,避免打包engine包含外部svg,所以把svg图标组件话,动态添加 |
| 774 | 772 | // .attr('href', CarIcon) |
| ... | ... | @@ -779,9 +777,9 @@ export default { |
| 779 | 777 | itemsEnter.select('g.titleBound') // 添加所有part上部分title中的text |
| 780 | 778 | .append('text') |
| 781 | 779 | .classed('title', true) |
| 782 | - .text(function (d, i) { | |
| 780 | + .text(function (d) { | |
| 783 | 781 | // 动态添加CarIcon组件替换之前添加的image |
| 784 | - if (i === 0) { | |
| 782 | + if (d.svgPartIndex === 1) { | |
| 785 | 783 | let car_g = svg.select('g.titleBound g.CarIcon') |
| 786 | 784 | if (car_g.empty()) { |
| 787 | 785 | // 动态创建CarIcon组件 |
| ... | ... | @@ -790,53 +788,54 @@ export default { |
| 790 | 788 | // console.log(self.part1_line_icon_width) |
| 791 | 789 | new CarIconClass({ |
| 792 | 790 | propsData: { |
| 793 | - cls: 'CarIcon' | |
| 791 | + cls: 'part1 CarIcon' | |
| 794 | 792 | }, |
| 795 | 793 | data() { |
| 796 | 794 | return self.carIconComData |
| 797 | 795 | } |
| 798 | - }).$mount(svg.select('g.titleBound image.CarIcon').node()) | |
| 796 | + }).$mount(svg.select('g.titleBound image.part1.CarIcon').node()) | |
| 799 | 797 | } |
| 800 | 798 | } |
| 799 | + | |
| 801 | 800 | // 添加文本 |
| 802 | - if (i === 0) { | |
| 801 | + if (d.svgPartIndex === 1) { | |
| 803 | 802 | return d.lineName |
| 804 | - } else if (i === 1) { | |
| 803 | + } else if (d.svgPartIndex === 2) { | |
| 805 | 804 | return d.text1 |
| 806 | - } else if (i === 2) { | |
| 805 | + } else if (d.svgPartIndex === 3) { | |
| 807 | 806 | return d.text1 |
| 808 | 807 | } else { |
| 809 | 808 | return '-' |
| 810 | 809 | } |
| 811 | 810 | }) |
| 812 | - .style('font-size', function (d, i) { | |
| 813 | - if (i === 0) { | |
| 811 | + .style('font-size', function (d) { | |
| 812 | + if (d.svgPartIndex === 1) { | |
| 814 | 813 | return self.part1_line_name_font_size |
| 815 | - } else if (i === 1) { | |
| 814 | + } else if (d.svgPartIndex === 2) { | |
| 816 | 815 | return self.part2_title1_font_size |
| 817 | - } else if (i === 2) { | |
| 816 | + } else if (d.svgPartIndex === 3) { | |
| 818 | 817 | return self.part3_title1_font_size |
| 819 | 818 | } |
| 820 | 819 | }) |
| 821 | - .style('fill', function (d, i) { | |
| 822 | - if (i === 0) { | |
| 820 | + .style('fill', function (d) { | |
| 821 | + if (d.svgPartIndex === 1) { | |
| 823 | 822 | return self.part1_line_name_font_color |
| 824 | - } else if (i === 1) { | |
| 823 | + } else if (d.svgPartIndex === 2) { | |
| 825 | 824 | return self.part2_title1_font_color |
| 826 | - } else if (i === 2) { | |
| 825 | + } else if (d.svgPartIndex === 3) { | |
| 827 | 826 | return self.part3_title1_font_color |
| 828 | 827 | } |
| 829 | 828 | }) |
| 830 | - .attr('x', function (d, i) { | |
| 831 | - if (i === 0) { | |
| 829 | + .attr('x', function (d) { | |
| 830 | + if (d.svgPartIndex === 1) { | |
| 832 | 831 | return self.part1_line_icon_width + 10 |
| 833 | 832 | } else { |
| 834 | 833 | return 0 |
| 835 | 834 | } |
| 836 | 835 | }) |
| 837 | - .attr('y', function (d, i) { | |
| 838 | - if (i === 0) { | |
| 839 | - let icon_bounds = svg.select('g.CarIcon').node().getBBox(); | |
| 836 | + .attr('y', function (d) { | |
| 837 | + if (d.svgPartIndex === 1) { | |
| 838 | + let icon_bounds = svg.select('g.part1.CarIcon').node().getBBox(); | |
| 840 | 839 | let text_bounds = this.getBBox(); |
| 841 | 840 | let temp = (text_bounds.height - icon_bounds.height) / 2 |
| 842 | 841 | if (temp > 0) { |
| ... | ... | @@ -849,20 +848,44 @@ export default { |
| 849 | 848 | return 0 |
| 850 | 849 | } |
| 851 | 850 | }) |
| 851 | + itemsEnter.select('g.titleBound') | |
| 852 | + .attr('transform', function (d) { | |
| 853 | + let rect_bounds = svg.select('g.part:nth-child(' + d.svgPartIndex +') rect.main').node().getBBox() | |
| 854 | + let title_bounds = this.getBBox() | |
| 855 | + let dx = 1 | |
| 856 | + let dy = 1 | |
| 857 | + | |
| 858 | + if (d.svgPartIndex === 1) { // part1标题部分相对于rect.main的上半部分居中 | |
| 859 | + dx = (rect_bounds.width - title_bounds.width) / 2 - title_bounds.x | |
| 860 | + dy = (rect_bounds.height / 2 - title_bounds.height) / 2 - title_bounds.y | |
| 861 | + } else { // part2,part3标题部分相对于rect.main的partTitleRectHeight高度居中 | |
| 862 | + dx = (rect_bounds.width - title_bounds.width) / 2 - title_bounds.x | |
| 863 | + dy = (partTitleRectHeight - title_bounds.height) / 2 - title_bounds.y | |
| 864 | + } | |
| 865 | + if (dx < 0) { | |
| 866 | + dx = 1 | |
| 867 | + } | |
| 868 | + if (dy < 0) { | |
| 869 | + dy = 1 | |
| 870 | + } | |
| 871 | + | |
| 872 | + return `translate(${dx}, ${dy})` | |
| 873 | + }) | |
| 874 | + | |
| 852 | 875 | // itemsUpdate.select('g.titleBound image.carIcon') |
| 853 | 876 | // .attr('width', self.part1_line_icon_width) // 指定宽度 |
| 854 | 877 | // .attr('height', self.part1_line_icon_height) // 指定高度 |
| 855 | 878 | itemsUpdate.select('g.titleBound text.title') |
| 856 | - .attr('x', function (d, i) { | |
| 857 | - if (i === 0) { | |
| 879 | + .attr('x', function (d) { | |
| 880 | + if (d.svgPartIndex === 1) { | |
| 858 | 881 | return self.part1_line_icon_width + 10 |
| 859 | 882 | } else { |
| 860 | 883 | return 0 |
| 861 | 884 | } |
| 862 | 885 | }) |
| 863 | - .attr('y', function (d, i) { | |
| 864 | - if (i === 0) { | |
| 865 | - let icon_bounds = svg.select('g.CarIcon').node().getBBox(); | |
| 886 | + .attr('y', function (d) { | |
| 887 | + if (d.svgPartIndex === 1) { | |
| 888 | + let icon_bounds = svg.select('g.part1.CarIcon').node().getBBox(); | |
| 866 | 889 | let text_bounds = this.getBBox(); |
| 867 | 890 | let temp = (text_bounds.height - icon_bounds.height) / 2 |
| 868 | 891 | if (temp > 0) { |
| ... | ... | @@ -876,13 +899,13 @@ export default { |
| 876 | 899 | } |
| 877 | 900 | }) |
| 878 | 901 | itemsUpdate.select('g.titleBound') |
| 879 | - .attr('transform', function (d, i) { | |
| 880 | - let rect_bounds = svg.select('g.part:nth-child(' + (i + 1) +') rect.main').node().getBBox() | |
| 902 | + .attr('transform', function (d) { | |
| 903 | + let rect_bounds = svg.select('g.part:nth-child(' + d.svgPartIndex +') rect.main').node().getBBox() | |
| 881 | 904 | let title_bounds = this.getBBox() |
| 882 | 905 | let dx = 1 |
| 883 | 906 | let dy = 1 |
| 884 | 907 | |
| 885 | - if (i === 0) { // part1标题部分相对于rect.main的上半部分居中 | |
| 908 | + if (d.svgPartIndex === 1) { // part1标题部分相对于rect.main的上半部分居中 | |
| 886 | 909 | dx = (rect_bounds.width - title_bounds.width) / 2 - title_bounds.x |
| 887 | 910 | dy = (rect_bounds.height / 2 - title_bounds.height) / 2 - title_bounds.y |
| 888 | 911 | } else { // part2,part3标题部分相对于rect.main的partTitleRectHeight高度居中 |
| ... | ... | @@ -895,14 +918,15 @@ export default { |
| 895 | 918 | if (dy < 0) { |
| 896 | 919 | dy = 1 |
| 897 | 920 | } |
| 921 | + | |
| 898 | 922 | return `translate(${dx}, ${dy})` |
| 899 | 923 | }) |
| 900 | 924 | // ------------- 2-2、添加每个part上部title(以上)------------// |
| 901 | 925 | |
| 902 | - // ------------ 3、添加part的下半部分 ----------------// | |
| 926 | + // ------------ 3、添加每个part的下半部分 ----------------// | |
| 903 | 927 | // ------------ 3-1、part1部分 -------------// |
| 904 | - itemsEnter.select(function (d, i) { | |
| 905 | - return i === 0 ? this : null | |
| 928 | + itemsEnter.select(function (d) { | |
| 929 | + return d.svgPartIndex === 1 ? this : null | |
| 906 | 930 | }).append('g') |
| 907 | 931 | .classed('content1Bound', true) |
| 908 | 932 | .attr('transform', 'translate(10, 10)') |
| ... | ... | @@ -918,9 +942,26 @@ export default { |
| 918 | 942 | .attr('y', 0) |
| 919 | 943 | .style('font-size', self.part1_terminal_stop_font_size) |
| 920 | 944 | .style('fill', self.part1_terminal_stop_font_color) |
| 945 | + itemsEnter.select('g.content1Bound') | |
| 946 | + .attr('transform', function (d) { | |
| 947 | + if (d.svgPartIndex === 1) { // 相对于rect.main的下半部分的上二分之一居中(其中-5表示向上偏离5) | |
| 948 | + let rect_part1_bounds = svg.select('rect.main:nth-child(1)').node().getBBox() | |
| 949 | + let g_content1_bounds = this.getBBox() | |
| 950 | + let dx = (rect_part1_bounds.width - g_content1_bounds.width) / 2 - g_content1_bounds.x | |
| 951 | + let dy = (rect_part1_bounds.height / 4 - g_content1_bounds.height) - g_content1_bounds.y | |
| 952 | + + rect_part1_bounds.height / 2 - 5 | |
| 953 | + if (dx < 0) { | |
| 954 | + dx = 1 | |
| 955 | + } | |
| 956 | + if (dy < 0) { | |
| 957 | + dy = 1 | |
| 958 | + } | |
| 959 | + return `translate(${dx}, ${dy})` | |
| 960 | + } | |
| 961 | + }) | |
| 921 | 962 | itemsUpdate.select('g.content1Bound') |
| 922 | - .attr('transform', function (d, i) { | |
| 923 | - if (i === 0) { // 相对于rect.main的下半部分的上二分之一居中(其中-5表示向上偏离5) | |
| 963 | + .attr('transform', function (d) { | |
| 964 | + if (d.svgPartIndex === 1) { // 相对于rect.main的下半部分的上二分之一居中(其中-5表示向上偏离5) | |
| 924 | 965 | let rect_part1_bounds = svg.select('rect.main:nth-child(1)').node().getBBox() |
| 925 | 966 | let g_content1_bounds = this.getBBox() |
| 926 | 967 | let dx = (rect_part1_bounds.width - g_content1_bounds.width) / 2 - g_content1_bounds.x |
| ... | ... | @@ -936,8 +977,8 @@ export default { |
| 936 | 977 | } |
| 937 | 978 | }) |
| 938 | 979 | |
| 939 | - itemsEnter.select(function (d, i) { | |
| 940 | - return i === 0 ? this : null | |
| 980 | + itemsEnter.select(function (d) { | |
| 981 | + return d.svgPartIndex === 1 ? this : null | |
| 941 | 982 | }).append('g') |
| 942 | 983 | .classed('content2Bound', true) |
| 943 | 984 | .attr('transform', 'translate(10, 10)') |
| ... | ... | @@ -953,9 +994,26 @@ export default { |
| 953 | 994 | .attr('y', 0) |
| 954 | 995 | .style('font-size', self.part1_terminal_stop_font_size) |
| 955 | 996 | .style('fill', self.part1_terminal_stop_font_color) |
| 997 | + itemsEnter.select('g.content2Bound') | |
| 998 | + .attr('transform', function (d) { | |
| 999 | + if (d.svgPartIndex === 1) { // 相对于rect.main的下半部分的下二分之一居中 | |
| 1000 | + let rect_part1_bounds = svg.select('rect.main:nth-child(1)').node().getBBox() | |
| 1001 | + let g_content1_bounds = this.getBBox() | |
| 1002 | + let dx = (rect_part1_bounds.width - g_content1_bounds.width) / 2 - g_content1_bounds.x | |
| 1003 | + let dy = - g_content1_bounds.y | |
| 1004 | + + rect_part1_bounds.height * 0.75 | |
| 1005 | + if (dx < 0) { | |
| 1006 | + dx = 1 | |
| 1007 | + } | |
| 1008 | + if (dy < 0) { | |
| 1009 | + dy = 1 | |
| 1010 | + } | |
| 1011 | + return `translate(${dx}, ${dy})` | |
| 1012 | + } | |
| 1013 | + }) | |
| 956 | 1014 | itemsUpdate.select('g.content2Bound') |
| 957 | - .attr('transform', function (d, i) { | |
| 958 | - if (i === 0) { // 相对于rect.main的下半部分的下二分之一居中 | |
| 1015 | + .attr('transform', function (d) { | |
| 1016 | + if (d.svgPartIndex === 1) { // 相对于rect.main的下半部分的下二分之一居中 | |
| 959 | 1017 | let rect_part1_bounds = svg.select('rect.main:nth-child(1)').node().getBBox() |
| 960 | 1018 | let g_content1_bounds = this.getBBox() |
| 961 | 1019 | let dx = (rect_part1_bounds.width - g_content1_bounds.width) / 2 - g_content1_bounds.x |
| ... | ... | @@ -974,8 +1032,8 @@ export default { |
| 974 | 1032 | // ------------ 3-2、part2部分 -------------// |
| 975 | 1033 | // ------------ 3-2-1、当part3存在时,part2中间纵向添加一条虚线(以下)---------- // |
| 976 | 1034 | let boundLineFun = d3.line() |
| 977 | - itemsEnter.select(function (d, i) { | |
| 978 | - return i === 1 && (showType === 0 || showType === 1) ? this : null | |
| 1035 | + itemsEnter.select(function (d) { | |
| 1036 | + return d.svgPartIndex === 2 && (showType === 0 || showType === 1) ? this : null | |
| 979 | 1037 | }).append('path') |
| 980 | 1038 | .classed('bound', true) |
| 981 | 1039 | .attr('d', function () { |
| ... | ... | @@ -992,10 +1050,9 @@ export default { |
| 992 | 1050 | ]) |
| 993 | 1051 | }) |
| 994 | 1052 | // ------------ 3-2-1、当part3存在时,part2中间纵向添加一条虚线(以上)---------- // |
| 995 | - | |
| 996 | 1053 | // ------------ 3-2-2、当part3存在时,part2纵向中间左侧添加内容标题(以下)----------- // |
| 997 | - itemsEnter.select(function (d, i) { | |
| 998 | - return i === 1 ? this : null | |
| 1054 | + itemsEnter.select(function (d) { | |
| 1055 | + return d.svgPartIndex === 2 ? this : null | |
| 999 | 1056 | }).append('g') |
| 1000 | 1057 | .classed('content3Bound', true) |
| 1001 | 1058 | .attr('transform', 'translate(10, 10)') |
| ... | ... | @@ -1010,9 +1067,25 @@ export default { |
| 1010 | 1067 | }) |
| 1011 | 1068 | .style('font-size', self.part2_title2_font_size) |
| 1012 | 1069 | .style('fill', self.part2_title2_font_color) |
| 1070 | + itemsEnter.select('g.content3Bound') | |
| 1071 | + .attr('transform', function (d) { | |
| 1072 | + if (d.svgPartIndex === 2) { // x方向居中对齐,y方向顶部对齐 | |
| 1073 | + let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() | |
| 1074 | + let g_bounds = this.getBBox() | |
| 1075 | + let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x | |
| 1076 | + let dy = partTitleRectHeight - g_bounds.y | |
| 1077 | + if (dx < 0) { | |
| 1078 | + dx = 1 | |
| 1079 | + } | |
| 1080 | + if (dy < 0) { | |
| 1081 | + dy = 1 | |
| 1082 | + } | |
| 1083 | + return `translate(${dx}, ${dy})` | |
| 1084 | + } | |
| 1085 | + }) | |
| 1013 | 1086 | itemsUpdate.select('g.content3Bound') |
| 1014 | - .attr('transform', function (d, i) { | |
| 1015 | - if (i === 1) { // x方向居中对齐,y方向顶部对齐 | |
| 1087 | + .attr('transform', function (d) { | |
| 1088 | + if (d.svgPartIndex === 2) { // x方向居中对齐,y方向顶部对齐 | |
| 1016 | 1089 | let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() |
| 1017 | 1090 | let g_bounds = this.getBBox() |
| 1018 | 1091 | let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x |
| ... | ... | @@ -1027,10 +1100,9 @@ export default { |
| 1027 | 1100 | } |
| 1028 | 1101 | }) |
| 1029 | 1102 | // ------------ 3-2-2、当part3存在时,part2纵向中间左侧添加内容标题(以上)----------- // |
| 1030 | - | |
| 1031 | 1103 | // ------------ 3-2-3、当part3存在时,part2纵向中间右侧添加内容标题(以下)----------- // |
| 1032 | - itemsEnter.select(function (d, i) { | |
| 1033 | - return i === 1 ? this : null | |
| 1104 | + itemsEnter.select(function (d) { | |
| 1105 | + return d.svgPartIndex === 2 ? this : null | |
| 1034 | 1106 | }).append('g') |
| 1035 | 1107 | .classed('content4Bound', true) |
| 1036 | 1108 | .attr('transform', 'translate(10, 10)') |
| ... | ... | @@ -1045,9 +1117,26 @@ export default { |
| 1045 | 1117 | }) |
| 1046 | 1118 | .style('font-size', self.part2_title2_font_size) |
| 1047 | 1119 | .style('fill', self.part2_title2_font_color) |
| 1120 | + itemsEnter.select('g.content4Bound') | |
| 1121 | + .attr('transform', function (d) { | |
| 1122 | + if (d.svgPartIndex === 2) { // x方向居中对齐,y方向顶部对齐 | |
| 1123 | + let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() | |
| 1124 | + let g_bounds = this.getBBox() | |
| 1125 | + let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x | |
| 1126 | + + rect_part2_bounds.width / 2 | |
| 1127 | + let dy = 48 - g_bounds.y | |
| 1128 | + if (dx < 0) { | |
| 1129 | + dx = 1 | |
| 1130 | + } | |
| 1131 | + if (dy < 0) { | |
| 1132 | + dy = 1 | |
| 1133 | + } | |
| 1134 | + return `translate(${dx},${dy})` | |
| 1135 | + } | |
| 1136 | + }) | |
| 1048 | 1137 | itemsUpdate.select('g.content4Bound') |
| 1049 | - .attr('transform', function (d, i) { | |
| 1050 | - if (i === 1) { // x方向居中对齐,y方向顶部对齐 | |
| 1138 | + .attr('transform', function (d) { | |
| 1139 | + if (d.svgPartIndex === 2) { // x方向居中对齐,y方向顶部对齐 | |
| 1051 | 1140 | let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() |
| 1052 | 1141 | let g_bounds = this.getBBox() |
| 1053 | 1142 | let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x |
| ... | ... | @@ -1063,10 +1152,9 @@ export default { |
| 1063 | 1152 | } |
| 1064 | 1153 | }) |
| 1065 | 1154 | // ------------ 3-2-3、当part3存在时,part2纵向中间右侧添加内容标题(以上)----------- // |
| 1066 | - | |
| 1067 | 1155 | // ------------ 3-2-3、当part3存在时,part2纵向中间左侧添加内容(以下)----------- // |
| 1068 | - itemsEnter.select(function (d, i) { | |
| 1069 | - return i === 1 ? this : null | |
| 1156 | + itemsEnter.select(function (d) { | |
| 1157 | + return d.svgPartIndex === 2 ? this : null | |
| 1070 | 1158 | }).append('g') |
| 1071 | 1159 | .classed('content5Bound', true) |
| 1072 | 1160 | .attr('transform', 'translate(10, 10)') |
| ... | ... | @@ -1161,9 +1249,26 @@ export default { |
| 1161 | 1249 | let left_bound = svg.select('text.content5_left').node().getBBox() |
| 1162 | 1250 | return left_bound.width + 2 |
| 1163 | 1251 | }) |
| 1252 | + itemsEnter.select('g.content5Bound') | |
| 1253 | + .attr('transform', function (d) { | |
| 1254 | + if (d.svgPartIndex === 2) { | |
| 1255 | + let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() | |
| 1256 | + let g_bounds = this.getBBox() | |
| 1257 | + let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x | |
| 1258 | + let dy = (rect_part2_bounds.height / 2 - g_bounds.height) / 2 - g_bounds.y | |
| 1259 | + + rect_part2_bounds.height / 2 | |
| 1260 | + if (dx < 0) { | |
| 1261 | + dx = 1 | |
| 1262 | + } | |
| 1263 | + if (dy < 0) { | |
| 1264 | + dy = 1 | |
| 1265 | + } | |
| 1266 | + return `translate(${dx}, ${dy})` | |
| 1267 | + } | |
| 1268 | + }) | |
| 1164 | 1269 | |
| 1165 | - itemsUpdate.select(function (d, i) { | |
| 1166 | - return i === 1 ? this : null | |
| 1270 | + itemsUpdate.select(function (d) { | |
| 1271 | + return d.svgPartIndex === 2 ? this : null | |
| 1167 | 1272 | }).select('g.content5Bound text.content5_left') |
| 1168 | 1273 | .text(function (d) { |
| 1169 | 1274 | if (showType === 0) { |
| ... | ... | @@ -1192,8 +1297,8 @@ export default { |
| 1192 | 1297 | return "todo" |
| 1193 | 1298 | } |
| 1194 | 1299 | }) |
| 1195 | - itemsUpdate.select(function (d, i) { | |
| 1196 | - return i === 1 ? this : null | |
| 1300 | + itemsUpdate.select(function (d) { | |
| 1301 | + return d.svgPartIndex === 2 ? this : null | |
| 1197 | 1302 | }).select('g.content5Bound text.content5_right') |
| 1198 | 1303 | .text(function (d) { |
| 1199 | 1304 | if (showType === 0) { |
| ... | ... | @@ -1226,8 +1331,8 @@ export default { |
| 1226 | 1331 | return left_bound.width + 2 |
| 1227 | 1332 | }) |
| 1228 | 1333 | itemsUpdate.select('g.content5Bound') |
| 1229 | - .attr('transform', function (d, i) { | |
| 1230 | - if (i === 1) { | |
| 1334 | + .attr('transform', function (d) { | |
| 1335 | + if (d.svgPartIndex === 2) { | |
| 1231 | 1336 | let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() |
| 1232 | 1337 | let g_bounds = this.getBBox() |
| 1233 | 1338 | let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x |
| ... | ... | @@ -1243,10 +1348,9 @@ export default { |
| 1243 | 1348 | } |
| 1244 | 1349 | }) |
| 1245 | 1350 | // ------------ 3-2-3、当part3存在时,part2纵向中间左侧添加内容(以上)----------- // |
| 1246 | - | |
| 1247 | 1351 | // ------------ 3-2-4、当part3存在时,part2纵向中间右侧添加内容(以下)----------- // |
| 1248 | - itemsEnter.select(function (d, i) { | |
| 1249 | - return i === 1 && (showType === 0 || showType === 1 || showType === 3) ? this : null | |
| 1352 | + itemsEnter.select(function (d) { | |
| 1353 | + return d.svgPartIndex === 2 && (showType === 0 || showType === 1 || showType === 3) ? this : null | |
| 1250 | 1354 | }).append('g') |
| 1251 | 1355 | .classed('content6Bound', true) |
| 1252 | 1356 | .attr('transform', 'translate(10, 10)') |
| ... | ... | @@ -1292,9 +1396,27 @@ export default { |
| 1292 | 1396 | let left_bound = svg.select('text.content6_left').node().getBBox() |
| 1293 | 1397 | return left_bound.width + 2 |
| 1294 | 1398 | }) |
| 1399 | + itemsEnter.select('g.content6Bound') | |
| 1400 | + .attr('transform', function (d) { | |
| 1401 | + if (d.svgPartIndex === 2) { | |
| 1402 | + let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() | |
| 1403 | + let g_bounds = this.getBBox() | |
| 1404 | + let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x | |
| 1405 | + + rect_part2_bounds.width / 2 | |
| 1406 | + let dy = (rect_part2_bounds.height / 2 - g_bounds.height) / 2 - g_bounds.y | |
| 1407 | + + rect_part2_bounds.height / 2 | |
| 1408 | + if (dx < 0) { | |
| 1409 | + dx = 1 | |
| 1410 | + } | |
| 1411 | + if (dy < 0) { | |
| 1412 | + dy = 1 | |
| 1413 | + } | |
| 1414 | + return `translate(${dx}, ${dy})` | |
| 1415 | + } | |
| 1416 | + }) | |
| 1295 | 1417 | |
| 1296 | - itemsUpdate.select(function (d, i) { | |
| 1297 | - return i === 1 && (showType === 0 || showType === 1 || showType === 3) ? this : null | |
| 1418 | + itemsUpdate.select(function (d) { | |
| 1419 | + return d.svgPartIndex === 2 && (showType === 0 || showType === 1 || showType === 3) ? this : null | |
| 1298 | 1420 | }).select('g.content6Bound text.content6_left') |
| 1299 | 1421 | .text(function (d) { |
| 1300 | 1422 | if (showType === 3) { |
| ... | ... | @@ -1310,8 +1432,8 @@ export default { |
| 1310 | 1432 | return d.currentFromStations_left |
| 1311 | 1433 | } |
| 1312 | 1434 | }) |
| 1313 | - itemsUpdate.select(function (d, i) { | |
| 1314 | - return i === 1 && (showType === 0 || showType === 1 || showType === 3) ? this : null | |
| 1435 | + itemsUpdate.select(function (d) { | |
| 1436 | + return d.svgPartIndex === 2 && (showType === 0 || showType === 1 || showType === 3) ? this : null | |
| 1315 | 1437 | }).select('g.content6Bound text.content6_right') |
| 1316 | 1438 | .text(function (d) { |
| 1317 | 1439 | if (showType === 3) { |
| ... | ... | @@ -1332,8 +1454,8 @@ export default { |
| 1332 | 1454 | return left_bound.width + 2 |
| 1333 | 1455 | }) |
| 1334 | 1456 | itemsUpdate.select('g.content6Bound') |
| 1335 | - .attr('transform', function (d, i) { | |
| 1336 | - if (i === 1) { | |
| 1457 | + .attr('transform', function (d) { | |
| 1458 | + if (d.svgPartIndex === 2) { | |
| 1337 | 1459 | let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() |
| 1338 | 1460 | let g_bounds = this.getBBox() |
| 1339 | 1461 | let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x |
| ... | ... | @@ -1350,10 +1472,9 @@ export default { |
| 1350 | 1472 | } |
| 1351 | 1473 | }) |
| 1352 | 1474 | // ------------ 3-2-4、当part3存在时,part2纵向中间右侧添加内容(以上)----------- // |
| 1353 | - | |
| 1354 | 1475 | // ------------ 3-2-5、当part3不存在时,part2添加内容(以下)----------- // |
| 1355 | - itemsEnter.select(function (d, i) { | |
| 1356 | - return i === 1 && showType === 2 ? this : null | |
| 1476 | + itemsEnter.select(function (d) { | |
| 1477 | + return d.svgPartIndex === 2 && showType === 2 ? this : null | |
| 1357 | 1478 | }).append('g') |
| 1358 | 1479 | .classed('content7Bound1', true) |
| 1359 | 1480 | .attr('transform', 'translate(10, 10)') |
| ... | ... | @@ -1383,9 +1504,27 @@ export default { |
| 1383 | 1504 | let left_bound = svg.select('text.content7_1_left').node().getBBox() |
| 1384 | 1505 | return left_bound.width + 2 |
| 1385 | 1506 | }) |
| 1507 | + itemsEnter.select('g.content7Bound1') | |
| 1508 | + .attr('transform', function (d) { | |
| 1509 | + if (d.svgPartIndex === 2) { | |
| 1510 | + let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() | |
| 1511 | + let g_bounds = this.getBBox() | |
| 1512 | + let dx = (rect_part2_bounds.width / 4 - g_bounds.width) / 2 - g_bounds.x | |
| 1513 | + + rect_part2_bounds.width / 2 | |
| 1514 | + let dy = (rect_part2_bounds.height / 2 - g_bounds.height) / 2 - g_bounds.y | |
| 1515 | + + rect_part2_bounds.height / 2 | |
| 1516 | + if (dx < 0) { | |
| 1517 | + dx = 1 | |
| 1518 | + } | |
| 1519 | + if (dy < 0) { | |
| 1520 | + dy = 1 | |
| 1521 | + } | |
| 1522 | + return `translate(${dx}, ${dy})` | |
| 1523 | + } | |
| 1524 | + }) | |
| 1386 | 1525 | |
| 1387 | - itemsUpdate.select(function (d, i) { | |
| 1388 | - return i === 1 && showType === 2 ? this : null | |
| 1526 | + itemsUpdate.select(function (d) { | |
| 1527 | + return d.svgPartIndex === 2 && showType === 2 ? this : null | |
| 1389 | 1528 | }).select('g.content7Bound1 text.content7_1_left') |
| 1390 | 1529 | .text(function (d) { |
| 1391 | 1530 | return d.currentFromStations_left |
| ... | ... | @@ -1393,8 +1532,8 @@ export default { |
| 1393 | 1532 | .attr('title', function (d) { |
| 1394 | 1533 | return d.currentFromStations_left |
| 1395 | 1534 | }) |
| 1396 | - itemsUpdate.select(function (d, i) { | |
| 1397 | - return i === 1 && showType === 2 ? this : null | |
| 1535 | + itemsUpdate.select(function (d) { | |
| 1536 | + return d.svgPartIndex === 2 && showType === 2 ? this : null | |
| 1398 | 1537 | }).select('g.content7Bound1 text.content7_1_right') |
| 1399 | 1538 | .text(function (d) { |
| 1400 | 1539 | return d.currentFromStations_right |
| ... | ... | @@ -1407,8 +1546,8 @@ export default { |
| 1407 | 1546 | return left_bound.width + 2 |
| 1408 | 1547 | }) |
| 1409 | 1548 | itemsUpdate.select('g.content7Bound1') |
| 1410 | - .attr('transform', function (d, i) { | |
| 1411 | - if (i === 1) { | |
| 1549 | + .attr('transform', function (d) { | |
| 1550 | + if (d.svgPartIndex === 2) { | |
| 1412 | 1551 | let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() |
| 1413 | 1552 | let g_bounds = this.getBBox() |
| 1414 | 1553 | let dx = (rect_part2_bounds.width / 4 - g_bounds.width) / 2 - g_bounds.x |
| ... | ... | @@ -1425,8 +1564,8 @@ export default { |
| 1425 | 1564 | } |
| 1426 | 1565 | }) |
| 1427 | 1566 | |
| 1428 | - itemsEnter.select(function (d, i) { | |
| 1429 | - return i === 1 && showType === 2 ? this : null | |
| 1567 | + itemsEnter.select(function (d) { | |
| 1568 | + return d.svgPartIndex === 2 && showType === 2 ? this : null | |
| 1430 | 1569 | }).append('g') |
| 1431 | 1570 | .classed('content7Bound2', true) |
| 1432 | 1571 | .attr('transform', 'translate(10, 10)') |
| ... | ... | @@ -1456,9 +1595,27 @@ export default { |
| 1456 | 1595 | let left_bound = svg.select('text.content7_2_left').node().getBBox() |
| 1457 | 1596 | return left_bound.width + 2 |
| 1458 | 1597 | }) |
| 1598 | + itemsEnter.select('g.content7Bound2') | |
| 1599 | + .attr('transform', function (d) { | |
| 1600 | + if (d.svgPartIndex === 2) { | |
| 1601 | + let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() | |
| 1602 | + let g_bounds = this.getBBox() | |
| 1603 | + let dx = (rect_part2_bounds.width / 4 - g_bounds.width) / 2 - g_bounds.x | |
| 1604 | + + rect_part2_bounds.width * 0.75 | |
| 1605 | + let dy = (rect_part2_bounds.height / 2 - g_bounds.height) / 2 - g_bounds.y | |
| 1606 | + + rect_part2_bounds.height / 2 | |
| 1607 | + if (dx < 0) { | |
| 1608 | + dx = 1 | |
| 1609 | + } | |
| 1610 | + if (dy < 0) { | |
| 1611 | + dy = 1 | |
| 1612 | + } | |
| 1613 | + return `translate(${dx}, ${dy})` | |
| 1614 | + } | |
| 1615 | + }) | |
| 1459 | 1616 | |
| 1460 | - itemsUpdate.select(function (d, i) { | |
| 1461 | - return i === 1 && showType === 2 ? this : null | |
| 1617 | + itemsUpdate.select(function (d) { | |
| 1618 | + return d.svgPartIndex === 2 && showType === 2 ? this : null | |
| 1462 | 1619 | }).select('g.content7Bound2 text.content7_2_left') |
| 1463 | 1620 | .text(function (d) { |
| 1464 | 1621 | return d.currentFromMinutes_left |
| ... | ... | @@ -1466,8 +1623,8 @@ export default { |
| 1466 | 1623 | .attr('title', function (d) { |
| 1467 | 1624 | return d.currentFromMinutes_left |
| 1468 | 1625 | }) |
| 1469 | - itemsUpdate.select(function (d, i) { | |
| 1470 | - return i === 1 && showType === 2 ? this : null | |
| 1626 | + itemsUpdate.select(function (d) { | |
| 1627 | + return d.svgPartIndex === 2 && showType === 2 ? this : null | |
| 1471 | 1628 | }).select('g.content7Bound2 text.content7_2_right') |
| 1472 | 1629 | .text(function (d) { |
| 1473 | 1630 | return d.currentFromMinutes_right |
| ... | ... | @@ -1480,8 +1637,8 @@ export default { |
| 1480 | 1637 | return left_bound.width + 2 |
| 1481 | 1638 | }) |
| 1482 | 1639 | itemsUpdate.select('g.content7Bound2') |
| 1483 | - .attr('transform', function (d, i) { | |
| 1484 | - if (i === 1) { | |
| 1640 | + .attr('transform', function (d) { | |
| 1641 | + if (d.svgPartIndex === 2) { | |
| 1485 | 1642 | let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() |
| 1486 | 1643 | let g_bounds = this.getBBox() |
| 1487 | 1644 | let dx = (rect_part2_bounds.width / 4 - g_bounds.width) / 2 - g_bounds.x |
| ... | ... | @@ -1500,8 +1657,8 @@ export default { |
| 1500 | 1657 | // ------------ 3-2-5、当part3不存在时,part2添加内容(以上)----------- // |
| 1501 | 1658 | |
| 1502 | 1659 | // ------------ 3-3、part3部分 -------------// |
| 1503 | - itemsEnter.select(function (d, i) { | |
| 1504 | - return i === 2 ? this : null | |
| 1660 | + itemsEnter.select(function (d) { | |
| 1661 | + return d.svgPartIndex === 3 ? this : null | |
| 1505 | 1662 | }).append('g') |
| 1506 | 1663 | .classed('contentAllBound', true) |
| 1507 | 1664 | .attr('transform', 'translate(10, 10)') |
| ... | ... | @@ -1531,9 +1688,25 @@ export default { |
| 1531 | 1688 | let left_bounds = svg.select('g.contentAllBound text.content').node().getBBox() |
| 1532 | 1689 | return left_bounds.width + 10 |
| 1533 | 1690 | }) |
| 1691 | + itemsEnter.select('g.contentAllBound') | |
| 1692 | + .attr('transform', function (d) { | |
| 1693 | + if (d.svgPartIndex === 3) { | |
| 1694 | + let rect_part3_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() | |
| 1695 | + let g_content_bounds = this.getBBox() | |
| 1696 | + let dx = (rect_part3_bounds.width - g_content_bounds.width) / 2 - g_content_bounds.x | |
| 1697 | + let dy = (rect_part3_bounds.height - 48 - g_content_bounds.height) / 2 - g_content_bounds.y + 48 | |
| 1698 | + if (dx < 0) { | |
| 1699 | + dx = 1 | |
| 1700 | + } | |
| 1701 | + if (dy < 0) { | |
| 1702 | + dy = 1 | |
| 1703 | + } | |
| 1704 | + return `translate(${dx}, ${dy})` | |
| 1705 | + } | |
| 1706 | + }) | |
| 1534 | 1707 | |
| 1535 | - itemsUpdate.select(function (d, i) { | |
| 1536 | - return i === 2 ? this : null | |
| 1708 | + itemsUpdate.select(function (d) { | |
| 1709 | + return d.svgPartIndex === 3 ? this : null | |
| 1537 | 1710 | }).select('g.contentAllBound text.content') |
| 1538 | 1711 | .text(function (d) { |
| 1539 | 1712 | return d.text2 |
| ... | ... | @@ -1541,8 +1714,8 @@ export default { |
| 1541 | 1714 | .attr('title', function (d) { |
| 1542 | 1715 | return d.text2 |
| 1543 | 1716 | }) |
| 1544 | - itemsUpdate.select(function (d, i) { | |
| 1545 | - return i === 2 ? this : null | |
| 1717 | + itemsUpdate.select(function (d) { | |
| 1718 | + return d.svgPartIndex === 3 ? this : null | |
| 1546 | 1719 | }).select('g.contentAllBound text.arrivalTime') |
| 1547 | 1720 | .text(function (d) { |
| 1548 | 1721 | return d.nextArrivalTime |
| ... | ... | @@ -1551,8 +1724,8 @@ export default { |
| 1551 | 1724 | return d.nextArrivalTime |
| 1552 | 1725 | }) |
| 1553 | 1726 | itemsUpdate.select('g.contentAllBound') |
| 1554 | - .attr('transform', function (d, i) { | |
| 1555 | - if (i === 2) { | |
| 1727 | + .attr('transform', function (d) { | |
| 1728 | + if (d.svgPartIndex === 3) { | |
| 1556 | 1729 | let rect_part3_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() |
| 1557 | 1730 | let g_content_bounds = this.getBBox() |
| 1558 | 1731 | let dx = (rect_part3_bounds.width - g_content_bounds.width) / 2 - g_content_bounds.x |
| ... | ... | @@ -1569,7 +1742,6 @@ export default { |
| 1569 | 1742 | |
| 1570 | 1743 | |
| 1571 | 1744 | } |
| 1572 | - | |
| 1573 | 1745 | } |
| 1574 | 1746 | |
| 1575 | 1747 | } | ... | ... |
front-end/h5/src/components/core/plugins/bsth/mhgj/chart/models/mhgjEBusStopLineChartData.js
| ... | ... | @@ -185,14 +185,19 @@ class MhgjEBusStopLineChartData { |
| 185 | 185 | |
| 186 | 186 | generateSvgData () { |
| 187 | 187 | // 根据内部数据产生svg用数据 |
| 188 | + // part用于d3中的data指定key,命名规则第一个数字表示第几部分,下划线第二个数字表示showType | |
| 188 | 189 | let showData = []; |
| 189 | 190 | if (this._showType === 0) { |
| 190 | 191 | showData.push({ |
| 192 | + svgD3PartKey: 'part1', | |
| 193 | + svgPartIndex: 1, | |
| 191 | 194 | lineName: this._lineName, |
| 192 | 195 | text1: '开往', |
| 193 | 196 | text2: this._terminalStationName |
| 194 | 197 | }); |
| 195 | 198 | showData.push({ |
| 199 | + svgD3PartKey: 'part2_0', | |
| 200 | + svgPartIndex: 2, | |
| 196 | 201 | text1: "本班车", |
| 197 | 202 | text2: "到达时间", |
| 198 | 203 | text3: "距本站", |
| ... | ... | @@ -201,6 +206,8 @@ class MhgjEBusStopLineChartData { |
| 201 | 206 | currentFromStations_right: "站" |
| 202 | 207 | }) |
| 203 | 208 | showData.push({ |
| 209 | + svgD3PartKey: 'part3', | |
| 210 | + svgPartIndex: 3, | |
| 204 | 211 | text1: "下一班车", |
| 205 | 212 | text2: "预计到站", |
| 206 | 213 | nextArrivalTime: this._nextArrivalTime |
| ... | ... | @@ -208,11 +215,15 @@ class MhgjEBusStopLineChartData { |
| 208 | 215 | |
| 209 | 216 | } else if (this._showType === 1) { |
| 210 | 217 | showData.push({ |
| 218 | + svgD3PartKey: 'part1', | |
| 219 | + svgPartIndex: 1, | |
| 211 | 220 | lineName: this._lineName, |
| 212 | 221 | text1: '开往', |
| 213 | 222 | text2: this._terminalStationName |
| 214 | 223 | }); |
| 215 | 224 | showData.push({ |
| 225 | + svgD3PartKey: 'part2_1', | |
| 226 | + svgPartIndex: 2, | |
| 216 | 227 | text1: "本班车", |
| 217 | 228 | text2: "到达时间", |
| 218 | 229 | text3: "距本站", |
| ... | ... | @@ -222,17 +233,23 @@ class MhgjEBusStopLineChartData { |
| 222 | 233 | currentFromStations_right: "站" |
| 223 | 234 | }) |
| 224 | 235 | showData.push({ |
| 236 | + svgD3PartKey: 'part3', | |
| 237 | + svgPartIndex: 3, | |
| 225 | 238 | text1: "下一班车", |
| 226 | 239 | text2: "预计到站", |
| 227 | 240 | nextArrivalTime: this._nextArrivalTime |
| 228 | 241 | }) |
| 229 | 242 | } else if (this._showType === 2) { |
| 230 | 243 | showData.push({ |
| 244 | + svgD3PartKey: 'part1', | |
| 245 | + svgPartIndex: 1, | |
| 231 | 246 | lineName: this._lineName, |
| 232 | 247 | text1: '开往', |
| 233 | 248 | text2: this._terminalStationName |
| 234 | 249 | }); |
| 235 | 250 | showData.push({ |
| 251 | + svgD3PartKey: 'part2_2', | |
| 252 | + svgPartIndex: 2, | |
| 236 | 253 | text1: "本班车", |
| 237 | 254 | text2: "到达时间", |
| 238 | 255 | text3: "距本站", |
| ... | ... | @@ -245,11 +262,15 @@ class MhgjEBusStopLineChartData { |
| 245 | 262 | |
| 246 | 263 | } else if (this._showType === 3) { |
| 247 | 264 | showData.push({ |
| 265 | + svgD3PartKey: 'part1', | |
| 266 | + svgPartIndex: 1, | |
| 248 | 267 | lineName: this._lineName, |
| 249 | 268 | text1: '开往', |
| 250 | 269 | text2: this._terminalStationName |
| 251 | 270 | }); |
| 252 | 271 | showData.push({ |
| 272 | + svgD3PartKey: 'part2_3', | |
| 273 | + svgPartIndex: 2, | |
| 253 | 274 | text1: "本班车", |
| 254 | 275 | text2: "到达时间", |
| 255 | 276 | text3: "距本站", | ... | ... |
front-end/h5/src/components/core/plugins/bsth/mhgj/list/mhgj-eBusStop-line-chart-list-scrollPage.js
| ... | ... | @@ -172,6 +172,9 @@ export default { |
| 172 | 172 | } else { |
| 173 | 173 | this.scrollPageInnerData = ScrollPageInnerData.generateDataListByRemoteData( |
| 174 | 174 | this.page_size, this.list_width, this.list_height, remoteDataList) |
| 175 | + // this.scrollPageInnerData = ScrollPageInnerData.generateDataListByTest( | |
| 176 | + // this.page_size, this.list_width, this.list_height) | |
| 177 | + | |
| 175 | 178 | // 发送bindData事件,父组件绑定该事件 |
| 176 | 179 | this.$emit('bindData', this.scrollPageInnerData.scrollDataItemList) |
| 177 | 180 | this.initLoading = false |
| ... | ... | @@ -195,6 +198,8 @@ export default { |
| 195 | 198 | } else { |
| 196 | 199 | jsonp(this.remoteUrl).then(remoteDataList => { |
| 197 | 200 | this.scrollPageInnerData.refreshDataWithRemoteData(remoteDataList) |
| 201 | + // console.log('refresh') | |
| 202 | + // this.scrollPageInnerData._scrollDataItemList[0]._eBusStopData.showType = 2 | |
| 198 | 203 | }).catch(err => { |
| 199 | 204 | console.log(err) |
| 200 | 205 | this.$message.error(` 获取数据失败,状态:${err.status},错误:${err.statusText}`, 1) | ... | ... |