HTRACE-180 Move the GUI to a top-level subproject. (stack via cmccabe) Create new module named htrace-webapp to house webapp. Add a pom to it that generates a WAR file. Move the web dir from htrace-htraced to this new module at src/main/web Added a web.xml so WAR builds. Changed the symlink over in htrace-htraced/go/gobuild.sh to point at the new location. Fixed a bug where the java REST client was looking for htraced in the wrong location.
Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/d0554d53 Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/d0554d53 Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/d0554d53 Branch: refs/heads/master Commit: d0554d53af527f8d61b5948c828958dac3a915a2 Parents: 42b2f6a Author: stack <[email protected]> Authored: Wed Jun 17 15:49:26 2015 -0700 Committer: Colin Patrick McCabe <[email protected]> Committed: Wed Jun 17 15:59:40 2015 -0700 ---------------------------------------------------------------------- .gitignore | 5 +- htrace-htraced/go/gobuild.sh | 2 +- htrace-htraced/pom.xml | 7 + .../org/apache/htrace/util/HTracedProcess.java | 4 +- htrace-htraced/src/web/app/about_view.js | 33 - htrace-htraced/src/web/app/modal.js | 34 - htrace-htraced/src/web/app/predicate.js | 117 - htrace-htraced/src/web/app/predicate_view.js | 68 - htrace-htraced/src/web/app/query_results.js | 45 - htrace-htraced/src/web/app/router.js | 74 - htrace-htraced/src/web/app/search_result.js | 55 - htrace-htraced/src/web/app/search_results.js | 25 - .../src/web/app/search_results_view.js | 361 - htrace-htraced/src/web/app/search_view.js | 197 - htrace-htraced/src/web/app/server_info.js | 31 - htrace-htraced/src/web/app/span.js | 252 - htrace-htraced/src/web/app/span_details_view.js | 39 - htrace-htraced/src/web/app/span_group_widget.js | 110 - htrace-htraced/src/web/app/span_widget.js | 237 - htrace-htraced/src/web/app/string.js | 66 - htrace-htraced/src/web/app/time_cursor.js | 81 - htrace-htraced/src/web/app/tree.js | 74 - htrace-htraced/src/web/app/triangle_button.js | 108 - htrace-htraced/src/web/app/widget_manager.js | 62 - htrace-htraced/src/web/custom.css | 101 - htrace-htraced/src/web/image/owl.png | Bin 435334 -> 0 bytes htrace-htraced/src/web/index.html | 226 - htrace-htraced/src/web/lib/backbone-1.1.2.js | 1608 --- .../lib/bootstrap-3.3.1/css/bootstrap-theme.css | 470 - .../bootstrap-3.3.1/css/bootstrap-theme.css.map | 1 - .../bootstrap-3.3.1/css/bootstrap-theme.min.css | 5 - .../web/lib/bootstrap-3.3.1/css/bootstrap.css | 6332 ------------ .../lib/bootstrap-3.3.1/css/bootstrap.css.map | 1 - .../lib/bootstrap-3.3.1/css/bootstrap.min.css | 5 - .../src/web/lib/bootstrap-3.3.1/js/bootstrap.js | 2320 ----- .../web/lib/bootstrap-3.3.1/js/bootstrap.min.js | 7 - .../src/web/lib/bootstrap-3.3.1/js/npm.js | 13 - htrace-htraced/src/web/lib/jquery-2.1.4.js | 9210 ------------------ htrace-htraced/src/web/lib/moment-2.10.3.js | 3111 ------ htrace-htraced/src/web/lib/underscore-1.7.0.js | 1416 --- htrace-webapp/README.md | 21 + htrace-webapp/pom.xml | 104 + htrace-webapp/src/main/web/WEB-INF/web.xml | 20 + htrace-webapp/src/main/web/app/about_view.js | 33 + htrace-webapp/src/main/web/app/modal.js | 34 + htrace-webapp/src/main/web/app/predicate.js | 117 + .../src/main/web/app/predicate_view.js | 68 + htrace-webapp/src/main/web/app/query_results.js | 45 + htrace-webapp/src/main/web/app/router.js | 74 + htrace-webapp/src/main/web/app/search_result.js | 55 + .../src/main/web/app/search_results.js | 25 + .../src/main/web/app/search_results_view.js | 361 + htrace-webapp/src/main/web/app/search_view.js | 197 + htrace-webapp/src/main/web/app/server_info.js | 31 + htrace-webapp/src/main/web/app/span.js | 252 + .../src/main/web/app/span_details_view.js | 39 + .../src/main/web/app/span_group_widget.js | 110 + htrace-webapp/src/main/web/app/span_widget.js | 237 + htrace-webapp/src/main/web/app/string.js | 66 + htrace-webapp/src/main/web/app/time_cursor.js | 81 + htrace-webapp/src/main/web/app/tree.js | 74 + .../src/main/web/app/triangle_button.js | 108 + .../src/main/web/app/widget_manager.js | 62 + htrace-webapp/src/main/web/custom.css | 101 + htrace-webapp/src/main/web/image/owl.png | Bin 0 -> 435334 bytes htrace-webapp/src/main/web/index.html | 226 + .../src/main/web/lib/backbone-1.1.2.js | 1608 +++ .../lib/bootstrap-3.3.1/css/bootstrap-theme.css | 470 + .../bootstrap-3.3.1/css/bootstrap-theme.css.map | 1 + .../bootstrap-3.3.1/css/bootstrap-theme.min.css | 5 + .../web/lib/bootstrap-3.3.1/css/bootstrap.css | 6332 ++++++++++++ .../lib/bootstrap-3.3.1/css/bootstrap.css.map | 1 + .../lib/bootstrap-3.3.1/css/bootstrap.min.css | 5 + .../web/lib/bootstrap-3.3.1/js/bootstrap.js | 2320 +++++ .../web/lib/bootstrap-3.3.1/js/bootstrap.min.js | 7 + .../src/main/web/lib/bootstrap-3.3.1/js/npm.js | 13 + htrace-webapp/src/main/web/lib/jquery-2.1.4.js | 9210 ++++++++++++++++++ htrace-webapp/src/main/web/lib/moment-2.10.3.js | 3111 ++++++ .../src/main/web/lib/underscore-1.7.0.js | 1416 +++ pom.xml | 5 + 80 files changed, 27058 insertions(+), 26900 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 8735de5..4baf9e2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *~ *.swp dependency-reduced-pom.xml -htrace-htraced/src/go/build -htrace-htraced/src/go/pkg +htrace-htraced/go/build +htrace-htraced/go/pkg +htrace-htraced/go/web htrace-htraced/bin http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/go/gobuild.sh ---------------------------------------------------------------------- diff --git a/htrace-htraced/go/gobuild.sh b/htrace-htraced/go/gobuild.sh index 259e6a7..121d55b 100755 --- a/htrace-htraced/go/gobuild.sh +++ b/htrace-htraced/go/gobuild.sh @@ -108,7 +108,7 @@ install) go install ${TAGS} -ldflags "${FLAGS}" -v org/apache/htrace/... "$@" # Make a symlink to web src dir so can do development in-situ out # of build dir. This is ugly but blame go build. - ln -fs "../src/web" "${GOBIN}/../" + ln -fs "../../htrace-webapp/src/main/web" "${GOBIN}/../" ;; bench) go test org/apache/htrace/... ${TAGS} -test.bench=. "$@" http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/pom.xml ---------------------------------------------------------------------- diff --git a/htrace-htraced/pom.xml b/htrace-htraced/pom.xml index 09324b1..d775850 100644 --- a/htrace-htraced/pom.xml +++ b/htrace-htraced/pom.xml @@ -179,6 +179,13 @@ language governing permissions and limitations under the License. --> <classifier>tests</classifier> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.htrace</groupId> + <artifactId>htrace-webapp</artifactId> + <version>${project.version}</version> + <type>war</type> + <scope>provided</scope> + </dependency> <!-- Global deps. --> <dependency> <groupId>commons-logging</groupId> http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/test/java/org/apache/htrace/util/HTracedProcess.java ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/test/java/org/apache/htrace/util/HTracedProcess.java b/htrace-htraced/src/test/java/org/apache/htrace/util/HTracedProcess.java index 5fa5d95..3e800d2 100644 --- a/htrace-htraced/src/test/java/org/apache/htrace/util/HTracedProcess.java +++ b/htrace-htraced/src/test/java/org/apache/htrace/util/HTracedProcess.java @@ -166,7 +166,7 @@ public class HTracedProcess extends Process { * @return Path to the htraced binary. */ public static File getPathToHTraceBinaryFromTopLevel(final File topLevel) { - return new File(new File(new File(new File(new File(topLevel, "htrace-htraced"), "src"), "go"), - "build"), "htraced"); + return new File(new File(new File(new File(topLevel, "htrace-htraced"), "go"), "build"), + "htraced"); } } http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/about_view.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/about_view.js b/htrace-htraced/src/web/app/about_view.js deleted file mode 100644 index 7dfe868..0000000 --- a/htrace-htraced/src/web/app/about_view.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; -htrace.AboutView = Backbone.View.extend({ - render: function() { - this.$el.html(_.template($("#about-view-template").html()) - ({ model : this.model })); - console.log("AboutView#render"); - return this; - }, - - close: function() { - console.log("AboutView#close") - this.undelegateEvents(); - } -}); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/modal.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/modal.js b/htrace-htraced/src/web/app/modal.js deleted file mode 100644 index 91d55fe..0000000 --- a/htrace-htraced/src/web/app/modal.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -// Show a modal dialog box with a warning message. -htrace.showModalWarning = function(title, body) { - var html = _.template($("#modal-warning-template").html()) - ({ title: title, body: body }); - htrace.showModal(html); -} - -// Show a modal dialog box. -htrace.showModal = function(html) { - var el = $("#modal"); - el.html(html); - el.modal(); -} http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/predicate.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/predicate.js b/htrace-htraced/src/web/app/predicate.js deleted file mode 100644 index 87a5602..0000000 --- a/htrace-htraced/src/web/app/predicate.js +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -htrace.checkStringIsPositiveWholeNumber = function(val) { - if (!val.match(/^[0-9]([0-9]*)$/)) { - if (!val.match(/[^\s]/)) { - throw "You entered an empty string into a numeric field."; - } - throw "Non-numeric characters found."; - } -}; - -htrace.checkStringIsNotEmpty = function(val) { - if (!val.match(/[^\s]/)) { - throw "You entered an empty string into a text field."; - } -}; - -// Predicate type -htrace.PType = Backbone.Model.extend({ - initialize: function(options) { - this.name = options.name; - this.field = options.field; - this.op = options.op; - }, - - // Try to normalize a value of this type into something htraced can accept. - // Returns a string containing the normalized value on success. Throws a - // string explaining the parse error otherwise. - // Dates are represented by milliseconds since the epoch; span ids don't start - // with 0x. - normalize: function(val) { - switch (this.field) { - case "begin": - return htrace.parseDate(val).valueOf().toString(); - case "end": - return htrace.parseDate(val).valueOf().toString(); - case "description": - htrace.checkStringIsNotEmpty(val); - return val; - case "duration": - htrace.checkStringIsPositiveWholeNumber(val); - return val; - case "spanid": - return htrace.normalizeSpanId(val); - default: - return "Normalization not implemented for field '" + this.field + "'"; - } - }, - - getDefaultValue: function() { - switch (this.field) { - case "begin": - return htrace.dateToString(moment()); - case "end": - return htrace.dateToString(moment()); - case "description": - return ""; - case "duration": - return "0"; - case "spanid": - return ""; - default: - return "(unknown)"; - } - } -}); - -htrace.parsePType = function(name) { - switch (name) { - case "Began after": - return new htrace.PType({name: name, field:"begin", op:"gt"}); - case "Began at or before": - return new htrace.PType({name: name, field:"begin", op:"le"}); - case "Ended after": - return new htrace.PType({name: name, field:"end", op:"gt"}); - case "Ended at or before": - return new htrace.PType({name: name, field:"end", op:"le"}); - case "Description contains": - return new htrace.PType({name: name, field:"description", op:"cn"}); - case "Description is exactly": - return new htrace.PType({name: name, field:"description", op:"eq"}); - case "Duration is longer than": - return new htrace.PType({name: name, field:"duration", op:"gt"}); - case "Duration is at most": - return new htrace.PType({name: name, field:"duration", op:"le"}); - case "Span ID is": - return new htrace.PType({name: name, field:"spanid", op:"eq"}); - default: - return null - } -}; - -htrace.Predicate = function(options) { - this.op = options.ptype.op; - this.field = options.ptype.field; - this.val = options.val; - return this; -}; http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/predicate_view.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/predicate_view.js b/htrace-htraced/src/web/app/predicate_view.js deleted file mode 100644 index aefe896..0000000 --- a/htrace-htraced/src/web/app/predicate_view.js +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -htrace.PredicateView = Backbone.View.extend({ - initialize: function(options) { - this.el = options.el; - this.index = options.index; - this.ptype = options.ptype; - this.searchView = options.searchView; - }, - - events: { - "click .closeButton": "remove", - }, - - render: function() { - this.$el.html(_.template($("#predicate-template").html()) - ({ desc: this.ptype.name, id: this.index })) - if (this.getText() === "") { - $(this.$el).find(".form-control").val(this.ptype.getDefaultValue()); - } - console.log(this.toString() + "#render"); - return this; - }, - - // Handle the user removing this predicate. - remove: function() { - this.searchView.removePredicateView(this); - Backbone.View.prototype.remove.apply(this, arguments); - }, - - // Get the text which the user has entered in. - getText: function() { - return $(this.$el).find(".form-control").val().trim(); - }, - - // Get the predicate expressed by this view. - // Throw an exception if the predicate can't be parsed. - getPredicate: function() { - return new htrace.Predicate({ - ptype: this.ptype, - val: this.ptype.normalize(this.getText()) - }); - }, - - toString: function() { - return "PredicateView(this.el=" + this.el + ", this.index=" + - this.index + ", this.ptype='" + this.ptype.name + "')"; - } -}); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/query_results.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/query_results.js b/htrace-htraced/src/web/app/query_results.js deleted file mode 100644 index dc37e1e..0000000 --- a/htrace-htraced/src/web/app/query_results.js +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -htrace.QueryResults = Backbone.Collection.extend({ - // The query results are spans. - model: htrace.Span, - - initialize: function(options) { - this.queryJson = options.queryJson; - }, - - url: function() { - return "query?query=" + this.queryString(); - }, - - parse: function(response, xhr) { - return response; - }, - - prettyQueryString: function() { - return JSON.stringify(this.queryJson, null, 2); - }, - - queryString: function() { - return JSON.stringify(this.queryJson); - } -}); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/router.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/router.js b/htrace-htraced/src/web/app/router.js deleted file mode 100644 index 607da44..0000000 --- a/htrace-htraced/src/web/app/router.js +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -htrace.HTraceRouter = Backbone.Router.extend({ - "routes": { - "": "empty", - "about": "about", - "search": "search", - "*unknown": "unknown" - }, - - empty: function() { - console.log("Redirecting to #about."); - Backbone.history.navigate("about", {"trigger": true, "replace": true}); - }, - - about: function() { - console.log("Visiting #about."); - serverInfo = new htrace.ServerInfo(); - var router = this; - serverInfo.fetch({ - "success": function(model, response, options) { - router.switchView(new htrace.AboutView({model: serverInfo, el: "#app"})); - router.activateNavBarEntry("about") - }, - "error": function(model, response, options) { - window.alert("Failed to fetch htraced server info via GET " + - "/server/info: " + JSON.stringify(response)); - } - }); - }, - - search: function() { - console.log("Visiting #search."); - this.switchView(new htrace.SearchView({el : "#app"})); - htrace.router.activateNavBarEntry("search"); - }, - - unknown: function() { - console.log("Unknown route " + Backbone.history.getFragment() + ".") - }, - - "switchView": function(view) { - this.view && this.view.close(); - this.view = view; - this.view.render(); - }, - - "activateNavBarEntry": function(id) { - $(".nav").find(".active").removeClass("active"); - $(".nav").find("#" + id).addClass("active"); - } -}); - -htrace.router = new htrace.HTraceRouter(); -Backbone.history.start(); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/search_result.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/search_result.js b/htrace-htraced/src/web/app/search_result.js deleted file mode 100644 index 9798ad7..0000000 --- a/htrace-htraced/src/web/app/search_result.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -// A pair of span trees: one going up, and the other going down. -// This represents a single search result. -htrace.SearchResult = Backbone.Model.extend({ - initialize: function(options) { - this.set("childrenRoot", { - root: options.span, - contents: null, - }); - this.set("childrenRoot", { - root: options.span, - contents: null, - }); - - this.set("parentsRoot", options.span); - }, - - getBegin: function() { - var begin = this.get("span").get("begin"); - var children = this.get("children"); - for (var childIdx = 0; childIdx < children.length; childIdx++) { - begin = Math.min(begin, children[childIdx].getBegin()); - } - return begin; - }, - - getEnd: function() { - var end = this.get("span").get("end"); - var children = this.get("children"); - for (var childIdx = 0; childIdx < children.length; childIdx++) { - end = Math.max(end, children[childIdx].getEnd()); - } - return end; - } -}); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/search_results.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/search_results.js b/htrace-htraced/src/web/app/search_results.js deleted file mode 100644 index 25b18ae..0000000 --- a/htrace-htraced/src/web/app/search_results.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -htrace.SearchResults = Backbone.Collection.extend({ - // The search results are span trees. - model: htrace.SpanTreeNode -}); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/search_results_view.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/search_results_view.js b/htrace-htraced/src/web/app/search_results_view.js deleted file mode 100644 index 111f530..0000000 --- a/htrace-htraced/src/web/app/search_results_view.js +++ /dev/null @@ -1,361 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -htrace.SearchResultsView = Backbone.View.extend({ - // The minimum time span we will allow between begin and end. - MINIMUM_TIME_SPAN: 100, - - begin: 0, - - end: this.MINIMUM_TIME_SPAN, - - initialize: function(options) { - this.searchResults = options.searchResults; - this.el = options.el; - this.listenTo(this.searchResults, 'add remove change reset', this.render); - - // Re-render the canvas when the window size changes. - // Add a debouncer delay to avoid spamming render requests. - var view = this; - $(window).on("resize", _.debounce(function() { - view.render(); - }, 250)); - }, - - // Get the canvas X coordinate of a mouse click from the absolute event - // coordinate. - getCanvasX: function(e) { - return e.pageX - $("#resultsCanvas").offset().left; - }, - - // Get the canvas Y coordinate of a mouse click from the absolute event - // coordinate. - getCanvasY: function(e) { - return e.pageY - $("#resultsCanvas").offset().top; - }, - - handleMouseDown: function(e) { - e.preventDefault(); - this.widgetManager.handle({ - type: "mouseDown", - x: this.getCanvasX(e), - y: this.getCanvasY(e) - }); - this.draw(); - }, - - handleMouseUp: function(e) { - e.preventDefault(); - this.widgetManager.handle({ - type: "mouseUp", - x: this.getCanvasX(e), - y: this.getCanvasY(e) - }); - this.draw(); - }, - - handleMouseOut: function(e) { - e.preventDefault(); - this.widgetManager.handle({ - type: "mouseOut" - }); - this.draw(); - }, - - handleMouseMove: function(e) { - e.preventDefault(); - this.widgetManager.handle({ - type: "mouseMove", - x: this.getCanvasX(e), - y: this.getCanvasY(e) - }); - this.draw(); - }, - - render: function() { - console.log("SearchResultsView#render."); - $(this.el).html(_.template($("#search-results-view-template").html())); - $('#selectedTime').attr('readonly', 'readonly'); - this.canvas = $("#resultsCanvas"); - this.ctx = this.canvas.get(0).getContext("2d"); - this.scaleCanvas(); - this.setupCoordinates(); - this.setupWidgets(); - this.draw(); - this.attachEvents(); - return this; - }, - - /* - * Compute the ratio to use between the size of the canvas (i.e. - * canvas.ctx.width, canvas.ctx.height) and the size in "HTML5 pixels." Note - * that 'HTML5 pixels" don't actually correspond to screen pixels. A line 1 - * "HTML5 pixel" wide actually takes up multiple scren pixels, etc. - * - * TODO: fix this to be sharper - */ - computeScaleFactor: function() { - var backingStoreRatio = this.ctx.backingStorePixelRatio || - this.ctx.mozBackingStorePixelRatio || - this.ctx.msBackingStorePixelRatio || - this.ctx.webkitBackingStorePixelRatio || - this.ctx.oBackingStorePixelRatio || - this.ctx.backingStorePixelRatio || 1; - return (window.devicePixelRatio || 1) / backingStoreRatio; - }, - - // Sets up the canvas size and scaling. - scaleCanvas: function() { - var cssX = this.canvas.parent().innerWidth(); - var cssY = $(window).innerHeight() - $("#header").innerHeight() - 50; - var ratio = this.computeScaleFactor(); - console.log("scaleCanvas: cssX=" + cssX + ", cssY=" + cssY + ", ratio=" + ratio); - this.maxX = cssX; - this.maxY = cssY; - $('#searchView').css('height', cssY + "px"); - $('#results').css('width', cssX + "px"); - $('#results').css('height', cssY + "px"); - $('#resultsView').css('width', cssX + "px"); - $('#resultsView').css('height', cssY + "px"); - $('#resultsDiv').css('width', cssX + "px"); - $('#resultsDiv').css('height', cssY + "px"); - $('#resultsCanvas').css('width', cssX + "px"); - $('#resultsCanvas').css('height', cssY + "px"); - this.ctx.canvas.width = cssX * ratio; - this.ctx.canvas.height = cssY * ratio; - this.ctx.scale(ratio, ratio); - }, - - // - // Set up the screen coordinates. - // - // 0 xB xD xS maxX - // +--------------+----------+--------------------+-----------+ - // |ProcessId | Buttons | Span Description | Scrollbar | - // +--------------+----------+--------------------+-----------+ - // - setupCoordinates: function() { - this.xB = Math.min(300, Math.floor(this.maxX / 5)); - this.xD = this.xB + Math.min(75, Math.floor(this.maxX / 20)); - var scrollBarWidth = Math.min(50, Math.floor(this.maxX / 10)); - this.xS = this.maxX - scrollBarWidth; - }, - - setupWidgets: function() { - this.widgetManager = new htrace.WidgetManager({searchResultsView: this}); - - // Create a SpanWidget for each span we know about - var spanWidgetHeight = Math.min(25, Math.floor(this.maxY / 32)); - var numResults = this.searchResults.size(); - var groupY = 0; - for (var i = 0; i < numResults; i++) { - var widget = new htrace.SpanGroupWidget({ - manager: this.widgetManager, - ctx: this.ctx, - span: this.searchResults.at(i), - x0: 0, - xB: this.xB, - xD: this.xD, - xF: this.xS, - y0: groupY, - begin: this.begin, - end: this.end, - spanWidgetHeight: spanWidgetHeight - }); - groupY = widget.yF; - } - - // Create the time cursor widget. - var selectedTime = this.begin; - if (this.timeCursor != null) { - selectedTime = this.timeCursor.selectedTime; - } - this.timeCursor = new htrace.TimeCursor({ - manager: this.widgetManager, - selectedTime: selectedTime, - el: "#selectedTime" - }); - this.timeCursor.ctx = this.ctx; - this.timeCursor.x0 = this.xD; - this.timeCursor.xF = this.xS; - this.timeCursor.y0 = 0; - this.timeCursor.yF = this.maxY; - this.timeCursor.begin = this.begin; - this.timeCursor.end = this.end; - }, - - draw: function() { - if (this.checkCanvasTooSmall()) { - return; - } - - // Set the background to white. - this.ctx.save(); - this.ctx.fillStyle="#ffffff"; - this.ctx.strokeStyle="#000000"; - this.ctx.fillRect(0, 0, this.maxX, this.maxY); - this.ctx.restore(); - - // Draw all the widgets. - this.widgetManager.handle({type: "draw"}); - }, - - checkCanvasTooSmall: function() { - if ((this.maxX < 200) || (this.maxY < 200)) { - this.ctx.fillStyle="#cccccc"; - this.ctx.strokeStyle="#000000"; - this.ctx.fillRect(0, 0, this.maxX, this.maxY); - this.ctx.font = "24px serif"; - this.ctx.fillStyle="#000000"; - this.ctx.fillText("Canvas too small!", 0, 24); - return true; - } - return false; - }, - - attachEvents: function() { - // Use jquery to capture mouse events on the canvas. - // For some reason using backbone doesn't work for getting these events. - var view = this; - $("#resultsCanvas").off("mousedown"); - $("#resultsCanvas").on("mousedown", function(e) { - view.handleMouseDown(e); - }); - $("#resultsCanvas").off("mouseup"); - $("#resultsCanvas").on("mouseup", function(e) { - view.handleMouseUp(e); - }); - $("#resultsCanvas").off("mouseout"); - $("#resultsCanvas").on("mouseout", function(e) { - view.handleMouseOut(e); - }); - $("#resultsCanvas").off("mousemove"); - $("#resultsCanvas").on("mousemove", function(e) { - view.handleMouseMove(e); - }); - }, - - remove: function() { - $(window).off("resize"); - $("#resultsCanvas").off("mousedown"); - $("#resultsCanvas").off("mouseup"); - $("#resultsCanvas").off("mousemove"); - Backbone.View.prototype.remove.apply(this, arguments); - }, - - handleBeginOrEndChange: function(e, type) { - e.preventDefault(); - var text = $(e.target).val().trim(); - var d = null; - try { - d = htrace.parseDate(text); - } catch(err) { - $("#begin").val(htrace.dateToString(this.begin)); - $("#end").val(htrace.dateToString(this.end)); - htrace.showModalWarning("Timeline " + type + " Format Error", - "Please enter a valid time in the timeline " + type + " field.<p/>" + - err); - return null; - } - if (type === "begin") { - this.setBegin(d.valueOf()); - } else if (type === "end") { - this.setEnd(d.valueOf()); - } else { - throw "invalid type for handleBeginOrEndChange: expected begin or end."; - } - }, - - setBegin: function(val) { - if (this.end < val + this.MINIMUM_TIME_SPAN) { - this.begin = val; - this.end = val + this.MINIMUM_TIME_SPAN; - console.log("SearchResultsView#setBegin(begin=" + this.begin + - ", end=" + this.end + ")"); - $("#begin").val(htrace.dateToString(this.begin)); - $("#end").val(htrace.dateToString(this.end)); - } else { - this.begin = val; - console.log("SearchResultsView#setBegin(begin=" + this.begin + ")"); - $("#begin").val(htrace.dateToString(this.begin)); - } - this.render(); - }, - - setEnd: function(val) { - if (this.begin + this.MINIMUM_TIME_SPAN > val) { - this.begin = val; - this.end = this.begin + this.MINIMUM_TIME_SPAN; - console.log("SearchResultsView#setEnd(begin=" + this.begin + - ", end=" + this.end + ")"); - $("#begin").val(htrace.dateToString(this.begin)); - $("#end").val(htrace.dateToString(this.end)); - } else { - this.end = val; - console.log("SearchResultsView#setEnd(end=" + this.end + ")"); - $("#end").val(htrace.dateToString(this.end)); - } - this.render(); - }, - - zoomFitAll: function() { - var numResults = this.searchResults.size(); - if (numResults == 0) { - this.setBegin(0); - this.setEnd(this.MINIMUM_TIME_SPAN); - return; - } - var minStart = 4503599627370496; - var maxEnd = 0; - for (var i = 0; i < numResults; i++) { - var span = this.searchResults.at(i); - var begin = span.getEarliestBegin(); - if (begin < minStart) { - minStart = begin; - } - var end = span.getLatestEnd(); - if (end > minStart) { - maxEnd = end; - } - } - this.setBegin(minStart); - this.setEnd(maxEnd); - }, - - // Apply a function to all spans - applyToAllSpans: function(cb) { - for (var i = 0; i < this.searchResults.length; i++) { - htrace.treeTraverseDepthFirstPre(this.searchResults.at(i), - htrace.getReifiedChildren, 0, - function(node, depth) { - console.log("node = " + node + ", node.constructor.name = " + node.constructor.name); - cb(node); - }); - htrace.treeTraverseDepthFirstPre(this.searchResults.at(i), - htrace.getReifiedParents, 0, - function(node, depth) { - if (depth > 0) { - cb(node); - } - }); - } - } -}); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/search_view.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/search_view.js b/htrace-htraced/src/web/app/search_view.js deleted file mode 100644 index 52f9101..0000000 --- a/htrace-htraced/src/web/app/search_view.js +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; -htrace.SearchView = Backbone.View.extend({ - initialize : function() { - this.predicateViews = []; - this.highestPredicateIndex = 0; - this.searchInProgress = false; - this.searchResults = new htrace.SearchResults(); - this.resultsView = new htrace.SearchResultsView({ - searchResults: this.searchResults, - el: "#results" - }); - }, - - events: { - "click #searchButton": "searchHandler", - "click #clearButton": "clearHandler", - "click .add-field": "dropdownHandler", - "blur #begin": "blurBeginHandler", - "blur #end": "blurEndHandler", - "click #zoomButton": "zoomFitAllHandler" - }, - - searchHandler: function(e){ - e.preventDefault(); - - // Do a new search. - this.doSearch(e.ctrlKey); - }, - - clearHandler: function(e){ - e.preventDefault(); - - // Clear existing search results. - this.searchResults.reset(); - }, - - doSearch: function(showDebug){ - if (this.searchInProgress) { - console.log("Can't start a new search while another one is in " + - "progress."); - return false; - } - - // Check if there are no search criteria. - if (this.predicateViews.length == 0) { - htrace.showModalWarning("No Search Criteria Specified", - "You have not specified any search criteria. " + - "Use the 'Add Predicate' button to specify what to search for."); - return false; - } - - // Build the predicate array. - predicates = [] - var predicateViewsLen = this.predicateViews.length; - for (var i = 0; i < predicateViewsLen; i++) { - var predicateView = this.predicateViews[i]; - try { - predicates.push(predicateView.getPredicate()); - } catch(err) { - htrace.showModalWarning("Search Field Validation Error", - "Invalid search string for the '" + predicateView.ptype.name + - "' field.<p/>" + err); - return false; - } - } - var queryJson = { - pred: predicates, - lim: 20 - }; - // If there are existing search results, we want results which "come after" - // those. So pass the last span we saw as a continuation token. - if (this.searchResults.size() > 0) { - queryJson.prev = - this.searchResults.at(this.searchResults.size() - 1).unparse(); - } - var searchView = this; - var queryResults = new htrace.QueryResults({queryJson: queryJson}); - console.log("Starting span query " + queryResults.url()); - this.searchInProgress = true; - queryResults.fetch({ - success: function(model, response, options){ - var firstResults = (searchView.searchResults.size() === 0); - console.log("Success on span query " + queryResults.url() + ": got " + - queryResults.size() + " result(s). firstResults=" + firstResults); - searchView.searchResults.add(queryResults.models); - if (firstResults) { - // After the initial search, zoom to fit everything. - // On subsequent searches, we leave the viewport alone. - searchView.resultsView.zoomFitAll(); - } - searchView.searchInProgress = false; - if (showDebug) { - htrace.showModalWarning("Search Debug", - "This is the search debug box, accessible by holding down the " + - "control key while clicking the search button.<p/>" + - "<h3>Query JSON</h3><pre>" + queryResults.prettyQueryString() + - "</pre><p/><h3>Response JSON</h3><pre>" + - JSON.stringify(queryResults, null, 2) + "</pre><p/>"); - } else if (queryResults.size() == 0) { - if (firstResults) { - htrace.showModalWarning("No Results Found", - "No results were found for your query.<p/>"); - } else { - htrace.showModalWarning("No Additional Results Found", - "No additional results were found for your query.<p/>"); - } - } - }, - error: function(model, response, options){ - this.searchResults.clear(); - var err = "Error " + JSON.stringify(response) + - " on span query " + query.url(); - console.log(err); - alert(err); - searchView.searchInProgress = false; - } - }); - return false; - }, - - dropdownHandler: function(e){ - e.preventDefault(); - var text = $(e.target).text(); - var ptype = htrace.parsePType(text); - if (!ptype) { - alert("Unable to parse predicate type '" + text + "'"); - return false; - } - var index = this.highestPredicateIndex; - this.highestPredicateIndex++; - var el = "pred" + index; - $("#predicates").append('<div id="' + el + '"/></div>'); - predicateView = new htrace.PredicateView({ - el: "#" + el, - index: index, - ptype: ptype, - searchView: this - }); - this.predicateViews.push(predicateView); - predicateView.render(); - return true; - }, - - blurBeginHandler: function(e) { - return this.resultsView.handleBeginOrEndChange(e, "begin"); - }, - - blurEndHandler: function(e) { - return this.resultsView.handleBeginOrEndChange(e, "end"); - }, - - zoomFitAllHandler: function(e) { - e.preventDefault(); - this.resultsView.zoomFitAll(); - }, - - removePredicateView: function(predicateView) { - this.predicateViews = _.without(this.predicateViews, predicateView); - }, - - render: function() { - this.$el.html(_.template($("#search-view-template").html()) - ({ model : this.model })) - this.resultsView.render(); - console.log("SearchView#render"); - return this; - }, - - close: function() { - console.log("SearchView#close") - while (this.predicateViews.length > 0) { - this.predicateViews[0].remove(); - } - this.resultsView.remove(); - this.resultsView = null; - this.undelegateEvents(); - } -}); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/server_info.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/server_info.js b/htrace-htraced/src/web/app/server_info.js deleted file mode 100644 index b03f706..0000000 --- a/htrace-htraced/src/web/app/server_info.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// htraced ServerInfo sent back from /serverInfo. -// See rest.go. -htrace.ServerInfo = Backbone.Model.extend({ - defaults: { - "ReleaseVersion": "unknown", - "GitVersion": "unknown", - }, - - url: function() { - return "server/info"; - } -}); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/span.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/span.js b/htrace-htraced/src/web/app/span.js deleted file mode 100644 index a056b4f..0000000 --- a/htrace-htraced/src/web/app/span.js +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -// The invalid span ID, which is all zeroes. -htrace.INVALID_SPAN_ID = "0000000000000000"; - -// Convert an array of htrace.Span models into a comma-separated string. -htrace.spanModelsToString = function(spans) { - var ret = ""; - var prefix = ""; - for (var i = 0; i < spans.length; i++) { - ret += prefix + JSON.stringify(spans[i].unparse()); - prefix = ", "; - } - return ret; -}; - -// Convert an array of return results from ajax calls into an array of -// htrace.Span models. -htrace.parseMultiSpanAjaxQueryResults = function(ajaxCalls) { - var parsedSpans = []; - for (var i = 0; i < ajaxCalls.length; i++) { - var text = ajaxCalls[i][0]; - var result = ajaxCalls[i][1]; - if (ajaxCalls[i]["status"] != "200") { - throw "ajax error: " + ajaxCalls[i].statusText; - } - var parsedSpan = new htrace.Span({}); - try { - parsedSpan.parse(ajaxCalls[i].responseJSON, {}); - } catch (e) { - throw "span parse error: " + e; - } - parsedSpans.push(parsedSpan); - } - return parsedSpans; -}; - -htrace.getReifiedParents = function(span) { - return span.get("reifiedParents") || []; -}; - -htrace.getReifiedChildren = function(span) { - return span.get("reifiedChildren") || []; -}; - -htrace.Span = Backbone.Model.extend({ - // Parse a span sent from htraced. - // We use more verbose names for some attributes. - // Missing attributes are treated as zero or empty. Numerical attributes are - // forced to be numbers. - parse: function(response, options) { - var span = {}; - this.set("spanId", response.s ? response.s : htrace.INVALID_SPAN_ID); - this.set("traceId", response.i ? response.i : htrace.INVALID_SPAN_ID); - this.set("processId", response.r ? response.r : ""); - this.set("parents", response.p ? response.p : []); - this.set("description", response.d ? response.d : ""); - this.set("begin", response.b ? parseInt(response.b, 10) : 0); - this.set("end", response.e ? parseInt(response.e, 10) : 0); - - this.set("selected", false); - - // reifiedChildren starts off as null and will be filled in as needed. - this.set("reifiedChildren", null); - - // If there are parents, reifiedParents starts off as null. Otherwise, we - // know it is the empty array. - this.set("reifiedParents", (this.get("parents").length == 0) ? [] : null); - - return span; - }, - - // Transform a span model back into a JSON string suitable for sending over - // the wire. - unparse: function() { - var obj = { }; - if (!(this.get("spanId") === htrace.INVALID_SPAN_ID)) { - obj.s = this.get("spanId"); - } - if (!(this.get("traceId") === htrace.INVALID_SPAN_ID)) { - obj.i = this.get("traceId"); - } - if (!(this.get("processId") === "")) { - obj.r = this.get("processId"); - } - if (this.get("parents").length > 0) { - obj.p = this.get("parents"); - } - if (this.get("description").length > 0) { - obj.d = this.get("description"); - } - if (this.get("begin") > 0) { - obj.b = this.get("begin"); - } - if (this.get("end") > 0) { - obj.e = this.get("end"); - } - return obj; - }, - - // - // Although the parent IDs are always present in the 'parents' field of the - // span, sometimes we need the actual parent span models. In that case we - // must "reify" them (make them real). - // - // This functionReturns a jquery promise which reifies all the parents of this - // span and stores them into reifiedParents. The promise returns the empty - // string on success, or an error string on failure. - // - reifyParents: function() { - var span = this; - var numParents = span.get("parents").length; - var ajaxCalls = []; - // Set up AJAX queries to reify the parents. - for (var i = 0; i < numParents; i++) { - ajaxCalls.push($.ajax({ - url: "span/" + span.get("parents")[i], - data: {}, - contentType: "application/json; charset=utf-8", - dataType: "json" - })); - } - var rootDeferred = jQuery.Deferred(); - $.when.apply($, ajaxCalls).then(function() { - var reifiedParents = []; - try { - reifiedParents = htrace.parseMultiSpanAjaxQueryResults(ajaxCalls); - } catch (e) { - rootDeferred.resolve("Error reifying parents for " + - span.get("spanId") + ": " + e); - return; - } - // The current span is a child of the reified parents. There may be other - // children of those parents, but we are ignoring that here. By making - // this non-null, the "expand children" button will not appear for these - // paren spans. - for (var j = 0; j < reifiedParents.length; j++) { - reifiedParents[j].set("reifiedChildren", [span]); - } - console.log("Setting reified parents for " + span.get("spanId") + - " to " + htrace.spanModelsToString (reifiedParents)); - span.set("reifiedParents", reifiedParents); - rootDeferred.resolve(""); - }); - return rootDeferred.promise(); - }, - - // - // The span itself does not contain its children. However, the server has an - // index which can be used to easily find the children of a particular span. - // - // This function returns a jquery promise which reifies all the children of - // this span and stores them into reifiedChildren. The promise returns the - // empty string on success, or an error string on failure. - // - reifyChildren: function() { - var rootDeferred = jQuery.Deferred(); - var span = this; - $.ajax({ - url: "span/" + span.get("spanId") + "/children?lim=50", - data: {}, - contentType: "application/json; charset=utf-8", - dataType: "json" - }).done(function(childIds) { - var ajaxCalls = []; - for (var i = 0; i < childIds.length; i++) { - ajaxCalls.push($.ajax({ - url: "span/" + childIds[i], - data: {}, - contentType: "application/json; charset=utf-8", - dataType: "json" - })); - }; - $.when.apply($, ajaxCalls).then(function() { - var reifiedChildren; - try { - reifiedChildren = htrace.parseMultiSpanAjaxQueryResults(ajaxCalls); - } catch (e) { - reifiedChildren = rootDeferred.resolve("Error reifying children " + - "for " + span.get("spanId") + ": " + e); - return; - } - // The current span is a parent of the new child. - // There may be other parents, but we are ignoring that here. - // By making this non-null, the "expand parents" button will not - // appear for these child spans. - for (var j = 0; j < reifiedChildren.length; j++) { - reifiedChildren[j].set("reifiedParents", [span]); - } - console.log("Setting reified children for " + span.get("spanId") + - " to " + htrace.spanModelsToString (reifiedChildren)); - span.set("reifiedChildren", reifiedChildren); - rootDeferred.resolve(""); - }); - }).fail(function(statusData) { - // Check if the /children query failed. - rootDeferred.resolve("Error querying children of " + - span.get("spanId") + ": got " + statusData); - return; - }); - return rootDeferred.promise(); - }, - - // Get the earliest begin time of this span or any of its reified parents or - // children. - getEarliestBegin: function() { - var earliestBegin = this.get("begin"); - htrace.treeTraverseDepthFirstPre(this, htrace.getReifiedParents, 0, - function(span, depth) { - earliestBegin = Math.min(earliestBegin, span.get("begin")); - }); - htrace.treeTraverseDepthFirstPre(this, htrace.getReifiedChildren, 0, - function(span, depth) { - earliestBegin = Math.min(earliestBegin, span.get("begin")); - }); - return earliestBegin; - }, - - // Get the earliest begin time of this span or any of its reified parents or - // children. - getLatestEnd: function() { - var latestEnd = this.get("end"); - htrace.treeTraverseDepthFirstPre(this, htrace.getReifiedParents, 0, - function(span, depth) { - latestEnd = Math.max(latestEnd, span.get("end")); - }); - htrace.treeTraverseDepthFirstPre(this, htrace.getReifiedChildren, 0, - function(span, depth) { - latestEnd = Math.max(latestEnd, span.get("end")); - }); - return latestEnd; - }, -}); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/span_details_view.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/span_details_view.js b/htrace-htraced/src/web/app/span_details_view.js deleted file mode 100644 index 9a37055..0000000 --- a/htrace-htraced/src/web/app/span_details_view.js +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -htrace.SpanDetailsView = Backbone.View.extend({ - initialize: function(options) { - this.el = options.el; - this.model = options.model; - } - - render: function() { - this.$el.html(_.template($("#about-view-template").html()) - ({ model : this.model })); - console.log("AboutView#render"); - return this; - }, - - close: function() { - console.log("AboutView#close") - this.undelegateEvents(); - } -}); http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/span_group_widget.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/span_group_widget.js b/htrace-htraced/src/web/app/span_group_widget.js deleted file mode 100644 index e32c2db..0000000 --- a/htrace-htraced/src/web/app/span_group_widget.js +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -// Widget containing a group of trace spans displayed on the canvas. -htrace.SpanGroupWidget = function(params) { - this.draw = function() { - this.ctx.save(); - this.ctx.fillStyle="#ffffff"; - this.ctx.fillRect(this.x0, this.y0, this.xF - this.x0, this.yF - this.y0); - this.ctx.strokeStyle="#aaaaaa"; - this.ctx.beginPath(); - this.ctx.moveTo(this.x0, this.y0); - this.ctx.lineTo(this.xF, this.y0); - this.ctx.stroke(); - this.ctx.beginPath(); - this.ctx.moveTo(this.x0, this.yF); - this.ctx.lineTo(this.xF, this.yF); - this.ctx.stroke(); - this.ctx.restore(); - return true; - }; - - this.createSpanWidget = function(node, indentLevel, - allowUpButton, allowDownButton) { - new htrace.SpanWidget({ - manager: this.manager, - ctx: this.ctx, - span: node, - x0: this.x0, - xB: this.xB, - xD: this.xD, - xF: this.xF, - xT: this.childIndent * indentLevel, - y0: this.spanY, - yF: this.spanY + this.spanWidgetHeight, - allowUpButton: allowUpButton, - allowDownButton: allowDownButton, - begin: this.begin, - end: this.end - }); - this.spanY += this.spanWidgetHeight; - } - - this.handle = function(e) { - switch (e.type) { - case "draw": - this.draw(); - return true; - } - } - - for (var k in params) { - this[k]=params[k]; - } - this.manager.register("draw", this); - this.spanY = this.y0 + 4; - - // Figure out how much to indent each child's description text. - this.childIndent = Math.max(10, (this.xF - this.xD) / 50); - - // Get the maximum depth of the parents tree to find out how far to indent. - var parentTreeHeight = - htrace.treeHeight(this.span, htrace.getReifiedParents); - - console.log("parentTreeHeight = " + parentTreeHeight); - // Traverse the parents tree upwards. - var thisWidget = this; - htrace.treeTraverseDepthFirstPost(this.span, htrace.getReifiedParents, 0, - function(node, depth) { - if (depth > 0) { - thisWidget.createSpanWidget(node, - parentTreeHeight - depth, true, false); - } - }); - thisWidget.createSpanWidget(this.span, parentTreeHeight, true, true); - // Traverse the children tree downwards. - htrace.treeTraverseDepthFirstPre(this.span, htrace.getReifiedChildren, 0, - function(node, depth) { - if (depth > 0) { - thisWidget.createSpanWidget(node, - parentTreeHeight + depth, false, true); - } - }); - this.yF = this.spanY + 4; - console.log("SpanGroupWidget(this.span=" + - JSON.stringify(this.span.unparse()) + - ", x0=" + this.x0 + ", xB=" + this.xB + - ", xD=" + this.xD + ", xF=" + this.xF + - ", y0=" + this.y0 + ", yF=" + this.yF + - ")"); - return this; -}; http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/span_widget.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/span_widget.js b/htrace-htraced/src/web/app/span_widget.js deleted file mode 100644 index 0d18fef..0000000 --- a/htrace-htraced/src/web/app/span_widget.js +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -// Widget containing the trace span displayed on the canvas. -htrace.SpanWidget = function(params) { - this.draw = function() { - this.drawBackground(); - this.drawProcessId(); - this.drawDescription(); - }; - - // Draw the background of this span widget. - this.drawBackground = function() { - this.ctx.save(); - if (this.span.get("selected")) { - this.ctx.fillStyle="#ffccff"; - } else { - this.ctx.fillStyle="#ffffff"; - } - this.ctx.fillRect(this.x0, this.y0, this.xSize, this.ySize); - this.ctx.restore(); - } - - // Draw process ID text. - this.drawProcessId = function() { - this.ctx.save(); - this.ctx.fillStyle="#000000"; - this.ctx.font = (this.ySize - 2) + "px sans-serif"; - this.ctx.beginPath(); - this.ctx.rect(this.x0, this.y0, this.xB - this.x0, this.ySize); - this.ctx.clip(); - this.ctx.fillText(this.span.get('processId'), this.x0, this.yF - 4); - this.ctx.restore(); - }; - - // Draw the span description - this.drawDescription = function() { - // Draw the light blue bar representing time. - this.ctx.save(); - this.ctx.beginPath(); - this.ctx.rect(this.xD, this.y0, this.xF - this.xD, this.ySize); - this.ctx.clip(); - this.ctx.strokeStyle="#000000"; - this.ctx.fillStyle="#a7b7ff"; - var beginX = this.timeToPosition(this.span.get('begin')); - var endX = this.timeToPosition(this.span.get('end')); - - // If the span is completely off the screen, draw a diamond at either the - // beginning or the end of the bar to indicate whether it's too early or too - // late to be seen. - if (endX < this.x0) { - beginX = this.xD; - endX = this.xD; - } - if (beginX > this.xF) { - beginX = this.xF; - endX = this.xF; - } - - var gapY = 2; - var epsilon = Math.max(2, Math.floor(this.xSize / 1000)); - if (endX - beginX < epsilon) { - // The time interval is too narrow to see. Draw a diamond on the point instead. - this.ctx.beginPath(); - this.ctx.moveTo(beginX, this.y0 + gapY); - this.ctx.lineTo(beginX + (Math.floor(this.ySize / 2) - gapY), - this.y0 + Math.floor(this.ySize / 2)); - this.ctx.lineTo(beginX, this.yF - gapY); - this.ctx.lineTo(beginX - (Math.floor(this.ySize / 2) - gapY), - this.y0 + Math.floor(this.ySize / 2)); - this.ctx.closePath(); - this.ctx.fill(); - } else { - // Draw a bar from the start time to the end time. -// console.log("beginX=" + beginX + ", endX=" + endX + -// ", begin=" + this.span.get('begin') + ", end=" + this.span.get('end')); - this.ctx.fillRect(beginX, this.y0 + gapY, endX - beginX, - this.ySize - (gapY * 2)); - } - - // Draw description text - this.ctx.fillStyle="#000000"; - this.ctx.font = (this.ySize - gapY) + "px sans-serif"; - this.ctx.fillText(this.span.get('description'), - this.xD + this.xT, - this.yF - gapY - 2); - - this.ctx.restore(); - }; - - // Convert a time in milliseconds since the epoch to an x position. - this.timeToPosition = function(time) { - return this.xD + - (((time - this.begin) * (this.xF - this.xD)) / - (this.end - this.begin)); - }; - - this.fillSpanDetailsView = function() { - var info = { - spanID: this.span.get("spanID"), - begin: htrace.dateToString(parseInt(this.span.get("begin"), 10)), - end: htrace.dateToString(parseInt(this.span.get("end"), 10)), - }; - var explicitOrder = { - spanId: -3, - begin: -2, - end: -1 - }; - keys = []; - for(k in this.span.attributes) { - if (k == "reifiedChildren") { - continue; - } - if (k == "reifiedParents") { - continue; - } - keys.push(k); - if (info[k] == null) { - info[k] = this.span.get(k); - } - } - // We sort the keys so that the stuff we want at the top appears at the top, - // and everything else is in alphabetical order. - keys = keys.sort(function(a, b) { - var oa = explicitOrder[a] || 0; - var ob = explicitOrder[b] || 0; - if (oa < ob) { - return -1; - } else if (oa > ob) { - return 1; - } else if (a < b) { - return -1; - } else if (a > b) { - return 1; - } else { - return 0; - } - }); - var len = keys.length; - var h = '<table style="table-layout:fixed;width:100%;word-wrap:break-word">'; - for (i = 0; i < len; i++) { - // Make every other row grey to improve visibility. - var colorString = ((i%2) == 1) ? "#f1f1f1" : "#ffffff"; - h += _.template('<tr bgcolor="' + colorString + '">' + - '<td style="width:30%;word-wrap:break-word"><%- key %></td>' + - '<td style="width:70%;word-wrap:break-word"><%- val %></td>' + - "</tr>")({key: keys[i], val: info[keys[i]]}); - } - h += '</table>'; - $("#spanDetails").html(h); - }; - - this.handle = function(e) { - switch (e.type) { - case "mouseDown": - if (!htrace.inBoundingBox(e.x, e.y, - this.x0, this.xF, this.y0, this.yF)) { - return true; - } - this.manager.searchResultsView.applyToAllSpans(function(span) { - if (span.get("selected") == true) { - span.set("selected", false); - } - }); - this.span.set("selected", true); - this.fillSpanDetailsView(); - return true; - case "draw": - this.draw(); - return true; - } - }; - - for (var k in params) { - this[k]=params[k]; - } - this.xSize = this.xF - this.x0; - this.ySize = this.yF - this.y0; - this.xDB = this.xD - this.xB; - this.manager.register("draw", this); - - var widget = this; - if ((this.span.get("reifiedParents") == null) && (this.allowUpButton)) { - new htrace.TriangleButton({ - ctx: this.ctx, - manager: this.manager, - direction: "up", - x0: this.xB + 2, - xF: this.xB + (this.xDB / 2) - 2, - y0: this.y0 + 2, - yF: this.yF - 2, - callback: function() { - $.when(widget.span.reifyParents()).done(function (result) { - console.log("reifyParents: result was '" + result + "'"); - widget.manager.searchResultsView.render(); - }); - }, - }); - } - if ((this.span.get("reifiedChildren") == null) && (this.allowDownButton)) { - new htrace.TriangleButton({ - ctx: this.ctx, - manager: this.manager, - direction: "down", - x0: this.xB + (this.xDB / 2) + 2, - xF: this.xD - 2, - y0: this.y0 + 2, - yF: this.yF - 2, - callback: function() { - $.when(widget.span.reifyChildren()).done(function (result) { - console.log("reifyChildren: result was '" + result + "'"); - widget.manager.searchResultsView.render(); - }); - }, - }); - } - this.manager.register("mouseDown", this); - return this; -}; http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/string.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/string.js b/htrace-htraced/src/web/app/string.js deleted file mode 100644 index b0dfb74..0000000 --- a/htrace-htraced/src/web/app/string.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -// Parse an ISO8601 date string into a moment.js object. -htrace.parseDate = function(val) { - if (val.match(/^[0-9]([0-9]*)$/)) { - // Treat an all-numeric field as UTC milliseconds since the epoch. - return moment.utc(parseInt(val, 10)); - } - // Look for approved date formats. - var toTry = [ - "YYYY-MM-DDTHH:mm:ss,SSS", - "YYYY-MM-DDTHH:mm:ss", - "YYYY-MM-DDTHH:mm", - "YYYY-MM-DD" - ]; - for (var i = 0; i < toTry.length; i++) { - var m = moment.utc(val, toTry[i], true); - if (m.isValid()) { - return m; - } - } - throw "Please enter the date either as YYYY-MM-DDTHH:mm:ss,SSS " + - "in UTC, or as the number of milliseconds since the epoch."; -}; - -// Convert a moment.js moment into an ISO8601-style date string. -htrace.dateToString = function(val) { - return moment.utc(val).format("YYYY-MM-DDTHH:mm:ss,SSS"); -}; - -// Normalize a span ID into the format the server expects to see -// (no leading 0x). -htrace.normalizeSpanId = function(str) { - // Strip off the 0x prefix, if there is one. - if (str.indexOf("0x") == 0) { - str = str.substring(2); - } - if (str.length != 16) { - throw "The length of '" + str + "' was " + str.length + - ", but span IDs must be 16 characters long."; - } - if (str.search(/[^0-9a-fA-F]/) != -1) { - throw "Span IDs must contain only hexadecimal digits, but '" + str + - "' contained invalid characters."; - } - return str; -}; http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/time_cursor.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/time_cursor.js b/htrace-htraced/src/web/app/time_cursor.js deleted file mode 100644 index 1caaa9a..0000000 --- a/htrace-htraced/src/web/app/time_cursor.js +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -// Draws a vertical bar selecting a time. -htrace.TimeCursor = function(params) { - this.positionToTime = function(x) { - if ((x < this.x0) || (x > this.xF)) { - return -1; - } - return this.begin + - (((x - this.x0) * (this.end - this.begin)) / (this.xF - this.x0)); - }; - - this.timeToPosition = function(time) { - return this.x0 + (((time - this.begin) * - (this.xF - this.x0)) / (this.end - this.begin)); - }; - - this.draw = function() { - if (this.selectedTime != -1) { - this.ctx.save(); - this.ctx.beginPath(); - this.ctx.rect(this.x0, this.y0, - this.xF - this.x0, this.yF - this.y0); - this.ctx.clip(); - this.ctx.strokeStyle="#ff0000"; - var x = this.timeToPosition(this.selectedTime); - this.ctx.beginPath(); - this.ctx.moveTo(x, this.y0); - this.ctx.lineTo(x, this.yF); - this.ctx.stroke(); - this.ctx.restore(); - } - }; - - this.handle = function(e) { - switch (e.type) { - case "mouseMove": - if (htrace.inBoundingBox(e.x, e.y, - this.x0, this.xF, this.y0, this.yF)) { - this.selectedTime = this.positionToTime(e.x); - if (this.selectedTime < 0) { - $(this.el).val(""); - } else { - $(this.el).val(htrace.dateToString(this.selectedTime)); - } - return true; - } - return true; - case "draw": - this.draw(); - return true; - } - }; - - this.selectedTime = -1; - for (var k in params) { - this[k]=params[k]; - } - this.manager.register("mouseMove", this); - this.manager.register("draw", this); - return this; -}; http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/tree.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/tree.js b/htrace-htraced/src/web/app/tree.js deleted file mode 100644 index 046085c..0000000 --- a/htrace-htraced/src/web/app/tree.js +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -// -// Get the height of a tree-- that is, the number of edges on the longest -// downward path between the root and a leaf -// -htrace.treeHeight = function(node, getDescendants) { - var height = 0; - var descendants = getDescendants(node); - for (var i = 0; i < descendants.length; i++) { - height = Math.max(height, - 1 + htrace.treeHeight(descendants[i], getDescendants)); - } - return height; -}; - -// -// Perform a depth-first, post-order traversal on the tree, invoking the -// callback on every node with the node and depth as the arguments. -// -// Example: -// 5 -// / \ -// 3 4 -// / \ -// 1 2 -// -htrace.treeTraverseDepthFirstPost = function(node, getDescendants, depth, cb) { - var descendants = getDescendants(node); - for (var i = 0; i < descendants.length; i++) { - htrace.treeTraverseDepthFirstPost(descendants[i], - getDescendants, depth + 1, cb); - } - cb(node, depth); -}; - -// -// Perform a depth-first, pre-order traversal on the tree, invoking the -// callback on every node with the node and depth as the arguments. -// -// Example: -// 1 -// / \ -// 2 5 -// / \ -// 3 4 -// -htrace.treeTraverseDepthFirstPre = function(node, getDescendants, depth, cb) { - cb(node, depth); - var descendants = getDescendants(node); - for (var i = 0; i < descendants.length; i++) { - htrace.treeTraverseDepthFirstPre(descendants[i], - getDescendants, depth + 1, cb); - } -}; http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/triangle_button.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/triangle_button.js b/htrace-htraced/src/web/app/triangle_button.js deleted file mode 100644 index f252476..0000000 --- a/htrace-htraced/src/web/app/triangle_button.js +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -// Triangle button widget. -htrace.TriangleButton = function(params) { - this.fgColor = "#6600ff"; - this.bgColor = "#ffffff"; - this.selected = false; - this.direction = "down"; - - this.draw = function() { - this.ctx.save(); - var fg = this.selected ? this.bgColor : this.fgColor; - var bg = this.selected ? this.fgColor : this.bgColor; - this.ctx.beginPath(); - this.ctx.rect(this.x0, this.y0, - this.xF - this.x0, this.yF - this.y0); - this.ctx.clip(); - this.ctx.fillStyle = bg; - this.ctx.strokeStyle = fg; - this.ctx.fillRect(this.x0, this.y0, - this.xF - this.x0, this.yF - this.y0); - this.ctx.lineWidth = 3; - this.ctx.strokeRect(this.x0, this.y0, - this.xF - this.x0, this.yF - this.y0); - var xPad = (this.xF - this.x0) / 5; - var yPad = (this.yF - this.y0) / 5; - this.ctx.fillStyle = fg; - this.ctx.strokeStyle = fg; - this.ctx.beginPath(); - this.ctx.strokeStyle = fg; - if (this.direction === "up") { - this.ctx.moveTo(Math.floor(this.x0 + ((this.xF - this.x0) / 2)), - this.y0 + yPad); - this.ctx.lineTo(this.xF - xPad, this.yF - yPad); - this.ctx.lineTo(this.x0 + xPad, this.yF - yPad); - } else if (this.direction === "down") { - this.ctx.moveTo(this.x0 + xPad, this.y0 + yPad); - this.ctx.lineTo(this.xF - xPad, this.y0 + yPad); - this.ctx.lineTo(Math.floor(this.x0 + ((this.xF - this.x0) / 2)), - this.yF - yPad); - } else { - console.log("TriangleButton: unknown direction " + this.direction); - } - this.ctx.closePath(); - this.ctx.fill(); - this.ctx.restore(); - }; - - this.handle = function(e) { - switch (e.type) { - case "mouseDown": - if (!htrace.inBoundingBox(e.x, e.y, - this.x0, this.xF, this.y0, this.yF)) { - return true; - } - this.manager.register("mouseUp", this); - this.manager.register("mouseMove", this); - this.manager.register("mouseOut", this); - this.selected = true; - return false; - case "mouseUp": - if (this.selected) { - this.callback(); - this.selected = false; - } - this.manager.unregister("mouseUp", this); - this.manager.unregister("mouseMove", this); - this.manager.unregister("mouseOut", this); - return true; - case "mouseMove": - this.selected = htrace.inBoundingBox(e.x, e.y, - this.x0, this.xF, this.y0, this.yF); - return true; - case "mouseOut": - this.selected = false; - return true; - case "draw": - this.draw(); - return true; - } - }; - - for (var k in params) { - this[k]=params[k]; - } - this.manager.register("mouseDown", this); - this.manager.register("draw", this); - return this; -}; http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/d0554d53/htrace-htraced/src/web/app/widget_manager.js ---------------------------------------------------------------------- diff --git a/htrace-htraced/src/web/app/widget_manager.js b/htrace-htraced/src/web/app/widget_manager.js deleted file mode 100644 index 5f393b0..0000000 --- a/htrace-htraced/src/web/app/widget_manager.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var htrace = htrace || {}; - -// Check if a point is inside a bounding box. -htrace.inBoundingBox = function(x, y, x0, xF, y0, yF) { - return ((x >= x0) && (x <= xF) && (y >= y0) && (y <= yF)); - } - -// Manages a set of widgets on the canvas. -// Buttons and sliders are both widgets. -htrace.WidgetManager = function(params) { - this.listeners = { - "mouseDown": [], - "mouseUp": [], - "mouseMove": [], - "mouseOut": [], - "draw": [], - }; - - this.register = function(type, widget) { - this.listeners[type].push(widget); - } - - this.unregister = function(type, widget) { - this.listeners[type] = _.without(this.listeners[type], widget); - } - - this.handle = function(e) { - // Make a copy of the listeners, in case the handling functions change the - // array. - var listeners = this.listeners[e.type].slice(); - var len = listeners.length; - for (var i = 0; i < len; i++) { - if (!listeners[i].handle(e)) { - break; - } - } - }; - - for (var k in params) { - this[k]=params[k]; - } - return this; -};
