Commit 52b23c2b58f33287479fa1c942dac27c0de7e24e

Authored by 徐烜
1 parent eeaa9c0c

闵行公交公司用的公交电子站牌页面组件

1、修正mhgj-eBusStop-line-chart组件bug(part没有正确的删除更新,主要修正model的generateSvgData方法,添加svgD3PartKey,svgPartIndex辅助d3绘制svg)
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,6 +31,7 @@ svg.mhgj-eBusStop-line-chart {
31 font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; 31 font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
32 } 32 }
33 33
  34 +/** 每个part对应一个g,和rect */
34 svg.mhgj-eBusStop-line-chart g.part { 35 svg.mhgj-eBusStop-line-chart g.part {
35 } 36 }
36 svg.mhgj-eBusStop-line-chart g.part rect.main { 37 svg.mhgj-eBusStop-line-chart g.part rect.main {
@@ -39,6 +40,7 @@ svg.mhgj-eBusStop-line-chart g.part rect.main { @@ -39,6 +40,7 @@ svg.mhgj-eBusStop-line-chart g.part rect.main {
39 stroke-width: 1; 40 stroke-width: 1;
40 Pointer-events: none; 41 Pointer-events: none;
41 } 42 }
  43 +/** 每个part上部title相关 */
42 svg.mhgj-eBusStop-line-chart g.part rect.titleBackground { 44 svg.mhgj-eBusStop-line-chart g.part rect.titleBackground {
43 fill: #7dc6fe; 45 fill: #7dc6fe;
44 stroke-width: 0; 46 stroke-width: 0;
@@ -46,12 +48,6 @@ svg.mhgj-eBusStop-line-chart g.part rect.titleBackground { @@ -46,12 +48,6 @@ svg.mhgj-eBusStop-line-chart g.part rect.titleBackground {
46 } 48 }
47 svg.mhgj-eBusStop-line-chart g.part g.titleBound { 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 svg.mhgj-eBusStop-line-chart g.part g.titleBound text.title { 51 svg.mhgj-eBusStop-line-chart g.part g.titleBound text.title {
56 font-size: 60px; 52 font-size: 60px;
57 font-weight: 900; 53 font-weight: 900;
@@ -60,8 +56,15 @@ svg.mhgj-eBusStop-line-chart g.part g.titleBound text.title { @@ -60,8 +56,15 @@ svg.mhgj-eBusStop-line-chart g.part g.titleBound text.title {
60 Pointer-events: none; 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 svg.mhgj-eBusStop-line-chart g.part g.content1Bound { 68 svg.mhgj-eBusStop-line-chart g.part g.content1Bound {
66 } 69 }
67 svg.mhgj-eBusStop-line-chart g.part g.content1Bound text.content1 { 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,7 +83,8 @@ svg.mhgj-eBusStop-line-chart g.part g.content2Bound text.content2 {
80 text-shadow: 0 0 2px #dadada; 83 text-shadow: 0 0 2px #dadada;
81 Pointer-events: none; 84 Pointer-events: none;
82 } 85 }
83 -/** part2用 */ 86 +
  87 +/** part2 */
84 svg.mhgj-eBusStop-line-chart g.part path.bound { 88 svg.mhgj-eBusStop-line-chart g.part path.bound {
85 stroke: rgb(0, 0, 0); 89 stroke: rgb(0, 0, 0);
86 stroke-width: 1; 90 stroke-width: 1;
@@ -170,8 +174,7 @@ svg.mhgj-eBusStop-line-chart g.part g.content7Bound2 text.content7_2_right { @@ -170,8 +174,7 @@ svg.mhgj-eBusStop-line-chart g.part g.content7Bound2 text.content7_2_right {
170 text-shadow: 0 0 2px #dadada; 174 text-shadow: 0 0 2px #dadada;
171 Pointer-events: none; 175 Pointer-events: none;
172 } 176 }
173 -  
174 -/** part3用 */ 177 +/** part3 */
175 svg.mhgj-eBusStop-line-chart g.part g.contentAllBound { 178 svg.mhgj-eBusStop-line-chart g.part g.contentAllBound {
176 } 179 }
177 svg.mhgj-eBusStop-line-chart g.part g.contentAllBound text.content { 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 import Vue from 'vue' 1 import Vue from 'vue'
5 2
6 import moment from 'moment' 3 import moment from 'moment'
@@ -288,6 +285,7 @@ export default { @@ -288,6 +285,7 @@ export default {
288 // if (!Utils.objectEquals(currentVal, oldVal)) { 285 // if (!Utils.objectEquals(currentVal, oldVal)) {
289 // self.refreshSvg() 286 // self.refreshSvg()
290 // } 287 // }
  288 + console.log('refreshSvg()')
291 self.refreshSvg() 289 self.refreshSvg()
292 }, 290 },
293 deep: true 291 deep: true
@@ -609,10 +607,10 @@ export default { @@ -609,10 +607,10 @@ export default {
609 .domain([0, 1]) // 定义域 607 .domain([0, 1]) // 定义域
610 .range([partUpPadding, height - partDownPadding]) // 值域 608 .range([partUpPadding, height - partDownPadding]) // 值域
611 609
612 - // ------------ 1、添加g元素 ----------------// 610 + // ------------ 1、添加g元素 ---------------- //
613 let itemsUpdate = svg.selectAll('g.part') 611 let itemsUpdate = svg.selectAll('g.part')
614 .data(svgData, function (d) { 612 .data(svgData, function (d) {
615 - return d.text1 613 + return d.svgD3PartKey
616 }) 614 })
617 let itemsEnter = itemsUpdate 615 let itemsEnter = itemsUpdate
618 let itemsExit = itemsUpdate.exit() 616 let itemsExit = itemsUpdate.exit()
@@ -620,69 +618,68 @@ export default { @@ -620,69 +618,68 @@ export default {
620 itemsExit.remove() 618 itemsExit.remove()
621 itemsEnter = itemsEnter.enter().append('g') 619 itemsEnter = itemsEnter.enter().append('g')
622 .classed('part', true) 620 .classed('part', true)
623 - .attr('transform', function (d, i) { 621 + .attr('transform', function (d) {
624 let x, y 622 let x, y
625 - if (i === 0) { // part1 623 + if (d.svgPartIndex === 1) { // part1
626 x = xScale(0) 624 x = xScale(0)
627 - } else if (i === 1) { // part2 625 + } else if (d.svgPartIndex === 2) { // part2
628 x = xScale(0) + partWidth + partBetweenPadding 626 x = xScale(0) + partWidth + partBetweenPadding
629 - } else if (i === 2) { // part3 627 + } else if (d.svgPartIndex === 3) { // part3
630 x = xScale(0) + partWidth * 2 + partBetweenPadding * 2 628 x = xScale(0) + partWidth * 2 + partBetweenPadding * 2
631 } 629 }
632 y = yScale(0) 630 y = yScale(0)
633 return `translate(${x}, ${y})` 631 return `translate(${x}, ${y})`
634 }) 632 })
635 itemsUpdate 633 itemsUpdate
636 - .attr('transform', function (d, i) { 634 + .attr('transform', function (d) {
637 let x, y 635 let x, y
638 - if (i === 0) { // part1 636 + if (d.svgPartIndex === 1) { // part1
639 x = xScale(0) 637 x = xScale(0)
640 - } else if (i === 1) { // part2 638 + } else if (d.svgPartIndex === 2) { // part2
641 x = xScale(0) + partWidth + partBetweenPadding 639 x = xScale(0) + partWidth + partBetweenPadding
642 - } else if (i === 2) { // part3 640 + } else if (d.svgPartIndex === 3) { // part3
643 x = xScale(0) + partWidth * 2 + partBetweenPadding * 2 641 x = xScale(0) + partWidth * 2 + partBetweenPadding * 2
644 } 642 }
645 y = yScale(0) 643 y = yScale(0)
646 return `translate(${x}, ${y})` 644 return `translate(${x}, ${y})`
647 }) 645 })
648 646
649 - // ------------ 2、添加各个part的上半部分 ----------------//  
650 - // ------------- 2-1、添加每个part最外部的rect(以下)------------// 647 + // ------------ 1-1、添加g rect.main 元素 ---------------- //
651 itemsEnter.append('rect') 648 itemsEnter.append('rect')
652 .classed('main', true) 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 return self.part1_background_color 652 return self.part1_background_color
656 - } else if (i === 1) { 653 + } else if (d.svgPartIndex === 2) {
657 return self.part2_background_color 654 return self.part2_background_color
658 - } else if (i === 2) { 655 + } else if (d.svgPartIndex === 3) {
659 return self.part3_background_color 656 return self.part3_background_color
660 } else { 657 } else {
661 return '#FFFFFF' 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 return self.part1_border_size 663 return self.part1_border_size
667 - } else if (i === 1) { 664 + } else if (d.svgPartIndex === 2) {
668 return self.part2_border_size 665 return self.part2_border_size
669 - } else if (i === 2) { 666 + } else if (d.svgPartIndex === 3) {
670 return self.part3_border_size 667 return self.part3_border_size
671 } else { 668 } else {
672 return 0 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 return null 674 return null
678 } else { // part2、part3的边框样式为虚线 675 } else { // part2、part3的边框样式为虚线
679 return "4,2" 676 return "4,2"
680 } 677 }
681 }) 678 })
682 - .attr('width', function (d, i) { 679 + .attr('width', function (d) {
683 // 三个part都存在,同宽度,part3不存在时,part2占用2个宽度 680 // 三个part都存在,同宽度,part3不存在时,part2占用2个宽度
684 // 宽度计算参考 0、前置计算准备 681 // 宽度计算参考 0、前置计算准备
685 - if (i === 1 ) { // part2 682 + if (d.svgPartIndex === 2 ) { // part2
686 if (showType === 0 || showType === 1) { 683 if (showType === 0 || showType === 1) {
687 return partWidth 684 return partWidth
688 } else if (showType === 2 || showType === 3) { 685 } else if (showType === 2 || showType === 3) {
@@ -696,8 +693,8 @@ export default { @@ -696,8 +693,8 @@ export default {
696 }) 693 })
697 .attr('height', partHeight + 'px') 694 .attr('height', partHeight + 'px')
698 itemsUpdate.select('rect.main') 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 if (showType === 0 || showType === 1) { 698 if (showType === 0 || showType === 1) {
702 return partWidth 699 return partWidth
703 } else if (showType === 2 || showType === 3) { 700 } else if (showType === 2 || showType === 3) {
@@ -710,13 +707,13 @@ export default { @@ -710,13 +707,13 @@ export default {
710 } 707 }
711 }) 708 })
712 .attr('height', partHeight + 'px') 709 .attr('height', partHeight + 'px')
713 - // ------------- 2-1、添加每个part最外部的rect(以上)------------//  
714 710
  711 + // ------------ 2、添加各个part的上半部分 ----------------//
715 // ------------- 2-1、添加每个part上部放置title的外部rect(以下)------------// 712 // ------------- 2-1、添加每个part上部放置title的外部rect(以下)------------//
716 itemsEnter.append('rect') 713 itemsEnter.append('rect')
717 .classed('titleBackground', true) 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 if (showType === 0 || showType === 1) { 717 if (showType === 0 || showType === 1) {
721 return partWidth - 2 718 return partWidth - 2
722 } else if (showType === 2 || showType === 3) { 719 } else if (showType === 2 || showType === 3) {
@@ -728,27 +725,27 @@ export default { @@ -728,27 +725,27 @@ export default {
728 return partWidth - 2 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 return 0 730 return 0
734 } else { 731 } else {
735 return partTitleRectHeight 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 return self.part1_background_color 737 return self.part1_background_color
741 - } else if (i === 1) { 738 + } else if (d.svgPartIndex === 2) {
742 return self.part2_title1_background_color 739 return self.part2_title1_background_color
743 - } else if (i === 2) { 740 + } else if (d.svgPartIndex === 3) {
744 return self.part3_title1_background_color 741 return self.part3_title1_background_color
745 } 742 }
746 }) 743 })
747 .attr('x', 1) 744 .attr('x', 1)
748 .attr('y', 1) 745 .attr('y', 1)
749 itemsUpdate.select('rect.titleBackground') 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 if (showType === 0 || showType === 1) { 749 if (showType === 0 || showType === 1) {
753 return partWidth - 2 750 return partWidth - 2
754 } else if (showType === 2 || showType === 3) { 751 } else if (showType === 2 || showType === 3) {
@@ -767,8 +764,9 @@ export default { @@ -767,8 +764,9 @@ export default {
767 .classed('titleBound', true) 764 .classed('titleBound', true)
768 .attr('transform', 'translate(10, 10)') 765 .attr('transform', 'translate(10, 10)')
769 itemsEnter.select('g.titleBound') // 添加part1上部分title中的图标 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 .append('image') 768 .append('image')
  769 + .classed('part1', true)
772 .classed('CarIcon', true) 770 .classed('CarIcon', true)
773 // 需要将svg图标代码嵌入组件代码中,避免打包engine包含外部svg,所以把svg图标组件话,动态添加 771 // 需要将svg图标代码嵌入组件代码中,避免打包engine包含外部svg,所以把svg图标组件话,动态添加
774 // .attr('href', CarIcon) 772 // .attr('href', CarIcon)
@@ -779,9 +777,9 @@ export default { @@ -779,9 +777,9 @@ export default {
779 itemsEnter.select('g.titleBound') // 添加所有part上部分title中的text 777 itemsEnter.select('g.titleBound') // 添加所有part上部分title中的text
780 .append('text') 778 .append('text')
781 .classed('title', true) 779 .classed('title', true)
782 - .text(function (d, i) { 780 + .text(function (d) {
783 // 动态添加CarIcon组件替换之前添加的image 781 // 动态添加CarIcon组件替换之前添加的image
784 - if (i === 0) { 782 + if (d.svgPartIndex === 1) {
785 let car_g = svg.select('g.titleBound g.CarIcon') 783 let car_g = svg.select('g.titleBound g.CarIcon')
786 if (car_g.empty()) { 784 if (car_g.empty()) {
787 // 动态创建CarIcon组件 785 // 动态创建CarIcon组件
@@ -790,53 +788,54 @@ export default { @@ -790,53 +788,54 @@ export default {
790 // console.log(self.part1_line_icon_width) 788 // console.log(self.part1_line_icon_width)
791 new CarIconClass({ 789 new CarIconClass({
792 propsData: { 790 propsData: {
793 - cls: 'CarIcon' 791 + cls: 'part1 CarIcon'
794 }, 792 },
795 data() { 793 data() {
796 return self.carIconComData 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 return d.lineName 802 return d.lineName
804 - } else if (i === 1) { 803 + } else if (d.svgPartIndex === 2) {
805 return d.text1 804 return d.text1
806 - } else if (i === 2) { 805 + } else if (d.svgPartIndex === 3) {
807 return d.text1 806 return d.text1
808 } else { 807 } else {
809 return '-' 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 return self.part1_line_name_font_size 813 return self.part1_line_name_font_size
815 - } else if (i === 1) { 814 + } else if (d.svgPartIndex === 2) {
816 return self.part2_title1_font_size 815 return self.part2_title1_font_size
817 - } else if (i === 2) { 816 + } else if (d.svgPartIndex === 3) {
818 return self.part3_title1_font_size 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 return self.part1_line_name_font_color 822 return self.part1_line_name_font_color
824 - } else if (i === 1) { 823 + } else if (d.svgPartIndex === 2) {
825 return self.part2_title1_font_color 824 return self.part2_title1_font_color
826 - } else if (i === 2) { 825 + } else if (d.svgPartIndex === 3) {
827 return self.part3_title1_font_color 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 return self.part1_line_icon_width + 10 831 return self.part1_line_icon_width + 10
833 } else { 832 } else {
834 return 0 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 let text_bounds = this.getBBox(); 839 let text_bounds = this.getBBox();
841 let temp = (text_bounds.height - icon_bounds.height) / 2 840 let temp = (text_bounds.height - icon_bounds.height) / 2
842 if (temp > 0) { 841 if (temp > 0) {
@@ -849,20 +848,44 @@ export default { @@ -849,20 +848,44 @@ export default {
849 return 0 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 // itemsUpdate.select('g.titleBound image.carIcon') 875 // itemsUpdate.select('g.titleBound image.carIcon')
853 // .attr('width', self.part1_line_icon_width) // 指定宽度 876 // .attr('width', self.part1_line_icon_width) // 指定宽度
854 // .attr('height', self.part1_line_icon_height) // 指定高度 877 // .attr('height', self.part1_line_icon_height) // 指定高度
855 itemsUpdate.select('g.titleBound text.title') 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 return self.part1_line_icon_width + 10 881 return self.part1_line_icon_width + 10
859 } else { 882 } else {
860 return 0 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 let text_bounds = this.getBBox(); 889 let text_bounds = this.getBBox();
867 let temp = (text_bounds.height - icon_bounds.height) / 2 890 let temp = (text_bounds.height - icon_bounds.height) / 2
868 if (temp > 0) { 891 if (temp > 0) {
@@ -876,13 +899,13 @@ export default { @@ -876,13 +899,13 @@ export default {
876 } 899 }
877 }) 900 })
878 itemsUpdate.select('g.titleBound') 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 let title_bounds = this.getBBox() 904 let title_bounds = this.getBBox()
882 let dx = 1 905 let dx = 1
883 let dy = 1 906 let dy = 1
884 907
885 - if (i === 0) { // part1标题部分相对于rect.main的上半部分居中 908 + if (d.svgPartIndex === 1) { // part1标题部分相对于rect.main的上半部分居中
886 dx = (rect_bounds.width - title_bounds.width) / 2 - title_bounds.x 909 dx = (rect_bounds.width - title_bounds.width) / 2 - title_bounds.x
887 dy = (rect_bounds.height / 2 - title_bounds.height) / 2 - title_bounds.y 910 dy = (rect_bounds.height / 2 - title_bounds.height) / 2 - title_bounds.y
888 } else { // part2,part3标题部分相对于rect.main的partTitleRectHeight高度居中 911 } else { // part2,part3标题部分相对于rect.main的partTitleRectHeight高度居中
@@ -895,14 +918,15 @@ export default { @@ -895,14 +918,15 @@ export default {
895 if (dy < 0) { 918 if (dy < 0) {
896 dy = 1 919 dy = 1
897 } 920 }
  921 +
898 return `translate(${dx}, ${dy})` 922 return `translate(${dx}, ${dy})`
899 }) 923 })
900 // ------------- 2-2、添加每个part上部title(以上)------------// 924 // ------------- 2-2、添加每个part上部title(以上)------------//
901 925
902 - // ------------ 3、添加part的下半部分 ----------------// 926 + // ------------ 3、添加每个part的下半部分 ----------------//
903 // ------------ 3-1、part1部分 -------------// 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 }).append('g') 930 }).append('g')
907 .classed('content1Bound', true) 931 .classed('content1Bound', true)
908 .attr('transform', 'translate(10, 10)') 932 .attr('transform', 'translate(10, 10)')
@@ -918,9 +942,26 @@ export default { @@ -918,9 +942,26 @@ export default {
918 .attr('y', 0) 942 .attr('y', 0)
919 .style('font-size', self.part1_terminal_stop_font_size) 943 .style('font-size', self.part1_terminal_stop_font_size)
920 .style('fill', self.part1_terminal_stop_font_color) 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 itemsUpdate.select('g.content1Bound') 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 let rect_part1_bounds = svg.select('rect.main:nth-child(1)').node().getBBox() 965 let rect_part1_bounds = svg.select('rect.main:nth-child(1)').node().getBBox()
925 let g_content1_bounds = this.getBBox() 966 let g_content1_bounds = this.getBBox()
926 let dx = (rect_part1_bounds.width - g_content1_bounds.width) / 2 - g_content1_bounds.x 967 let dx = (rect_part1_bounds.width - g_content1_bounds.width) / 2 - g_content1_bounds.x
@@ -936,8 +977,8 @@ export default { @@ -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 }).append('g') 982 }).append('g')
942 .classed('content2Bound', true) 983 .classed('content2Bound', true)
943 .attr('transform', 'translate(10, 10)') 984 .attr('transform', 'translate(10, 10)')
@@ -953,9 +994,26 @@ export default { @@ -953,9 +994,26 @@ export default {
953 .attr('y', 0) 994 .attr('y', 0)
954 .style('font-size', self.part1_terminal_stop_font_size) 995 .style('font-size', self.part1_terminal_stop_font_size)
955 .style('fill', self.part1_terminal_stop_font_color) 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 itemsUpdate.select('g.content2Bound') 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 let rect_part1_bounds = svg.select('rect.main:nth-child(1)').node().getBBox() 1017 let rect_part1_bounds = svg.select('rect.main:nth-child(1)').node().getBBox()
960 let g_content1_bounds = this.getBBox() 1018 let g_content1_bounds = this.getBBox()
961 let dx = (rect_part1_bounds.width - g_content1_bounds.width) / 2 - g_content1_bounds.x 1019 let dx = (rect_part1_bounds.width - g_content1_bounds.width) / 2 - g_content1_bounds.x
@@ -974,8 +1032,8 @@ export default { @@ -974,8 +1032,8 @@ export default {
974 // ------------ 3-2、part2部分 -------------// 1032 // ------------ 3-2、part2部分 -------------//
975 // ------------ 3-2-1、当part3存在时,part2中间纵向添加一条虚线(以下)---------- // 1033 // ------------ 3-2-1、当part3存在时,part2中间纵向添加一条虚线(以下)---------- //
976 let boundLineFun = d3.line() 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 }).append('path') 1037 }).append('path')
980 .classed('bound', true) 1038 .classed('bound', true)
981 .attr('d', function () { 1039 .attr('d', function () {
@@ -992,10 +1050,9 @@ export default { @@ -992,10 +1050,9 @@ export default {
992 ]) 1050 ])
993 }) 1051 })
994 // ------------ 3-2-1、当part3存在时,part2中间纵向添加一条虚线(以上)---------- // 1052 // ------------ 3-2-1、当part3存在时,part2中间纵向添加一条虚线(以上)---------- //
995 -  
996 // ------------ 3-2-2、当part3存在时,part2纵向中间左侧添加内容标题(以下)----------- // 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 }).append('g') 1056 }).append('g')
1000 .classed('content3Bound', true) 1057 .classed('content3Bound', true)
1001 .attr('transform', 'translate(10, 10)') 1058 .attr('transform', 'translate(10, 10)')
@@ -1010,9 +1067,25 @@ export default { @@ -1010,9 +1067,25 @@ export default {
1010 }) 1067 })
1011 .style('font-size', self.part2_title2_font_size) 1068 .style('font-size', self.part2_title2_font_size)
1012 .style('fill', self.part2_title2_font_color) 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 itemsUpdate.select('g.content3Bound') 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 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() 1089 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox()
1017 let g_bounds = this.getBBox() 1090 let g_bounds = this.getBBox()
1018 let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x 1091 let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x
@@ -1027,10 +1100,9 @@ export default { @@ -1027,10 +1100,9 @@ export default {
1027 } 1100 }
1028 }) 1101 })
1029 // ------------ 3-2-2、当part3存在时,part2纵向中间左侧添加内容标题(以上)----------- // 1102 // ------------ 3-2-2、当part3存在时,part2纵向中间左侧添加内容标题(以上)----------- //
1030 -  
1031 // ------------ 3-2-3、当part3存在时,part2纵向中间右侧添加内容标题(以下)----------- // 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 }).append('g') 1106 }).append('g')
1035 .classed('content4Bound', true) 1107 .classed('content4Bound', true)
1036 .attr('transform', 'translate(10, 10)') 1108 .attr('transform', 'translate(10, 10)')
@@ -1045,9 +1117,26 @@ export default { @@ -1045,9 +1117,26 @@ export default {
1045 }) 1117 })
1046 .style('font-size', self.part2_title2_font_size) 1118 .style('font-size', self.part2_title2_font_size)
1047 .style('fill', self.part2_title2_font_color) 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 itemsUpdate.select('g.content4Bound') 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 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() 1140 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox()
1052 let g_bounds = this.getBBox() 1141 let g_bounds = this.getBBox()
1053 let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x 1142 let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x
@@ -1063,10 +1152,9 @@ export default { @@ -1063,10 +1152,9 @@ export default {
1063 } 1152 }
1064 }) 1153 })
1065 // ------------ 3-2-3、当part3存在时,part2纵向中间右侧添加内容标题(以上)----------- // 1154 // ------------ 3-2-3、当part3存在时,part2纵向中间右侧添加内容标题(以上)----------- //
1066 -  
1067 // ------------ 3-2-3、当part3存在时,part2纵向中间左侧添加内容(以下)----------- // 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 }).append('g') 1158 }).append('g')
1071 .classed('content5Bound', true) 1159 .classed('content5Bound', true)
1072 .attr('transform', 'translate(10, 10)') 1160 .attr('transform', 'translate(10, 10)')
@@ -1161,9 +1249,26 @@ export default { @@ -1161,9 +1249,26 @@ export default {
1161 let left_bound = svg.select('text.content5_left').node().getBBox() 1249 let left_bound = svg.select('text.content5_left').node().getBBox()
1162 return left_bound.width + 2 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 }).select('g.content5Bound text.content5_left') 1272 }).select('g.content5Bound text.content5_left')
1168 .text(function (d) { 1273 .text(function (d) {
1169 if (showType === 0) { 1274 if (showType === 0) {
@@ -1192,8 +1297,8 @@ export default { @@ -1192,8 +1297,8 @@ export default {
1192 return "todo" 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 }).select('g.content5Bound text.content5_right') 1302 }).select('g.content5Bound text.content5_right')
1198 .text(function (d) { 1303 .text(function (d) {
1199 if (showType === 0) { 1304 if (showType === 0) {
@@ -1226,8 +1331,8 @@ export default { @@ -1226,8 +1331,8 @@ export default {
1226 return left_bound.width + 2 1331 return left_bound.width + 2
1227 }) 1332 })
1228 itemsUpdate.select('g.content5Bound') 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 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() 1336 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox()
1232 let g_bounds = this.getBBox() 1337 let g_bounds = this.getBBox()
1233 let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x 1338 let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x
@@ -1243,10 +1348,9 @@ export default { @@ -1243,10 +1348,9 @@ export default {
1243 } 1348 }
1244 }) 1349 })
1245 // ------------ 3-2-3、当part3存在时,part2纵向中间左侧添加内容(以上)----------- // 1350 // ------------ 3-2-3、当part3存在时,part2纵向中间左侧添加内容(以上)----------- //
1246 -  
1247 // ------------ 3-2-4、当part3存在时,part2纵向中间右侧添加内容(以下)----------- // 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 }).append('g') 1354 }).append('g')
1251 .classed('content6Bound', true) 1355 .classed('content6Bound', true)
1252 .attr('transform', 'translate(10, 10)') 1356 .attr('transform', 'translate(10, 10)')
@@ -1292,9 +1396,27 @@ export default { @@ -1292,9 +1396,27 @@ export default {
1292 let left_bound = svg.select('text.content6_left').node().getBBox() 1396 let left_bound = svg.select('text.content6_left').node().getBBox()
1293 return left_bound.width + 2 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 }).select('g.content6Bound text.content6_left') 1420 }).select('g.content6Bound text.content6_left')
1299 .text(function (d) { 1421 .text(function (d) {
1300 if (showType === 3) { 1422 if (showType === 3) {
@@ -1310,8 +1432,8 @@ export default { @@ -1310,8 +1432,8 @@ export default {
1310 return d.currentFromStations_left 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 }).select('g.content6Bound text.content6_right') 1437 }).select('g.content6Bound text.content6_right')
1316 .text(function (d) { 1438 .text(function (d) {
1317 if (showType === 3) { 1439 if (showType === 3) {
@@ -1332,8 +1454,8 @@ export default { @@ -1332,8 +1454,8 @@ export default {
1332 return left_bound.width + 2 1454 return left_bound.width + 2
1333 }) 1455 })
1334 itemsUpdate.select('g.content6Bound') 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 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() 1459 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox()
1338 let g_bounds = this.getBBox() 1460 let g_bounds = this.getBBox()
1339 let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x 1461 let dx = (rect_part2_bounds.width / 2 - g_bounds.width) / 2 - g_bounds.x
@@ -1350,10 +1472,9 @@ export default { @@ -1350,10 +1472,9 @@ export default {
1350 } 1472 }
1351 }) 1473 })
1352 // ------------ 3-2-4、当part3存在时,part2纵向中间右侧添加内容(以上)----------- // 1474 // ------------ 3-2-4、当part3存在时,part2纵向中间右侧添加内容(以上)----------- //
1353 -  
1354 // ------------ 3-2-5、当part3不存在时,part2添加内容(以下)----------- // 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 }).append('g') 1478 }).append('g')
1358 .classed('content7Bound1', true) 1479 .classed('content7Bound1', true)
1359 .attr('transform', 'translate(10, 10)') 1480 .attr('transform', 'translate(10, 10)')
@@ -1383,9 +1504,27 @@ export default { @@ -1383,9 +1504,27 @@ export default {
1383 let left_bound = svg.select('text.content7_1_left').node().getBBox() 1504 let left_bound = svg.select('text.content7_1_left').node().getBBox()
1384 return left_bound.width + 2 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 }).select('g.content7Bound1 text.content7_1_left') 1528 }).select('g.content7Bound1 text.content7_1_left')
1390 .text(function (d) { 1529 .text(function (d) {
1391 return d.currentFromStations_left 1530 return d.currentFromStations_left
@@ -1393,8 +1532,8 @@ export default { @@ -1393,8 +1532,8 @@ export default {
1393 .attr('title', function (d) { 1532 .attr('title', function (d) {
1394 return d.currentFromStations_left 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 }).select('g.content7Bound1 text.content7_1_right') 1537 }).select('g.content7Bound1 text.content7_1_right')
1399 .text(function (d) { 1538 .text(function (d) {
1400 return d.currentFromStations_right 1539 return d.currentFromStations_right
@@ -1407,8 +1546,8 @@ export default { @@ -1407,8 +1546,8 @@ export default {
1407 return left_bound.width + 2 1546 return left_bound.width + 2
1408 }) 1547 })
1409 itemsUpdate.select('g.content7Bound1') 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 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() 1551 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox()
1413 let g_bounds = this.getBBox() 1552 let g_bounds = this.getBBox()
1414 let dx = (rect_part2_bounds.width / 4 - g_bounds.width) / 2 - g_bounds.x 1553 let dx = (rect_part2_bounds.width / 4 - g_bounds.width) / 2 - g_bounds.x
@@ -1425,8 +1564,8 @@ export default { @@ -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 }).append('g') 1569 }).append('g')
1431 .classed('content7Bound2', true) 1570 .classed('content7Bound2', true)
1432 .attr('transform', 'translate(10, 10)') 1571 .attr('transform', 'translate(10, 10)')
@@ -1456,9 +1595,27 @@ export default { @@ -1456,9 +1595,27 @@ export default {
1456 let left_bound = svg.select('text.content7_2_left').node().getBBox() 1595 let left_bound = svg.select('text.content7_2_left').node().getBBox()
1457 return left_bound.width + 2 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 }).select('g.content7Bound2 text.content7_2_left') 1619 }).select('g.content7Bound2 text.content7_2_left')
1463 .text(function (d) { 1620 .text(function (d) {
1464 return d.currentFromMinutes_left 1621 return d.currentFromMinutes_left
@@ -1466,8 +1623,8 @@ export default { @@ -1466,8 +1623,8 @@ export default {
1466 .attr('title', function (d) { 1623 .attr('title', function (d) {
1467 return d.currentFromMinutes_left 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 }).select('g.content7Bound2 text.content7_2_right') 1628 }).select('g.content7Bound2 text.content7_2_right')
1472 .text(function (d) { 1629 .text(function (d) {
1473 return d.currentFromMinutes_right 1630 return d.currentFromMinutes_right
@@ -1480,8 +1637,8 @@ export default { @@ -1480,8 +1637,8 @@ export default {
1480 return left_bound.width + 2 1637 return left_bound.width + 2
1481 }) 1638 })
1482 itemsUpdate.select('g.content7Bound2') 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 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() 1642 let rect_part2_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox()
1486 let g_bounds = this.getBBox() 1643 let g_bounds = this.getBBox()
1487 let dx = (rect_part2_bounds.width / 4 - g_bounds.width) / 2 - g_bounds.x 1644 let dx = (rect_part2_bounds.width / 4 - g_bounds.width) / 2 - g_bounds.x
@@ -1500,8 +1657,8 @@ export default { @@ -1500,8 +1657,8 @@ export default {
1500 // ------------ 3-2-5、当part3不存在时,part2添加内容(以上)----------- // 1657 // ------------ 3-2-5、当part3不存在时,part2添加内容(以上)----------- //
1501 1658
1502 // ------------ 3-3、part3部分 -------------// 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 }).append('g') 1662 }).append('g')
1506 .classed('contentAllBound', true) 1663 .classed('contentAllBound', true)
1507 .attr('transform', 'translate(10, 10)') 1664 .attr('transform', 'translate(10, 10)')
@@ -1531,9 +1688,25 @@ export default { @@ -1531,9 +1688,25 @@ export default {
1531 let left_bounds = svg.select('g.contentAllBound text.content').node().getBBox() 1688 let left_bounds = svg.select('g.contentAllBound text.content').node().getBBox()
1532 return left_bounds.width + 10 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 }).select('g.contentAllBound text.content') 1710 }).select('g.contentAllBound text.content')
1538 .text(function (d) { 1711 .text(function (d) {
1539 return d.text2 1712 return d.text2
@@ -1541,8 +1714,8 @@ export default { @@ -1541,8 +1714,8 @@ export default {
1541 .attr('title', function (d) { 1714 .attr('title', function (d) {
1542 return d.text2 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 }).select('g.contentAllBound text.arrivalTime') 1719 }).select('g.contentAllBound text.arrivalTime')
1547 .text(function (d) { 1720 .text(function (d) {
1548 return d.nextArrivalTime 1721 return d.nextArrivalTime
@@ -1551,8 +1724,8 @@ export default { @@ -1551,8 +1724,8 @@ export default {
1551 return d.nextArrivalTime 1724 return d.nextArrivalTime
1552 }) 1725 })
1553 itemsUpdate.select('g.contentAllBound') 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 let rect_part3_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox() 1729 let rect_part3_bounds = d3.select(this.parentNode).select('rect.main').node().getBBox()
1557 let g_content_bounds = this.getBBox() 1730 let g_content_bounds = this.getBBox()
1558 let dx = (rect_part3_bounds.width - g_content_bounds.width) / 2 - g_content_bounds.x 1731 let dx = (rect_part3_bounds.width - g_content_bounds.width) / 2 - g_content_bounds.x
@@ -1569,7 +1742,6 @@ export default { @@ -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,14 +185,19 @@ class MhgjEBusStopLineChartData {
185 185
186 generateSvgData () { 186 generateSvgData () {
187 // 根据内部数据产生svg用数据 187 // 根据内部数据产生svg用数据
  188 + // part用于d3中的data指定key,命名规则第一个数字表示第几部分,下划线第二个数字表示showType
188 let showData = []; 189 let showData = [];
189 if (this._showType === 0) { 190 if (this._showType === 0) {
190 showData.push({ 191 showData.push({
  192 + svgD3PartKey: 'part1',
  193 + svgPartIndex: 1,
191 lineName: this._lineName, 194 lineName: this._lineName,
192 text1: '开往', 195 text1: '开往',
193 text2: this._terminalStationName 196 text2: this._terminalStationName
194 }); 197 });
195 showData.push({ 198 showData.push({
  199 + svgD3PartKey: 'part2_0',
  200 + svgPartIndex: 2,
196 text1: "本班车", 201 text1: "本班车",
197 text2: "到达时间", 202 text2: "到达时间",
198 text3: "距本站", 203 text3: "距本站",
@@ -201,6 +206,8 @@ class MhgjEBusStopLineChartData { @@ -201,6 +206,8 @@ class MhgjEBusStopLineChartData {
201 currentFromStations_right: "站" 206 currentFromStations_right: "站"
202 }) 207 })
203 showData.push({ 208 showData.push({
  209 + svgD3PartKey: 'part3',
  210 + svgPartIndex: 3,
204 text1: "下一班车", 211 text1: "下一班车",
205 text2: "预计到站", 212 text2: "预计到站",
206 nextArrivalTime: this._nextArrivalTime 213 nextArrivalTime: this._nextArrivalTime
@@ -208,11 +215,15 @@ class MhgjEBusStopLineChartData { @@ -208,11 +215,15 @@ class MhgjEBusStopLineChartData {
208 215
209 } else if (this._showType === 1) { 216 } else if (this._showType === 1) {
210 showData.push({ 217 showData.push({
  218 + svgD3PartKey: 'part1',
  219 + svgPartIndex: 1,
211 lineName: this._lineName, 220 lineName: this._lineName,
212 text1: '开往', 221 text1: '开往',
213 text2: this._terminalStationName 222 text2: this._terminalStationName
214 }); 223 });
215 showData.push({ 224 showData.push({
  225 + svgD3PartKey: 'part2_1',
  226 + svgPartIndex: 2,
216 text1: "本班车", 227 text1: "本班车",
217 text2: "到达时间", 228 text2: "到达时间",
218 text3: "距本站", 229 text3: "距本站",
@@ -222,17 +233,23 @@ class MhgjEBusStopLineChartData { @@ -222,17 +233,23 @@ class MhgjEBusStopLineChartData {
222 currentFromStations_right: "站" 233 currentFromStations_right: "站"
223 }) 234 })
224 showData.push({ 235 showData.push({
  236 + svgD3PartKey: 'part3',
  237 + svgPartIndex: 3,
225 text1: "下一班车", 238 text1: "下一班车",
226 text2: "预计到站", 239 text2: "预计到站",
227 nextArrivalTime: this._nextArrivalTime 240 nextArrivalTime: this._nextArrivalTime
228 }) 241 })
229 } else if (this._showType === 2) { 242 } else if (this._showType === 2) {
230 showData.push({ 243 showData.push({
  244 + svgD3PartKey: 'part1',
  245 + svgPartIndex: 1,
231 lineName: this._lineName, 246 lineName: this._lineName,
232 text1: '开往', 247 text1: '开往',
233 text2: this._terminalStationName 248 text2: this._terminalStationName
234 }); 249 });
235 showData.push({ 250 showData.push({
  251 + svgD3PartKey: 'part2_2',
  252 + svgPartIndex: 2,
236 text1: "本班车", 253 text1: "本班车",
237 text2: "到达时间", 254 text2: "到达时间",
238 text3: "距本站", 255 text3: "距本站",
@@ -245,11 +262,15 @@ class MhgjEBusStopLineChartData { @@ -245,11 +262,15 @@ class MhgjEBusStopLineChartData {
245 262
246 } else if (this._showType === 3) { 263 } else if (this._showType === 3) {
247 showData.push({ 264 showData.push({
  265 + svgD3PartKey: 'part1',
  266 + svgPartIndex: 1,
248 lineName: this._lineName, 267 lineName: this._lineName,
249 text1: '开往', 268 text1: '开往',
250 text2: this._terminalStationName 269 text2: this._terminalStationName
251 }); 270 });
252 showData.push({ 271 showData.push({
  272 + svgD3PartKey: 'part2_3',
  273 + svgPartIndex: 2,
253 text1: "本班车", 274 text1: "本班车",
254 text2: "到达时间", 275 text2: "到达时间",
255 text3: "距本站", 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,6 +172,9 @@ export default {
172 } else { 172 } else {
173 this.scrollPageInnerData = ScrollPageInnerData.generateDataListByRemoteData( 173 this.scrollPageInnerData = ScrollPageInnerData.generateDataListByRemoteData(
174 this.page_size, this.list_width, this.list_height, remoteDataList) 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 // 发送bindData事件,父组件绑定该事件 178 // 发送bindData事件,父组件绑定该事件
176 this.$emit('bindData', this.scrollPageInnerData.scrollDataItemList) 179 this.$emit('bindData', this.scrollPageInnerData.scrollDataItemList)
177 this.initLoading = false 180 this.initLoading = false
@@ -195,6 +198,8 @@ export default { @@ -195,6 +198,8 @@ export default {
195 } else { 198 } else {
196 jsonp(this.remoteUrl).then(remoteDataList => { 199 jsonp(this.remoteUrl).then(remoteDataList => {
197 this.scrollPageInnerData.refreshDataWithRemoteData(remoteDataList) 200 this.scrollPageInnerData.refreshDataWithRemoteData(remoteDataList)
  201 + // console.log('refresh')
  202 + // this.scrollPageInnerData._scrollDataItemList[0]._eBusStopData.showType = 2
198 }).catch(err => { 203 }).catch(err => {
199 console.log(err) 204 console.log(err)
200 this.$message.error(` 获取数据失败,状态:${err.status},错误:${err.statusText}`, 1) 205 this.$message.error(` 获取数据失败,状态:${err.status},错误:${err.statusText}`, 1)