1 package autotest.tko;
2 
3 import autotest.common.JsonRpcCallback;
4 import autotest.common.Utils;
5 import autotest.common.ui.SimpleDialog;
6 
7 import com.google.gwt.event.dom.client.ClickEvent;
8 import com.google.gwt.event.dom.client.ClickHandler;
9 import com.google.gwt.json.client.JSONArray;
10 import com.google.gwt.json.client.JSONObject;
11 import com.google.gwt.json.client.JSONString;
12 import com.google.gwt.json.client.JSONValue;
13 import com.google.gwt.user.client.ui.Anchor;
14 import com.google.gwt.user.client.ui.FlexTable;
15 
16 class MetricsPlot extends Plot {
MetricsPlot()17     public MetricsPlot() {
18         super("create_metrics_plot");
19     }
20 
21     /**
22      * drilldownParams contains:
23      * * query - SQL query for the selected series
24      * * series - name of the selected series
25      * * param - parameter to fill in query for the selected data point
26      */
27     @Override
showDrilldownImpl(JSONObject drilldownParams)28     protected void showDrilldownImpl(JSONObject drilldownParams) {
29         String query = Utils.jsonToString(drilldownParams.get("query"));
30         final String series = Utils.jsonToString(drilldownParams.get("series"));
31         final String param = Utils.jsonToString(drilldownParams.get("param"));
32 
33         JSONObject params = new JSONObject();
34         params.put("query", new JSONString(query));
35         params.put("param", new JSONString(param));
36         rpcProxy.rpcCall("execute_query_with_param", params, new JsonRpcCallback() {
37             @Override
38             public void onSuccess(JSONValue result) {
39                 JSONArray data = result.isArray();
40 
41                 String title = series + " for " + param;
42                 FlexTable contents = new FlexTable();
43                 final SimpleDialog drill = new SimpleDialog(title, contents);
44 
45                 for (int i = 0; i < data.size(); i++) {
46                     final JSONArray row = data.get(i).isArray();
47                     final int testId = (int) row.get(0).isNumber().doubleValue();
48                     String yValue = Utils.jsonToString(row.get(1));
49 
50                     Anchor link = new Anchor(yValue);
51                     link.addClickHandler(new ClickHandler() {
52                         public void onClick(ClickEvent event) {
53                             drill.hide();
54                             listener.onSelectTest(testId);
55                         }
56                     });
57                     contents.setWidget(i, 0, link);
58                 }
59 
60                 drill.center();
61             }
62         });
63     }
64 }
65