Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add parameters to change the foreground and background colors.

The query API now supports two more query string parameters,
`fgcolor' and `bgcolor' to set (respectively) the foreground
and background colors.  Acceptable values are of the form
`xRRGGBB' where RGB values are in hexadecimal.  For `bgcolor'
the special value `transparent' can also be used.

This closes #43 and #94.

Change-Id: I9b451fb1b340fc80d4169a0c8b6c1b37af8f5339
  • Loading branch information...
commit e6ddd13f470d0687b07df80fd42974e049941773 1 parent fed8fbc
@tsuna tsuna authored
Showing with 34 additions and 1 deletion.
  1. +28 −1 src/graph/Plot.java
  2. +6 −0 src/tsd/GraphHandler.java
View
29 src/graph/Plot.java
@@ -96,6 +96,13 @@ public Plot(final long start_time, final long end_time) {
* in the Gnuplot script file: {@code set KEY VALUE}.
* When the value is {@code null} the script will instead contain
* {@code unset KEY}.
+ * <p>
+ * Special parameters with a special meaning (since OpenTSDB 1.1):
+ * <ul>
+ * <li>{@code bgcolor}: Either {@code transparent} or an RGB color in
+ * hexadecimal (with a leading 'x' as in {@code x01AB23}).</li>
+ * <li>{@code fgcolor}: An RGB color in hexadecimal ({@code x42BEE7}).</li>
+ * </ul>
*/
public void setParams(final Map<String, String> params) {
this.params = params;
@@ -212,7 +219,27 @@ private void writeGnuplotScript(final String basepath,
gp.append("set term png small size ")
// Why the fuck didn't they also add methods for numbers?
.append(Short.toString(width)).append(",")
- .append(Short.toString(height)).append("\n"
+ .append(Short.toString(height));
+ final String fgcolor = params.remove("fgcolor");
+ String bgcolor = params.remove("bgcolor");
+ if (fgcolor != null && bgcolor == null) {
+ // We can't specify a fgcolor without specifying a bgcolor.
+ bgcolor = "xFFFFFF"; // So use a default.
+ }
+ if (bgcolor != null) {
+ if (fgcolor != null && "transparent".equals(bgcolor)) {
+ // In case we need to specify a fgcolor but we wanted a transparent
+ // background, we also need to pass a bgcolor otherwise the first
+ // hex color will be mistakenly taken as a bgcolor by Gnuplot.
+ bgcolor = "transparent xFFFFFF";
+ }
+ gp.append(' ').append(bgcolor);
+ }
+ if (fgcolor != null) {
+ gp.append(' ').append(fgcolor);
+ }
+
+ gp.append("\n"
+ "set xdata time\n"
+ "set timefmt \"%s\"\n"
+ "set xtic rotate\n"
View
6 src/tsd/GraphHandler.java
@@ -677,6 +677,12 @@ static void setPlotParams(final HttpQuery query, final Plot plot) {
if ((value = popParam(querystring, "title")) != null) {
params.put("title", stringify(value));
}
+ if ((value = popParam(querystring, "bgcolor")) != null) {
+ params.put("bgcolor", value);
+ }
+ if ((value = popParam(querystring, "fgcolor")) != null) {
+ params.put("fgcolor", value);
+ }
// This must remain after the previous `if' in order to properly override
// any previous `key' parameter if a `nokey' parameter is given.
if ((value = popParam(querystring, "nokey")) != null) {
Please sign in to comment.
Something went wrong with that request. Please try again.