@@ -9,7 +9,7 @@ function Neod3Renderer() {
9
9
text-color-internal: #000000;\
10
10
text-color-external: #000000;\
11
11
caption: '{name}';\
12
- font-size: 10px ;\
12
+ font-size: 12px ;\
13
13
}\
14
14
relationship {\
15
15
color: #4356C0;\
@@ -30,8 +30,18 @@ function Neod3Renderer() {
30
30
} ) ;
31
31
var downloadSvgLink = $downloadSvgLink [ 0 ] ;
32
32
var blobSupport = 'Blob' in window ;
33
- var URLSupport = 'URL' in window && 'createObjectURL' in window . URL
33
+ var URLSupport = 'URL' in window && 'createObjectURL' in window . URL ;
34
34
var msBlobSupport = typeof window . navigator . msSaveOrOpenBlob !== 'undefined' ;
35
+ var svgStyling = '<style>\ntext{font-family:sans-serif}\n</style>' ;
36
+ var stylingUrl = window . location . hostname === 'www.neo4j.org' ? 'http://gist.neo4j.org/css/neod3' : 'css/neod3' ;
37
+ if ( window . isInternetExplorer ) {
38
+ stylingUrl += '-ie.css' ;
39
+ } else {
40
+ stylingUrl += '.css' ;
41
+ }
42
+
43
+ var existingStyles = { } ;
44
+ var currentColor = 1 ;
35
45
36
46
function dummyFunc ( ) {
37
47
}
@@ -59,14 +69,14 @@ function Neod3Renderer() {
59
69
for ( var i = 0 ; i < nodes . length ; i ++ ) {
60
70
var props = nodes [ i ] . properties = extract_props ( nodes [ i ] ) ;
61
71
var keys = Object . keys ( props ) ;
62
- if ( label ( nodes [ i ] ) != "" && keys . length > 0 ) {
72
+ if ( label ( nodes [ i ] ) !== "" && keys . length > 0 ) {
63
73
var selected_keys = prio_props . filter ( function ( k ) {
64
- return keys . indexOf ( k ) != - 1
74
+ return keys . indexOf ( k ) !== - 1
65
75
} ) ;
66
76
selected_keys = selected_keys . concat ( keys ) . concat ( [ 'id' ] ) ;
67
77
var selector = "node." + label ( nodes [ i ] ) ;
68
78
var selectedKey = selected_keys [ 0 ] ;
69
- if ( typeof ( props [ selectedKey ] ) == "string" && props [ selectedKey ] . length > 30 ) {
79
+ if ( typeof ( props [ selectedKey ] ) === "string" && props [ selectedKey ] . length > 30 ) {
70
80
props [ selectedKey ] = props [ selectedKey ] . substring ( 0 , 30 ) + " ..." ;
71
81
}
72
82
style [ selector ] = style [ selector ] || selectedKey ;
@@ -75,20 +85,29 @@ function Neod3Renderer() {
75
85
return style ;
76
86
}
77
87
78
- function style_sheet ( style , styleContents ) {
79
- var styleSheet = "" ;
80
- var c = 1 ;
88
+ function style_sheet ( styles , styleContents ) {
89
+ var styleItems = [ ] ;
81
90
var colors = neo . style . defaults . colors ;
82
- for ( var k in style ) {
83
- var color = colors [ c ] ;
84
- c = ( c + 1 ) % colors . length
85
- styleSheet += "\n" + k + " {caption: '{" + style [ k ] + "}'; color: " + color . color +
86
- "; border-color: " + color [ 'border-color' ] +
87
- "; text-color-internal: #000000" + // + color['text-color-internal'] +
88
- "; text-color-external: #000000" + // + color['text-color-internal'] +
89
- "; }\n" ;
91
+ for ( var selector in styles ) {
92
+ var styleItem ;
93
+ if ( selector in existingStyles ) {
94
+ styleItem = existingStyles [ selector ] ;
95
+ } else {
96
+ var color = colors [ currentColor ] ;
97
+ currentColor = ( currentColor + 1 ) % colors . length ;
98
+ var textColor = window . isInternetExplorer ? '#000000' : color [ 'text-color-internal' ] ;
99
+ styleItem = selector +
100
+ " {caption: '{" + styles [ selector ] +
101
+ "}'; color: " + color . color +
102
+ "; border-color: " + color [ 'border-color' ] +
103
+ "; text-color-internal: " + textColor +
104
+ "; text-color-external: " + textColor +
105
+ "; }" ;
106
+ existingStyles [ selector ] = styleItem ;
107
+ }
108
+ styleItems . push ( styleItem ) ;
90
109
}
91
- return styleContents + styleSheet ;
110
+ return styleContents + styleItems . join ( "\n" ) ;
92
111
}
93
112
94
113
function applyZoom ( ) {
@@ -132,8 +151,8 @@ function Neod3Renderer() {
132
151
links [ i ] . target = links [ i ] . end ;
133
152
links [ i ] . properties = props ( links [ i ] ) ;
134
153
}
135
- var nodeStyle = node_styles ( nodes ) ;
136
- var styleSheet = style_sheet ( nodeStyle , styleContents )
154
+ var nodeStyles = node_styles ( nodes ) ;
155
+ var styleSheet = style_sheet ( nodeStyles , styleContents ) ;
137
156
138
157
var graphModel = neo . graphModel ( )
139
158
. nodes ( nodes )
@@ -216,9 +235,15 @@ function Neod3Renderer() {
216
235
}
217
236
}
218
237
var svg = serializer ( element ) ;
219
- svg = svg . replace ( '<svg ' , '<svg height="' + $container . height ( ) + '" width="' + $container . width ( ) + '" style="font-family: sans-serif;" ' ) ;
238
+ svg = svg . replace ( '<svg ' , '<svg height="' + $container . height ( ) + '" width="' + $container . width ( ) + '" ' )
239
+ . replace ( / < g / , '\n' + svgStyling + '\n<g' ) ;
220
240
return svg ;
221
241
}
222
242
243
+ $ . get ( stylingUrl , function ( data ) {
244
+ svgStyling = '<style>\n' + data + '\n</style>' ;
245
+ $ ( svgStyling ) . appendTo ( 'head' ) ;
246
+ } ) ;
247
+
223
248
return { 'render' : render } ;
224
249
}
0 commit comments