Repository: bazelbuild/bazel
Issue: HtmlChart is uncolored
Labels: type: feature request
P4
category: misc > misc
good first issue

### Description of the problem / feature request / question:

Legend and Chart are completely white.

![bildschirmfoto 2017-06-02 um 11 51 27](https://cloud.githubusercontent.com/assets/28805183/26720825/e64d9e32-4789-11e7-929a-f32b1a79a39c.png)

### Environment info

* Operating System: MacOSX
* Bazel version: release 0.4.5-homebrew

### Reason

css color values `background-color:rgba(102,153,204,1,000000)` are not valid . This should be a result of german decimal separator ','. 

### Solution

force '.' as decimal separator.

Issue comments:
Thanks for the bug report! Unfortunately we have no capacity to fix it now, so I'm marking it P4 to indicate that we need external help to fix it. Would you be interested in fixing it?

Pull request review comments:
Why not use Locale.US here. That seems to more clearly document the purpose. Also, might want to add a comment on why we provide a locale here.
Maybe the test should reset the locale before it returns?

Patch that resolved the issue:
diff --git a/src/main/java/com/google/devtools/build/lib/profiler/chart/HtmlChartVisitor.java b/src/main/java/com/google/devtools/build/lib/profiler/chart/HtmlChartVisitor.java
index 4649326b312772..170334df66dc35 100644
--- a/src/main/java/com/google/devtools/build/lib/profiler/chart/HtmlChartVisitor.java
+++ b/src/main/java/com/google/devtools/build/lib/profiler/chart/HtmlChartVisitor.java
@@ -16,6 +16,7 @@
 
 import java.io.PrintStream;
 import java.util.List;
+import java.util.Locale;
 
 /**
  * {@link ChartVisitor} that builds HTML from the visited chart and prints it
@@ -313,13 +314,14 @@ private void anchor(String name) {
   /**
    * Formats the given {@link Color} to a css style color string.
    */
-  private String formatColor(Color color) {
+  public static String formatColor(Color color) {
     int r = color.getRed();
     int g = color.getGreen();
     int b = color.getBlue();
     int a = color.getAlpha();
 
-    return String.format("rgba(%d,%d,%d,%f)", r, g, b, (a / 255.0));
+    // US Locale is used to ensure a dot as decimal separator
+    return String.format(Locale.US, "rgba(%d,%d,%d,%f)", r, g, b, (a / 255.0));
   }
 
   /**


Test patch:
diff --git a/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java b/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java
index 0551881064fdea..b8f94567fb14a7 100644
--- a/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java
+++ b/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java
@@ -29,12 +29,16 @@
 import com.google.devtools.build.lib.profiler.chart.ChartVisitor;
 import com.google.devtools.build.lib.profiler.chart.Color;
 import com.google.devtools.build.lib.profiler.chart.DetailedChartCreator;
+import com.google.devtools.build.lib.profiler.chart.HtmlChartVisitor;
 import com.google.devtools.build.lib.testutil.FoundationTestCase;
 import com.google.devtools.build.lib.testutil.Scratch;
 import com.google.devtools.build.lib.testutil.Suite;
 import com.google.devtools.build.lib.testutil.TestSpec;
 import com.google.devtools.build.lib.vfs.Path;
+
 import java.util.List;
+import java.util.Locale;
+
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -230,6 +234,18 @@ public void testVisitor() throws Exception {
     assertThat(visitor.lineCount).isEqualTo(0);
   }
 
+  @Test
+  public void testHtmlChartVisitorFormatColor() {
+    Locale defaultLocale = Locale.getDefault();
+
+    Locale.setDefault(Locale.GERMANY);
+    String black = HtmlChartVisitor.formatColor(Color.GRAY);
+    String[] grayComponents = black.split(",");
+    assertThat(grayComponents.length).isEqualTo(4);
+
+    Locale.setDefault(defaultLocale);
+  }
+
   private ProfileInfo createProfileInfo(Runnable runnable, int noOfRows) throws Exception {
     Scratch scratch = new Scratch();
     Path cacheDir = scratch.dir("/tmp");