451a4f564a1292d1661bf027379afccee090e1e0
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / ScriptTimelineOverviewGraph.js
1 /*
2  * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 WebInspector.ScriptTimelineOverviewGraph = class ScriptTimelineOverviewGraph extends WebInspector.TimelineOverviewGraph
27 {
28     constructor(timeline, timelineOverview)
29     {
30         super(timelineOverview);
31
32         this.element.classList.add("script");
33
34         this._scriptTimeline = timeline;
35         this._scriptTimeline.addEventListener(WebInspector.Timeline.Event.RecordAdded, this._scriptTimelineRecordAdded, this);
36
37         this._timelineRecordBars = [];
38
39         this.reset();
40     }
41
42     // Public
43
44     reset()
45     {
46         super.reset();
47
48         this._timelineRecordBarMap = new Map;
49
50         this.element.removeChildren();
51     }
52
53     updateLayout()
54     {
55         super.updateLayout();
56
57         var secondsPerPixel = this.timelineOverview.secondsPerPixel;
58
59         var recordBarIndex = 0;
60
61         function createBar(records, renderMode)
62         {
63             var timelineRecordBar = this._timelineRecordBars[recordBarIndex];
64             if (!timelineRecordBar)
65                 timelineRecordBar = this._timelineRecordBars[recordBarIndex] = new WebInspector.TimelineRecordBar(records, renderMode);
66             else {
67                 timelineRecordBar.renderMode = renderMode;
68                 timelineRecordBar.records = records;
69             }
70             timelineRecordBar.refresh(this);
71             if (!timelineRecordBar.element.parentNode)
72                 this.element.appendChild(timelineRecordBar.element);
73             ++recordBarIndex;
74         }
75
76         // Create bars for non-GC records and GC records.
77         let [gcRecords, nonGCRecords] = this._scriptTimeline.records.partition((x) => x.isGarbageCollection());
78         let boundCreateBar = createBar.bind(this);
79         WebInspector.TimelineRecordBar.createCombinedBars(nonGCRecords, secondsPerPixel, this, boundCreateBar);
80         WebInspector.TimelineRecordBar.createCombinedBars(gcRecords, secondsPerPixel, this, boundCreateBar);
81
82         // Remove the remaining unused TimelineRecordBars.
83         for (; recordBarIndex < this._timelineRecordBars.length; ++recordBarIndex) {
84             this._timelineRecordBars[recordBarIndex].records = null;
85             this._timelineRecordBars[recordBarIndex].element.remove();
86         }
87     }
88
89     // Private
90
91     _scriptTimelineRecordAdded(event)
92     {
93         this.needsLayout();
94     }
95 };