Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: tools/deep_memory_profiler/visualizer/dropdown-view.js

Issue 23777005: Modified directory preparing for app engine for dmprof visualizer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove index.js Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * This is a view class showing subs of selected item.
7 * TODO(junjianx): use dropdown menu to show.
8 * @param {Object} profiler Must have addListener method.
9 * @construct
10 */
11 var DropdownView = function(profiler) {
12 this.profiler_ = profiler;
13 this.placeholder_ = '#subs-dropdown';
14 // Clear state when profiler model changed.
15 profiler.addListener('changed', this.redraw_.bind(this));
16 profiler.addListener('changed:selected', this.update_.bind(this));
17 };
18
19 /**
20 * Render new dropdown at first time being called and recover otherwise.
21 * @private
22 */
23 DropdownView.prototype.redraw_ = function() {
24 var self = this;
25
26 var data = [{ label: 'subs' }];
27 if (!this.$tree_) {
28 this.$tree_ = $(this.placeholder_).tree({
29 data: data,
30 autoOpen: true
31 });
32
33 // Delegate click event to profiler.
34 this.$tree_.bind('tree.click', function(event) {
35 event.preventDefault();
36 self.profiler_.setSub(event.node.id);
37 });
38 } else {
39 this.$tree_.tree('loadData', data);
40 }
41 };
42
43 /**
44 * Update dropdown view when new model is selected in menu view.
45 * @param {string} id Model id.
46 * @private
47 */
48 DropdownView.prototype.update_ = function(id) {
49 var self = this;
50
51 // Get all subs of selected model.
52 var prof = this.profiler_;
53 var models = prof.getModelsbyId(id);
54 var children = models.reduce(function(previous, current) {
55 if ('subs' in current) {
56 current.subs.forEach(function(sub) {
57 var id = sub.join(',');
58 var label = sub.join(':');
59 if (!previous.some(function(sub) {
60 return sub.id === id;
61 })) {
62 var child = {
63 id: id,
64 label: label
65 };
66 previous.push(child);
67 }
68 });
69 }
70 return previous;
71 }, []);
72
73 // Update data of subs tree.
74 var data = [{
75 label: 'subs',
76 children: children
77 }];
78 var $tree = this.$tree_;
79 $tree.tree('loadData', data);
80
81 // Select current sub if exists.
82 var curSub = prof.getCurSubById(id);
83 if (curSub) {
84 var node = $tree.tree('getNodeById', curSub);
85 $tree.tree('selectNode', node);
86 $tree.tree('scrollToNode', node);
87 }
88 };
OLDNEW
« no previous file with comments | « tools/deep_memory_profiler/.gitignore ('k') | tools/deep_memory_profiler/visualizer/graph-view.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698