@@ -4,34 +4,31 @@ function Symbol(chart, options, symbol) {
4
4
this . symbol = symbol ;
5
5
this . connectedTo = [ ] ;
6
6
this . symbolType = options . symbolType ;
7
+ this . flowstate = ( options . flowstate || 'future' ) ;
7
8
8
9
this . next_direction = options . next && options [ 'direction_next' ] ? options [ 'direction_next' ] : undefined ;
9
- var class = ( this . options . class || this . chart . options . symbols [ this . symbolType ] [ 'class' ] || this . chart . options [ 'class' ] ) ;
10
-
10
+
11
11
this . text = this . chart . paper . text ( 0 , 0 , options . text ) ;
12
12
//Raphael does not support the svg group tag so setting the text node id to the symbol node id plus t
13
13
if ( options . key ) { this . text . node . id = options . key + 't' ; }
14
- this . text . attr ( {
15
- 'text-anchor' : 'start' ,
16
- 'font-size' : ( this . chart . options . symbols [ this . symbolType ] [ 'font-size' ] || this . chart . options [ 'font-size' ] ) ,
17
- 'x' : ( this . chart . options . symbols [ this . symbolType ] [ 'text-margin' ] || this . chart . options [ 'text-margin' ] ) ,
18
- stroke : ( this . chart . options . symbols [ this . symbolType ] [ 'font-color' ] || this . chart . options [ 'font-color' ] )
19
- } ) ;
14
+ this . text . attr ( { 'text-anchor' : 'start' ,
15
+ 'x' : this . getAttr ( 'text-margin' ) ,
16
+ 'stroke' : this . getAttr ( 'font-color' ) ,
17
+ 'font-size' : this . getAttr ( 'font-size' ) } ) ;
20
18
21
- var font = ( this . chart . options . symbols [ this . symbolType ] [ 'font' ] || this . chart . options [ 'font' ] ) ;
22
- var fontF = ( this . chart . options . symbols [ this . symbolType ] [ 'font-family' ] || this . chart . options [ 'font-family' ] ) ;
23
- var fontW = ( this . chart . options . symbols [ this . symbolType ] [ 'font-weight' ] || this . chart . options [ 'font-weight' ] ) ;
19
+ var font = this . getAttr ( 'font' ) ;
20
+ var fontF = this . getAttr ( 'font-family' ) ;
21
+ var fontW = this . getAttr ( 'font-weight' ) ;
24
22
25
23
if ( font ) this . text . attr ( { 'font' : font } ) ;
26
24
if ( fontF ) this . text . attr ( { 'font-family' : fontF } ) ;
27
25
if ( fontW ) this . text . attr ( { 'font-weight' : fontW } ) ;
28
- if ( class ) this . text . attr ( { 'class' : class } ) ;
29
26
30
27
if ( options . link ) { this . text . attr ( 'href' , options . link ) ; }
31
28
if ( options . target ) { this . text . attr ( 'target' , options . target ) ; }
32
- if ( this . chart . options . symbols [ this . symbolType ] [ 'maxWidth' ] || this . chart . options [ 'maxWidth' ] ) {
29
+ var maxWidth = this . getAttr ( 'maxWidth' ) ;
30
+ if ( maxWidth ) {
33
31
// using this approach: http://stackoverflow.com/a/3153457/22466
34
- var maxWidth = this . chart . options . symbols [ this . symbolType ] [ 'maxWidth' ] || this . chart . options [ 'maxWidth' ] ;
35
32
var words = options . text . split ( ' ' ) ;
36
33
var tempText = "" ;
37
34
for ( var i = 0 , ii = words . length ; i < ii ; i ++ ) {
@@ -45,20 +42,21 @@ function Symbol(chart, options, symbol) {
45
42
}
46
43
this . text . attr ( "text" , tempText . substring ( 1 ) ) ;
47
44
}
45
+
48
46
this . group . push ( this . text ) ;
49
47
50
48
if ( symbol ) {
51
- symbol . attr ( {
52
- stroke : ( this . chart . options . symbols [ this . symbolType ] [ 'element-color' ] || this . chart . options [ 'element-color' ] ) ,
53
- 'stroke-width' : ( this . chart . options . symbols [ this . symbolType ] [ 'line-width' ] || this . chart . options [ 'line-width' ] ) ,
54
- width : this . text . getBBox ( ) . width + 2 * ( this . chart . options . symbols [ this . symbolType ] [ 'text-margin' ] || this . chart . options [ 'text-margin' ] ) ,
55
- height : this . text . getBBox ( ) . height + 2 * ( this . chart . options . symbols [ this . symbolType ] [ 'text-margin' ] || this . chart . options [ 'text-margin' ] ) ,
56
- fill : ( this . chart . options . symbols [ this . symbolType ] [ 'fill' ] || this . chart . options [ 'fill' ] )
57
- } ) ;
58
- if ( options . link ) { symbol . attr ( 'href' , options . link ) ; }
49
+ var tmpMargin = this . getAttr ( 'text-margin' ) ;
50
+
51
+ symbol . attr ( { 'fill' : this . getAttr ( 'fill' ) ,
52
+ 'stroke' : this . getAttr ( 'element-color' ) ,
53
+ 'stroke-width' : this . getAttr ( 'line-width' ) ,
54
+ 'width' : this . text . getBBox ( ) . width + 2 * tmpMargin ,
55
+ 'height' : this . text . getBBox ( ) . height + 2 * tmpMargin } ) ;
56
+
57
+ if ( options . link ) { symbol . attr ( 'href' , options . link ) ; }
59
58
if ( options . target ) { symbol . attr ( 'target' , options . target ) ; }
60
59
if ( options . key ) { symbol . node . id = options . key ; }
61
- if ( class ) { symbol . attr ( 'class' , class ) ; }
62
60
63
61
this . group . push ( symbol ) ;
64
62
symbol . insertBefore ( this . text ) ;
@@ -69,10 +67,27 @@ function Symbol(chart, options, symbol) {
69
67
70
68
this . initialize ( ) ;
71
69
}
70
+
72
71
}
72
+ /* Gets the attribute based on Flowstate, Symbol-Name and default, first found wins */
73
+ Symbol . prototype . getAttr = function ( attName ) {
74
+ if ( ! this . chart ) {
75
+ return undefined ;
76
+ }
77
+ var opt3 = ( this . chart . options ) ? this . chart . options [ attName ] : undefined ;
78
+ var opt2 = ( this . chart . options . symbols ) ? this . chart . options . symbols [ this . symbolType ] [ attName ] : undefined ;
79
+ var opt1 = undefined ;
80
+ if ( this . chart . options . flowstate ) {
81
+ if ( this . chart . options . flowstate [ this . flowstate ] ) {
82
+ opt1 = this . chart . options . flowstate [ this . flowstate ] [ attName ] ;
83
+ }
84
+ }
85
+ return ( opt1 || opt2 || opt3 ) ;
86
+ }
87
+
73
88
74
89
Symbol . prototype . initialize = function ( ) {
75
- this . group . transform ( 't' + ( this . chart . options . symbols [ this . symbolType ] [ 'line-width' ] || this . chart . options [ 'line-width' ] ) + ',' + ( this . chart . options . symbols [ this . symbolType ] [ 'line-width' ] || this . chart . options [ 'line-width' ] ) ) ;
90
+ this . group . transform ( 't' + this . getAttr ( 'line-width' ) + ',' + this . getAttr ( 'line-width' ) ) ;
76
91
77
92
this . width = this . group . getBBox ( ) . width ;
78
93
this . height = this . group . getBBox ( ) . height ;
@@ -134,7 +149,7 @@ Symbol.prototype.getRight = function() {
134
149
Symbol . prototype . render = function ( ) {
135
150
if ( this . next ) {
136
151
137
- var lineLength = this . chart . options . symbols [ this . symbolType ] [ 'line-length' ] || this . chart . options [ 'line-length' ] ;
152
+ var lineLength = this . getAttr ( 'line-length' ) ;
138
153
139
154
if ( this . next_direction === 'right' ) {
140
155
@@ -223,8 +238,8 @@ Symbol.prototype.drawLineTo = function(symbol, text, origin) {
223
238
224
239
var maxX = 0 ,
225
240
line ,
226
- lineLength = this . chart . options . symbols [ this . symbolType ] [ 'line-length' ] || this . chart . options [ 'line-length' ] ,
227
- lineWith = this . chart . options . symbols [ this . symbolType ] [ 'line-width' ] || this . chart . options [ 'line-width' ] ;
241
+ lineLength = this . getAttr ( 'line-length' ) ,
242
+ lineWith = this . getAttr ( 'line-width' ) ;
228
243
229
244
if ( ( ! origin || origin === 'bottom' ) && isOnSameColumn && isUnder ) {
230
245
line = drawLine ( this . chart , bottom , symbolTop , text ) ;
0 commit comments