1
-
2
1
var DEFAULT_OPTIONS = {
3
2
radius : 8 ,
4
3
outerStrokeWidth : 1 ,
5
4
parentNodeColor : 'blue' ,
6
5
showPieChartBorder : true ,
7
6
pieChartBorderColor : 'white' ,
8
7
pieChartBorderWidth : '1' ,
9
- showLabelText : false ,
8
+ showLabelText : true ,
10
9
labelText : 'text' ,
10
+ labelWeight : 'bold' ,
11
11
labelColor : 'blue'
12
12
} ;
13
13
@@ -48,7 +48,7 @@ function drawPieChartBorder(nodeElement, options) {
48
48
. attr ( "stroke-width" , pieChartBorderWidth ) ;
49
49
}
50
50
51
- function drawPieChart ( nodeElement , percentages , options ) {
51
+ function drawPieChart ( nodeElement , percentages , options , colorScale ) {
52
52
var radius = getOptionOrDefault ( 'radius' , options ) ;
53
53
var halfRadius = radius / 2 ;
54
54
var halfCircumference = 2 * Math . PI * halfRadius ;
@@ -60,7 +60,7 @@ function drawPieChart(nodeElement, percentages, options) {
60
60
nodeElement . insert ( 'circle' , '#parent-pie + *' )
61
61
. attr ( "r" , halfRadius )
62
62
. attr ( "fill" , 'transparent' )
63
- . style ( 'stroke' , color ( percentages [ p ] . color ) )
63
+ . style ( 'stroke' , colorScale ( percentages [ p ] . color ) )
64
64
. style ( 'stroke-width' , radius )
65
65
. style ( 'stroke-dasharray' ,
66
66
halfCircumference * percentToDraw / 100
@@ -73,28 +73,70 @@ function drawTitleText(nodeElement, options) {
73
73
var radius = getOptionOrDefault ( 'radius' , options ) ;
74
74
var text = getOptionOrDefault ( 'labelText' , options ) ;
75
75
var color = getOptionOrDefault ( 'labelColor' , options ) ;
76
+ var labelWeight = getOptionOrDefault ( 'labelWeight' , options ) ;
77
+
78
+ var textElement = nodeElement . select ( ".text-label" ) ;
79
+
80
+ var fontSize = 12 ;
81
+
82
+ if ( textElement . empty ( ) ) {
83
+ textElement = nodeElement . append ( "text" )
84
+ . attr ( "class" , "text-label" )
85
+ . attr ( "fill" , color )
86
+ . attr ( "dy" , radius * 3 )
87
+ . style ( "font-size" , fontSize + "px" )
88
+ . style ( "font-weight" , labelWeight )
89
+ . style ( "pointer-events" , "none" ) ;
90
+ }
91
+
92
+ // Set text content
93
+ textElement . text ( String ( text ) ) ;
76
94
77
- nodeElement . append ( "text" )
78
- . text ( String ( text ) )
79
- . attr ( "fill" , color )
80
- . attr ( "dy" , radius * 3 ) ;
95
+ // Set initial visibility based on the group and showLabelText option
96
+ textElement . style ( "display" , options . group === 1 ? "inline" : "none" ) ;
97
+
98
+ // Add mouseover and mouseout events directly to the nodeElement
99
+ nodeElement . on ( "mouseover" , function ( ) {
100
+ if ( options . group === 0 && options . showLabelText ) {
101
+ textElement . style ( "visibility" , "visible" ) ;
102
+ }
103
+ } ) . on ( "mouseout" , function ( ) {
104
+ if ( options . group === 0 ) {
105
+ textElement . style ( "visibility" , "hidden" ) ;
106
+ }
107
+ } ) ;
81
108
}
82
109
110
+
111
+
112
+
83
113
var NodePieBuilder = {
84
- drawNodePie : function ( nodeElement , percentages , options ) {
114
+ drawNodePie : function ( nodeElement , percentages , options , colorScale ) {
85
115
drawParentCircle ( nodeElement , options ) ;
86
116
87
117
if ( ! percentages ) return ;
88
- drawPieChart ( nodeElement , percentages , options ) ;
118
+ drawPieChart ( nodeElement , percentages , options , colorScale ) ;
89
119
90
120
var showPieChartBorder = getOptionOrDefault ( 'showPieChartBorder' , options ) ;
91
121
if ( showPieChartBorder ) {
92
122
drawPieChartBorder ( nodeElement , options ) ;
93
123
}
94
124
95
- var showLabelText = getOptionOrDefault ( 'showLabelText' , options ) ;
96
- if ( showLabelText ) {
97
- drawTitleText ( nodeElement , options ) ;
98
- }
125
+ drawTitleText ( nodeElement , options ) ;
126
+
127
+ // Add mouseover and mouseout events directly to the nodeElement
128
+ nodeElement . on ( "mouseover" , function ( ) {
129
+ if ( options . group === 0 && options . showLabelText ) {
130
+ nodeElement . select ( ".text-label" ) . style ( "display" , "inline" ) ;
131
+ }
132
+ } ) . on ( "mouseout" , function ( ) {
133
+ if ( options . group === 0 ) {
134
+ nodeElement . select ( ".text-label" ) . style ( "display" , "none" ) ;
135
+ }
136
+ } ) ;
99
137
}
100
138
} ;
139
+
140
+
141
+
142
+
0 commit comments