Chromium Code Reviews| Index: masters/master.chromium/public_html/gantt_chart.js |
| diff --git a/masters/master.chromium/public_html/gantt_chart.js b/masters/master.chromium/public_html/gantt_chart.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..63504421da8234046a14954f4896bf9611960e62 |
| --- /dev/null |
| +++ b/masters/master.chromium/public_html/gantt_chart.js |
| @@ -0,0 +1,84 @@ |
| +google.charts.load('current', {'packages':['gantt']}); |
|
dsansome
2016/11/08 04:49:11
Add a copyright header:
// Copyright 2016 The Chr
philwright
2016/11/09 04:58:38
Done.
|
| + |
| +/* |
|
dsansome
2016/11/08 04:49:11
Use JSDoc style comments: https://engdoc.corp.goog
philwright
2016/11/09 04:58:38
Done.
|
| +reconcileSwarmingSteps reconciles a Swarming step's "trigger" step with |
| +it's subsequent "collect results" step. |
| + |
| +Swarming steps in BuildBot create two steps - one to trigger the work |
| +on swarming, and a later step to collect the results. |
| + |
| +The two steps have the same name, except the trigger step has "[trigger] " |
| +prepended to the name. |
| + |
| +This function consolidates the two steps into one by using the start |
| +time from the trigger step and the end time from the "collect results" |
| +step. |
| + |
| +This function assumes that a trigger step will be found before the |
| +corresponding "collect results" step in the list of steps. |
| +*/ |
| +function reconcileSwarmingSteps(steps) { |
| + var reconciledSteps = []; |
|
dsansome
2016/11/08 04:49:11
s/var/let/
philwright
2016/11/09 04:58:38
Done.
|
| + var triggerSteps = {}; |
| + |
| + for (i = 0; i < steps.length; i++) { |
|
dsansome
2016/11/08 04:49:11
Use for...of (https://developer.mozilla.org/en-US/
philwright
2016/11/09 04:58:38
Done.
|
| + s = steps[i]; |
| + // trigger steps have names like "[trigger] TheRestOfTheNameGoesHere..." |
| + isTriggerStep = /\[trigger\] (.*)/.exec(s.name); |
|
dsansome
2016/11/08 04:49:11
Always scope local variables using "let".
philwright
2016/11/09 04:58:38
Done.
|
| + if (isTriggerStep) { |
| + triggerSteps[isTriggerStep[1]] = s; |
| + } else { |
| + if (triggerSteps[s.name]) { |
| + s.start = triggerSteps[s.name].start; |
| + } |
| + reconciledSteps.push(s); |
| + } |
| + } |
| + |
| + return reconciledSteps; |
| +}; |
| + |
| +function drawChart(steps) { |
| + var data = new google.visualization.DataTable(); |
| + data.addColumn('string', 'Task ID'); |
| + data.addColumn('string', 'Task Name'); |
| + data.addColumn('string', 'Resource'); |
| + data.addColumn('date', 'Start Date'); |
| + data.addColumn('date', 'End Date'); |
| + data.addColumn('number', 'Duration'); |
| + data.addColumn('number', 'Percent Complete'); |
| + data.addColumn('string', 'Dependencies'); |
| + |
| + for (i = 0; i < steps.length; i++) { |
|
dsansome
2016/11/08 04:49:11
for..of
philwright
2016/11/09 04:58:38
Done.
|
| + var s = steps[i]; |
| + data.addRows([['' + i, s.name, null, s.start, s.end, null, 100, null]]); |
| + } |
| + |
| + var trackHeight = 25 |
| + var options = { |
| + height: data.getNumberOfRows() * trackHeight, |
| + gantt: { |
| + trackHeight: trackHeight, |
| + barHeight: trackHeight * 0.8, |
| + labelMaxWidth: 500 |
|
dsansome
2016/11/08 04:49:11
Trailing commas are OK now: https://engdoc.corp.go
philwright
2016/11/09 04:58:38
Done.
|
| + } |
| + }; |
| + |
| + var chart = new google.visualization.Gantt( |
| + document.getElementById('chart_div') |
|
dsansome
2016/11/08 04:49:11
4-space indentation here
philwright
2016/11/09 04:58:38
Done.
|
| + ); |
|
dsansome
2016/11/08 04:49:11
And put this on the line above
philwright
2016/11/09 04:58:38
Done.
|
| + chart.draw(data, options); |
| +} |
| + |
| +var chartVisible = false; |
| +function toggleChart(rawSteps) { |
| + if (chartVisible) { |
| + document.getElementById('chart_div').style.display = 'none'; |
| + chartVisible = false; |
| + } else { |
| + document.getElementById('chart_div').style.display = 'block'; |
| + var steps = reconcileSwarmingSteps(rawSteps); |
| + drawChart(steps); |
| + chartVisible = true; |
| + } |
| +} |