52
52
*/
53
53
54
54
var VizConstants = {
55
- rddColor : "#444444" ,
56
- rddCachedColor : "#FF0000" ,
57
- rddOperationColor : "#AADFFF" ,
58
- stageColor : "#FFDDEE" ,
59
- clusterLabelColor : "#888888" ,
60
- edgeColor : "#444444" ,
61
- edgeWidth : "1.5px" ,
62
55
svgMarginX : 20 ,
63
56
svgMarginY : 20 ,
64
57
stageSep : 50 ,
@@ -113,17 +106,21 @@ function toggleDagViz(forJob) {
113
106
function renderDagViz ( forJob ) {
114
107
115
108
// If there is not a dot file to render, fail fast and report error
109
+ var jobOrStage = forJob ? "job" : "stage" ;
116
110
if ( metadataContainer ( ) . empty ( ) ) {
117
111
graphContainer ( ) . append ( "div" ) . text (
118
- "No visualization information available for this " + ( forJob ? "job" : "stage" ) ) ;
112
+ "No visualization information available for this " + jobOrStage ) ;
119
113
return ;
120
114
}
121
115
122
- var svg = graphContainer ( ) . append ( "svg" ) ;
116
+ var svg = graphContainer ( ) . append ( "svg" ) . attr ( "class" , jobOrStage ) ;
117
+
123
118
if ( forJob ) {
124
119
renderDagVizForJob ( svg ) ;
120
+ postProcessDagVizForJob ( ) ;
125
121
} else {
126
122
renderDagVizForStage ( svg ) ;
123
+ postProcessDagVizForStage ( ) ;
127
124
}
128
125
129
126
// Find cached RDDs
@@ -137,9 +134,17 @@ function renderDagViz(forJob) {
137
134
138
135
//
139
136
resizeSvg ( svg ) ;
137
+ }
140
138
141
- //
142
- styleDagViz ( forJob ) ;
139
+ function postProcessDagVizForJob ( ) {
140
+ }
141
+
142
+ function postProcessDagVizForStage ( ) {
143
+ // Round corners on RDDs on the stage page
144
+ graphContainer ( )
145
+ . selectAll ( "svg.stage g.node rect" )
146
+ . attr ( "rx" , "5" )
147
+ . attr ( "ry" , "5" ) ;
143
148
}
144
149
145
150
/*
@@ -216,6 +221,7 @@ function renderDagVizForJob(svgContainer) {
216
221
var crossStageEdges = [ ] ;
217
222
218
223
metadataContainer ( ) . selectAll ( ".stage-metadata" ) . each ( function ( d , i ) {
224
+ // Set up container
219
225
var metadata = d3 . select ( this ) ;
220
226
var dot = metadata . select ( ".dot-file" ) . text ( ) ;
221
227
var stageId = metadata . attr ( "stageId" ) ;
@@ -226,11 +232,14 @@ function renderDagVizForJob(svgContainer) {
226
232
var container = svgContainer
227
233
. append ( "a" ) . attr ( "xlink:href" , stageLink )
228
234
. append ( "g" ) . attr ( "id" , containerId ) ;
235
+
229
236
// Now we need to shift the container for this stage so it doesn't overlap
230
237
// with existing ones. We do not need to do this for the first stage.
231
238
if ( i > 0 ) {
232
239
// Take into account the position and width of the last stage's container
233
- var existingStages = stageClusters ( ) ;
240
+ var existingStages = graphContainer ( )
241
+ . selectAll ( "svg g.cluster" )
242
+ . filter ( "[id*=\"" + VizConstants . stageClusterPrefix + "\"]" ) ;
234
243
if ( ! existingStages . empty ( ) ) {
235
244
var lastStage = d3 . select ( existingStages [ 0 ] . pop ( ) ) ;
236
245
var lastStageId = lastStage . attr ( "id" ) ;
@@ -262,25 +271,6 @@ function renderDagVizForJob(svgContainer) {
262
271
connectRDDs ( fromRDDId , toRDDId , container ) ;
263
272
}
264
273
}
265
- }
266
-
267
- /* Render the dot file as an SVG in the given container. */
268
- function renderDot ( dot , container ) {
269
- var escaped_dot = dot
270
- . replace ( / & l t ; / g, "<" )
271
- . replace ( / & g t ; / g, ">" )
272
- . replace ( / & q u o t ; / g, "\"" ) ;
273
- var g = graphlibDot . read ( escaped_dot ) ;
274
- var renderer = new dagreD3 . render ( ) ;
275
- renderer ( container , g ) ;
276
- }
277
-
278
- /* Style the visualization we just rendered. */
279
- function styleDagViz ( forJob ) {
280
- graphContainer ( )
281
- . selectAll ( "svg path" )
282
- . style ( "stroke" , VizConstants . edgeColor )
283
- . style ( "stroke-width" , VizConstants . edgeWidth ) ;
284
274
285
275
// Put an arrow at the end of every edge
286
276
// We need to do this because we manually render some edges ourselves
@@ -289,77 +279,19 @@ function styleDagViz(forJob) {
289
279
graphContainer ( ) . select ( "svg" )
290
280
. append ( function ( ) { return dagreD3Marker . cloneNode ( true ) ; } )
291
281
. attr ( "id" , "marker-arrow" )
292
- . select ( "path" )
293
- . attr ( "fill" , VizConstants . edgeColor )
294
- . attr ( "strokeWidth" , "0px" ) ;
295
282
graphContainer ( ) . selectAll ( "svg g > path" ) . attr ( "marker-end" , "url(#marker-arrow)" ) ;
296
283
graphContainer ( ) . selectAll ( "svg g.edgePaths def" ) . remove ( ) ; // We no longer need these
297
-
298
- // Apply any job or stage specific styles
299
- if ( forJob ) {
300
- styleDagVizForJob ( ) ;
301
- } else {
302
- styleDagVizForStage ( ) ;
303
- }
304
284
}
305
285
306
- /* Apply job-page-specific style to the visualization. */
307
- function styleDagVizForJob ( ) {
308
- graphContainer ( )
309
- . selectAll ( "svg g.cluster rect" )
310
- . style ( "fill" , "white" )
311
- . style ( "stroke" , VizConstants . rddOperationColor )
312
- . style ( "stroke-width" , "4px" )
313
- . style ( "stroke-opacity" , "0.5" ) ;
314
- stageClusters ( )
315
- . select ( "rect" )
316
- . style ( "stroke" , VizConstants . stageColor )
317
- . style ( "strokeWidth" , "6px" ) ;
318
- graphContainer ( )
319
- . selectAll ( "svg g.node circle" )
320
- . style ( "fill" , VizConstants . rddColor ) ;
321
- // TODO: add a legend to explain what a highlighted dot means
322
- graphContainer ( )
323
- . selectAll ( "svg g.cached circle" )
324
- . style ( "fill" , VizConstants . rddCachedColor ) ;
325
- graphContainer ( )
326
- . selectAll ( "svg g#cross-stage-edges path" )
327
- . style ( "fill" , "none" ) ;
328
- graphContainer ( )
329
- . selectAll ( "svg g.cluster text" )
330
- . attr ( "fill" , VizConstants . clusterLabelColor )
331
- . attr ( "font-size" , "11px" ) ;
332
- }
333
-
334
- /* Apply stage-page-specific style to the visualization. */
335
- function styleDagVizForStage ( ) {
336
- graphContainer ( )
337
- . selectAll ( "svg g.cluster rect" )
338
- . style ( "fill" , "#F0F8FF" )
339
- . style ( "stroke" , VizConstants . rddOperationColor )
340
- . style ( "stroke-width" , "4px" )
341
- . style ( "stroke-opacity" , "0.5" ) ;
342
- stageClusters ( )
343
- . select ( "rect" )
344
- . style ( "fill" , "white" )
345
- . style ( "stroke" , VizConstants . stageColor )
346
- . style ( "strokeWidth" , "6px" ) ;
347
- graphContainer ( )
348
- . selectAll ( "svg g.node rect" )
349
- . style ( "fill" , "#444444" )
350
- . attr ( "rx" , "5" ) // round corners
351
- . attr ( "ry" , "5" ) ;
352
- graphContainer ( )
353
- . selectAll ( "svg g.cached rect" )
354
- . style ( "fill" , VizConstants . rddCachedColor )
355
- graphContainer ( )
356
- . selectAll ( "svg g.node g.label text tspan" )
357
- . style ( "fill" , "white" ) ;
358
- graphContainer ( )
359
- . selectAll ( "svg g.cluster text" )
360
- . attr ( "fill" , "#444444" )
361
- . attr ( "font-size" , "14px" )
362
- . attr ( "font-weight" , "bold" )
286
+ /* Render the dot file as an SVG in the given container. */
287
+ function renderDot ( dot , container ) {
288
+ var escaped_dot = dot
289
+ . replace ( / & l t ; / g, "<" )
290
+ . replace ( / & g t ; / g, ">" )
291
+ . replace ( / & q u o t ; / g, "\"" ) ;
292
+ var g = graphlibDot . read ( escaped_dot ) ;
293
+ var renderer = new dagreD3 . render ( ) ;
294
+ renderer ( container , g ) ;
363
295
}
364
296
365
297
/*
@@ -371,10 +303,8 @@ function getAbsolutePosition(d3selection) {
371
303
throw "Attempted to get absolute position of an empty selection." ;
372
304
}
373
305
var obj = d3selection ;
374
- var _x = obj . attr ( "x" ) || 0 ,
375
- _y = obj . attr ( "y" ) || 0 ;
376
- _x = toFloat ( _x ) ;
377
- _y = toFloat ( _y ) ;
306
+ var _x = toFloat ( obj . attr ( "x" ) ) || 0 ;
307
+ var _y = toFloat ( obj . attr ( "y" ) ) || 0 ;
378
308
while ( ! obj . empty ( ) ) {
379
309
var transformText = obj . attr ( "transform" ) ;
380
310
if ( transformText ) {
@@ -395,7 +325,7 @@ function getAbsolutePosition(d3selection) {
395
325
/* (Job page only) Connect two RDD nodes with a curved edge. */
396
326
function connectRDDs ( fromRDDId , toRDDId , container ) {
397
327
var fromNodeId = VizConstants . nodePrefix + fromRDDId ;
398
- var toNodeId = VizConstants . nodePrefix + toRDDId
328
+ var toNodeId = VizConstants . nodePrefix + toRDDId ;
399
329
var fromPos = getAbsolutePosition ( graphContainer ( ) . select ( "#" + fromNodeId ) ) ;
400
330
var toPos = getAbsolutePosition ( graphContainer ( ) . select ( "#" + toNodeId ) ) ;
401
331
@@ -445,15 +375,12 @@ function connectRDDs(fromRDDId, toRDDId, container) {
445
375
container . append ( "path" ) . datum ( points ) . attr ( "d" , line ) ;
446
376
}
447
377
448
- /* Helper d3 accessor to clusters that represent stages. */
449
- function stageClusters ( ) {
450
- return graphContainer ( )
451
- . selectAll ( "svg g.cluster" )
452
- . filter ( "[id*=\"" + VizConstants . stageClusterPrefix + "\"]" ) ;
453
- }
454
-
455
378
/* Helper method to convert attributes to numeric values. */
456
379
function toFloat ( f ) {
457
- return parseFloat ( f . toString ( ) . replace ( / p x $ / , "" ) ) ;
380
+ if ( f ) {
381
+ return parseFloat ( f . toString ( ) . replace ( / p x $ / , "" ) ) ;
382
+ } else {
383
+ return f ;
384
+ }
458
385
}
459
386
0 commit comments