diff options
author | Adrián Medraño Calvo <adrian@medranocalvo.com> | 2017-07-28 09:54:54 (GMT) |
---|---|---|
committer | Adrián Medraño Calvo <adrian@medranocalvo.com> | 2017-07-28 12:06:18 (GMT) |
commit | e4521220d9623f9e00ff1a5f1497665c956b1387 (patch) | |
tree | 4beacf0e1431620b3e5bebc0074028e8bc0b5494 | |
parent | d2c078754fbaee1bd22d77202f9af3d706f45b94 (diff) | |
download | blt-e4521220d9623f9e00ff1a5f1497665c956b1387.zip blt-e4521220d9623f9e00ff1a5f1497665c956b1387.tar.gz blt-e4521220d9623f9e00ff1a5f1497665c956b1387.tar.bz2 |
Add -tickformat axis option, rename -command option to -tickformatcommand
-rw-r--r-- | doc/graph.html | 42 | ||||
-rw-r--r-- | doc/graph.n | 38 | ||||
-rw-r--r-- | generic/tkbltGrAxis.C | 22 | ||||
-rw-r--r-- | generic/tkbltGrAxis.h | 4 |
4 files changed, 66 insertions, 40 deletions
diff --git a/doc/graph.html b/doc/graph.html index 412c817..70f1e6f 100644 --- a/doc/graph.html +++ b/doc/graph.html @@ -438,23 +438,6 @@ Sets the color of the axis and tick labels. The default is black. - <B>-command</B> <I>prefix</I> - Specifies a Tcl command to be invoked when formatting the - axis tick labels. <I>Prefix</I> is a string containing the name - of a Tcl proc and any extra arguments for the procedure. - This command is invoked for each major tick on the axis. - Two additional arguments are passed to the procedure: the - pathname of the widget and the current the numeric value - of the tick. The procedure returns the formatted tick - label. If "" is returned, no label will appear next to - the tick. You can get the standard tick labels again by - setting <I>prefix</I> to "". The default is "". - - Please note that this procedure is invoked while the - graph is redrawn. You may query configuration options. - But do not them, because this can have unexpected - results. - <B>-descending</B> <I>boolean</I> Indicates whether the values along the axis are monotoni- cally increasing or decreasing. If <I>boolean</I> is true, the @@ -542,6 +525,31 @@ Specifies the font for axis tick labels. The default is *-Courier-Bold-R-Normal-*-100-*. + <B>-tickformat</B> <I>formatStr</I> + Specifies a printf-like description to format teh axis + tick labels. You can get the standard tick labels again by + setting <I>formatStr</I> to "". The default is "". + + <B>-tickformatcommand</B>, <B>-command</B> <I>prefix</I> + Specifies a Tcl command to be invoked when formatting the + axis tick labels. <I>Prefix</I> is a string containing the name + of a Tcl proc and any extra arguments for the procedure. + This command is invoked for each major tick on the axis. + Two additional arguments are passed to the procedure: the + pathname of the widget and the current the numeric value + of the tick. The procedure returns the formatted tick + label. If "" is returned, no label will appear next to + the tick. You can get the standard tick labels again by + setting <I>prefix</I> to "". The default is "". + + The numeric value for the tick might change when using the + <B>-logscale</B> and <B>-tickformat</B> options. + + Please note that this procedure is invoked while the + graph is redrawn. You may query configuration options. + But do not them, because this can have unexpected + results. + <B>-ticklength</B> <I>pixels</I> Sets the length of major and minor ticks (minor ticks are half the length of major ticks). If <I>pixels</I> is less than diff --git a/doc/graph.n b/doc/graph.n index 72df726..fbbbb9b 100644 --- a/doc/graph.n +++ b/doc/graph.n @@ -686,21 +686,6 @@ the element is always the first tag in the list. The default value is Sets the color of the axis and tick labels. The default is \f(CWblack\fR. .TP -\fB\-command \fIprefix\fR -Specifies a Tcl command to be invoked when formatting the axis tick -labels. \fIPrefix\fR is a string containing the name of a Tcl proc and -any extra arguments for the procedure. This command is invoked for each -major tick on the axis. Two additional arguments are passed to the -procedure: the pathname of the widget and the current the numeric -value of the tick. The procedure returns the formatted tick label. If -\f(CW""\fR is returned, no label will appear next to the tick. You can -get the standard tick labels again by setting \fIprefix\fR to -\f(CW""\fR. The default is \f(CW""\fR. -.sp 1 -Please note that this procedure is invoked while the graph is redrawn. -You may query configuration options. But do not them, because this -can have unexpected results. -.TP \fB\-descending \fIboolean\fR Indicates whether the values along the axis are monotonically increasing or decreasing. If \fIboolean\fR is true, the axis values will be @@ -810,6 +795,29 @@ displayed. The default is \f(CW2\fR. Specifies the font for axis tick labels. The default is \f(CW*-Courier-Bold-R-Normal-*-100-*\fR. .TP +\fB\-tickformat\fR \fIformatStr\fR +Specifies a printf-like description to format teh axis +tick labels. You can get the standard tick labels again by +setting \fIformatStr\fR to \f(CW""\fR. The default is \f(CW""\fR. +.TP +\fB\-tickformatcommand\fR, \fB\-command \fIprefix\fR +Specifies a Tcl command to be invoked when formatting the axis tick +labels. \fIPrefix\fR is a string containing the name of a Tcl proc and +any extra arguments for the procedure. This command is invoked for each +major tick on the axis. Two additional arguments are passed to the +procedure: the pathname of the widget and the current the numeric +value of the tick. The procedure returns the formatted tick label. If +\f(CW""\fR is returned, no label will appear next to the tick. You can +get the standard tick labels again by setting \fIprefix\fR to +\f(CW""\fR. The default is \f(CW""\fR. +.sp 1 +The numeric value for the tick might change when using the +\fB\-logscale\fR and \fB\-tickformat\fR options. +.sp 1 +Please note that this procedure is invoked while the graph is redrawn. +You may query configuration options. But do not them, because this +can have unexpected results. +.TP \fB\-ticklength \fIpixels\fR Sets the length of major and minor ticks (minor ticks are half the length of major ticks). If \fIpixels\fR is less than zero, the axis diff --git a/generic/tkbltGrAxis.C b/generic/tkbltGrAxis.C index a9cb879..bac6316 100644 --- a/generic/tkbltGrAxis.C +++ b/generic/tkbltGrAxis.C @@ -84,8 +84,8 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_COLOR, "-color", "color", "Color", STD_NORMAL_FOREGROUND, -1, Tk_Offset(AxisOptions, tickColor), 0, NULL, CACHE}, - {TK_OPTION_STRING, "-command", "command", "Command", - NULL, -1, Tk_Offset(AxisOptions, formatCmd), TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_SYNONYM, "-command", NULL, NULL, + NULL, 0, -1, 0, (ClientData)"-tickformatcommand", 0}, {TK_OPTION_BOOLEAN, "-descending", "descending", "Descending", "no", -1, Tk_Offset(AxisOptions, descending), 0, NULL, RESET}, {TK_OPTION_BOOLEAN, "-exterior", "exterior", "exterior", @@ -179,6 +179,10 @@ static Tk_OptionSpec optionSpecs[] = { "8", -1, Tk_Offset(AxisOptions, tickLength), 0, NULL, LAYOUT}, {TK_OPTION_INT, "-tickdefault", "tickDefault", "TickDefault", "4", -1, Tk_Offset(AxisOptions, reqNumMajorTicks), 0, NULL, RESET}, + {TK_OPTION_STRING, "-tickformat", "tickFormat", "TickFormat", + NULL, -1, Tk_Offset(AxisOptions, tickFormat), TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_STRING, "-tickformatcommand", "tickformatcommand", "TickFormatCommand", + NULL, -1, Tk_Offset(AxisOptions, tickFormatCmd), TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING, "-title", "title", "Title", NULL, -1, Tk_Offset(AxisOptions, title), TK_OPTION_NULL_OK, NULL, LAYOUT}, {TK_OPTION_BOOLEAN, "-titlealternate", "titleAlternate", "TitleAlternate", @@ -1032,12 +1036,16 @@ TickLabel* Axis::makeLabel(double value) AxisOptions* ops = (AxisOptions*)ops_; char string[TICK_LABEL_SIZE + 1]; - if (ops->logScale) + + if (ops->tickFormat && *ops->tickFormat) { + snprintf(string, TICK_LABEL_SIZE, ops->tickFormat, value); + } else if (ops->logScale) { snprintf(string, TICK_LABEL_SIZE, "1E%d", int(value)); - else - snprintf(string, TICK_LABEL_SIZE, "%.*G", 15, value); + } else { + snprintf(string, TICK_LABEL_SIZE, "%.15G", value); + } - if (ops->formatCmd) { + if (ops->tickFormatCmd) { Tcl_Interp* interp = graphPtr_->interp_; Tk_Window tkwin = graphPtr_->tkwin_; @@ -1045,7 +1053,7 @@ TickLabel* Axis::makeLabel(double value) // name of the widget and the default tick label as arguments when // invoking it. Copy and save the new label from interp->result. Tcl_ResetResult(interp); - if (Tcl_VarEval(interp, ops->formatCmd, " ", Tk_PathName(tkwin), + if (Tcl_VarEval(interp, ops->tickFormatCmd, " ", Tk_PathName(tkwin), " ", string, NULL) != TCL_OK) { Tcl_BackgroundError(interp); } diff --git a/generic/tkbltGrAxis.h b/generic/tkbltGrAxis.h index 90a1165..d459e8c 100644 --- a/generic/tkbltGrAxis.h +++ b/generic/tkbltGrAxis.h @@ -114,7 +114,7 @@ namespace Blt { int showTicks; double windowSize; - const char *formatCmd; + const char *tickFormatCmd; int descending; int labelOffset; TextStyleOptions limitsTextStyle; @@ -153,6 +153,8 @@ namespace Blt { Tk_Font tickFont; Tk_Font titleFont; XColor* titleColor; + + const char *tickFormat; } AxisOptions; class Axis { |