PageRenderTime 68ms CodeModel.GetById 59ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/main/java/com/google/test/metric/report/chart/HistogramChartUrl.java

http://testability-explorer.googlecode.com/
Java | 58 lines | 34 code | 9 blank | 15 comment | 3 complexity | a21a59dfe963c14a16abb4fed0eb09a0 MD5 | raw file
 1/*
 2 * Copyright 2007 Google Inc.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package com.google.test.metric.report.chart;
17
18import static java.lang.Math.pow;
19import static java.lang.String.format;
20
21import java.util.List;
22
23import com.google.common.base.Function;
24import com.google.common.collect.Lists;
25import com.google.test.metric.report.chart.Histogram.Logarithmic;
26
27public class HistogramChartUrl extends GoogleChartAPI {
28
29  public HistogramChartUrl() {
30    keys.put("cht", "bvs");
31  }
32
33  public void setBarWidth(int width) {
34    keys.put("chbh", Integer.toString(width));
35  }
36
37  public void setBarWidth(int width, int spaceBar, int spaceGroup) {
38    keys.put("chbh", toList(",", width, spaceBar, spaceGroup));
39  }
40
41  public void setYMark(int min, int max, Function<Integer, Double> scalingFunction) {
42    keys.put("chxt", "y");
43    if (scalingFunction instanceof Logarithmic) {
44      List<String> yLabels = Lists.newLinkedList();
45      List<String> yPositions = Lists.newLinkedList();
46      double scaledMax = scalingFunction.apply(max);
47      for (int labelExponent = 0; pow(10, labelExponent) < max; labelExponent++) {
48        yLabels.add(String.valueOf((int)pow(10, labelExponent)));
49        yPositions.add(String.valueOf(100 * (labelExponent + 1) / scaledMax));
50      }
51      keys.put("chxl", "0:|" + toList("|", yLabels.toArray(new String[yLabels.size()])));
52      keys.put("chxp", "0," + toList(",", yPositions.toArray(new String[yPositions.size()])));
53    } else {
54      keys.put("chxr", format("0,%d,%d", min, max));
55    }
56  }
57
58}