|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +function drawApplicationTimeline(groupArray, eventObjArray, startTime) { |
| 19 | + var groups = new vis.DataSet(groupArray); |
| 20 | + var items = new vis.DataSet(eventObjArray); |
| 21 | + var container = $("#application-timeline")[0]; |
| 22 | + var options = { |
| 23 | + groupOrder: function(a, b) { |
| 24 | + return a.value - b.value |
| 25 | + }, |
| 26 | + editable: false, |
| 27 | + showCurrentTime: false, |
| 28 | + min: startTime, |
| 29 | + zoomable: false |
| 30 | + }; |
| 31 | + |
| 32 | + var applicationTimeline = new vis.Timeline(container); |
| 33 | + applicationTimeline.setOptions(options); |
| 34 | + applicationTimeline.setGroups(groups); |
| 35 | + applicationTimeline.setItems(items); |
| 36 | + |
| 37 | + setupZoomable("#application-timeline-zoom-lock", applicationTimeline); |
| 38 | + setupExecutorEventAction(); |
| 39 | + |
| 40 | + function setupJobEventAction() { |
| 41 | + $(".item.range.job.application-timeline-object").each(function() { |
| 42 | + var getJobId = function(baseElem) { |
| 43 | + var jobIdText = $($(baseElem).find(".application-timeline-content")[0]).text(); |
| 44 | + var jobId = jobIdText.match("\\(Job (\\d+)\\)")[1]; |
| 45 | + return jobId; |
| 46 | + }; |
| 47 | + |
| 48 | + $(this).click(function() { |
| 49 | + window.location.href = "job/?id=" + getJobId(this); |
| 50 | + }); |
| 51 | + |
| 52 | + $(this).hover( |
| 53 | + function() { |
| 54 | + $("#job-" + getJobId(this)).addClass("corresponding-item-hover"); |
| 55 | + $($(this).find("div.application-timeline-content")[0]).tooltip("show"); |
| 56 | + }, |
| 57 | + function() { |
| 58 | + $("#job-" + getJobId(this)).removeClass("corresponding-item-hover"); |
| 59 | + $($(this).find("div.application-timeline-content")[0]).tooltip("hide"); |
| 60 | + } |
| 61 | + ); |
| 62 | + }); |
| 63 | + } |
| 64 | + |
| 65 | + setupJobEventAction(); |
| 66 | + |
| 67 | + $("span.expand-application-timeline").click(function() { |
| 68 | + $("#application-timeline").toggleClass('collapsed'); |
| 69 | + |
| 70 | + // Switch the class of the arrow from open to closed. |
| 71 | + $(this).find('.expand-application-timeline-arrow').toggleClass('arrow-open'); |
| 72 | + $(this).find('.expand-application-timeline-arrow').toggleClass('arrow-closed'); |
| 73 | + }); |
| 74 | +} |
| 75 | + |
| 76 | +function drawJobTimeline(groupArray, eventObjArray, startTime) { |
| 77 | + var groups = new vis.DataSet(groupArray); |
| 78 | + var items = new vis.DataSet(eventObjArray); |
| 79 | + var container = $('#job-timeline')[0]; |
| 80 | + var options = { |
| 81 | + groupOrder: function(a, b) { |
| 82 | + return a.value - b.value; |
| 83 | + }, |
| 84 | + editable: false, |
| 85 | + showCurrentTime: false, |
| 86 | + min: startTime, |
| 87 | + zoomable: false, |
| 88 | + }; |
| 89 | + |
| 90 | + var jobTimeline = new vis.Timeline(container); |
| 91 | + jobTimeline.setOptions(options); |
| 92 | + jobTimeline.setGroups(groups); |
| 93 | + jobTimeline.setItems(items); |
| 94 | + |
| 95 | + setupZoomable("#job-timeline-zoom-lock", jobTimeline); |
| 96 | + setupExecutorEventAction(); |
| 97 | + |
| 98 | + function setupStageEventAction() { |
| 99 | + $(".item.range.stage.job-timeline-object").each(function() { |
| 100 | + var getStageIdAndAttempt = function(baseElem) { |
| 101 | + var stageIdText = $($(baseElem).find(".job-timeline-content")[0]).text(); |
| 102 | + var stageIdAndAttempt = stageIdText.match("\\(Stage (\\d+\\.\\d+)\\)")[1].split("."); |
| 103 | + return stageIdAndAttempt; |
| 104 | + }; |
| 105 | + |
| 106 | + $(this).click(function() { |
| 107 | + var idAndAttempt = getStageIdAndAttempt(this); |
| 108 | + var id = idAndAttempt[0]; |
| 109 | + var attempt = idAndAttempt[1]; |
| 110 | + window.location.href = "../../stages/stage/?id=" + id + "&attempt=" + attempt; |
| 111 | + }); |
| 112 | + |
| 113 | + $(this).hover( |
| 114 | + function() { |
| 115 | + var idAndAttempt = getStageIdAndAttempt(this); |
| 116 | + var id = idAndAttempt[0]; |
| 117 | + var attempt = idAndAttempt[1]; |
| 118 | + $("#stage-" + id + "-" + attempt).addClass("corresponding-item-hover"); |
| 119 | + $($(this).find("div.job-timeline-content")[0]).tooltip("show"); |
| 120 | + }, |
| 121 | + function() { |
| 122 | + var idAndAttempt = getStageIdAndAttempt(this); |
| 123 | + var id = idAndAttempt[0]; |
| 124 | + var attempt = idAndAttempt[1]; |
| 125 | + $("#stage-" + id + "-" + attempt).removeClass("corresponding-item-hover"); |
| 126 | + $($(this).find("div.job-timeline-content")[0]).tooltip("hide"); |
| 127 | + } |
| 128 | + ); |
| 129 | + }); |
| 130 | + } |
| 131 | + |
| 132 | + setupStageEventAction(); |
| 133 | + |
| 134 | + $("span.expand-job-timeline").click(function() { |
| 135 | + $("#job-timeline").toggleClass('collapsed'); |
| 136 | + |
| 137 | + // Switch the class of the arrow from open to closed. |
| 138 | + $(this).find('.expand-job-timeline-arrow').toggleClass('arrow-open'); |
| 139 | + $(this).find('.expand-job-timeline-arrow').toggleClass('arrow-closed'); |
| 140 | + }); |
| 141 | +} |
| 142 | + |
| 143 | +function setupExecutorEventAction() { |
| 144 | + $(".item.box.executor").each(function () { |
| 145 | + $(this).hover( |
| 146 | + function() { |
| 147 | + $($(this).find(".executor-event-content")[0]).tooltip("show"); |
| 148 | + }, |
| 149 | + function() { |
| 150 | + $($(this).find(".executor-event-content")[0]).tooltip("hide"); |
| 151 | + } |
| 152 | + ); |
| 153 | + }); |
| 154 | +} |
| 155 | + |
| 156 | +function setupZoomable(id, timeline) { |
| 157 | + $(id + '>input[type="checkbox"]').click(function() { |
| 158 | + if (this.checked) { |
| 159 | + timeline.setOptions({zoomable: false}); |
| 160 | + } else { |
| 161 | + timeline.setOptions({zoomable: true}); |
| 162 | + } |
| 163 | + }); |
| 164 | + |
| 165 | + $(id + ">span").click(function() { |
| 166 | + $(this).parent().find('input:checkbox').trigger('click'); |
| 167 | + }); |
| 168 | +} |
0 commit comments