/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. */
  16. package com.google.test.metric.report.chart;
  17. import static java.lang.Math.pow;
  18. import static java.lang.String.format;
  19. import java.util.List;
  20. import com.google.common.base.Function;
  21. import com.google.common.collect.Lists;
  22. import com.google.test.metric.report.chart.Histogram.Logarithmic;
  23. public class HistogramChartUrl extends GoogleChartAPI {
  24. public HistogramChartUrl() {
  25. keys.put("cht", "bvs");
  26. }
  27. public void setBarWidth(int width) {
  28. keys.put("chbh", Integer.toString(width));
  29. }
  30. public void setBarWidth(int width, int spaceBar, int spaceGroup) {
  31. keys.put("chbh", toList(",", width, spaceBar, spaceGroup));
  32. }
  33. public void setYMark(int min, int max, Function<Integer, Double> scalingFunction) {
  34. keys.put("chxt", "y");
  35. if (scalingFunction instanceof Logarithmic) {
  36. List<String> yLabels = Lists.newLinkedList();
  37. List<String> yPositions = Lists.newLinkedList();
  38. double scaledMax = scalingFunction.apply(max);
  39. for (int labelExponent = 0; pow(10, labelExponent) < max; labelExponent++) {
  40. yLabels.add(String.valueOf((int)pow(10, labelExponent)));
  41. yPositions.add(String.valueOf(100 * (labelExponent + 1) / scaledMax));
  42. }
  43. keys.put("chxl", "0:|" + toList("|", yLabels.toArray(new String[yLabels.size()])));
  44. keys.put("chxp", "0," + toList(",", yPositions.toArray(new String[yPositions.size()])));
  45. } else {
  46. keys.put("chxr", format("0,%d,%d", min, max));
  47. }
  48. }
  49. }