diff --git c/lib/Tk/PlotDataset.pm w/lib/Tk/PlotDataset.pm index f8d7e9c..59c9681 100644 --- c/lib/Tk/PlotDataset.pm +++ w/lib/Tk/PlotDataset.pm @@ -156,7 +156,8 @@ This option can be used to override the default format strings, as used by sprintf, to generate the tick labels on the x-axis. In linear mode the default is '%.3g', in log mode '1e%3.2d' will be used for values less than zero and '1e+%2.2d' will be used for values of zero or more. If you override this -format, it will apply to all values in all modes of the x-axis. +format, it will apply to all values in all modes of the x-axis. It is also possible +to supply a code reference, which will take the x value as argument. =item -yTickFormat @@ -164,7 +165,8 @@ This option can be used to override the default format strings, as used by sprintf, to generate the tick labels on the y-axis. In linear mode the default is '%.3g', in log mode '1e%3.2d' will be used for values less than zero and '1e+%2.2d' will be used for values of zero or more. If you override this -format, it will apply to all values in all modes of the y-axis. +format, it will apply to all values in all modes of the y-axis. It is also possible +to supply a code reference, which will take the y value as argument. =item -y1TickFormat @@ -173,7 +175,8 @@ sprintf, to generate the tick labels on the y1-axis. In linear mode the default is '%.3g', in log mode '1e%3.2d' will be used for values less than zero and '1e+%2.2d' will be used for values of zero or more. If you override this format, it will apply to all values in all modes of the y1-axis. The y1-axis -ticks will only be displayed if there are datasets using the y1-axis. +ticks will only be displayed if there are datasets using the y1-axis. It is also possible +to supply a code reference, which will take the y value as argument. =item -balloons @@ -1033,8 +1036,12 @@ sub _create_plot_axis # start and end point of the axis, other args a => b my $tick = delete $args{-tick}; my $label = delete $args{-label}; - my $tick_format = delete $args{-tickFormat}; - $tick_format = '%.3g' unless $tick_format; + my $tick_format_sub = do + { + my $tick_format = delete $args{-tickFormat}; + $tick_format = '%.3g' unless $tick_format; + ref $tick_format eq 'CODE' ? $tick_format : sub { sprintf $tick_format, $_[0] }; + }; my ($do_tick, $do_label) = map {ref $_ eq 'ARRAY'} ($tick, $label); $self -> createLine($x1, $y1, $x2, $y2, %args); @@ -1118,7 +1125,7 @@ sub _create_plot_axis # start and end point of the axis, other args a => b { $self -> createText ( - $x1 - $tl, $y2 - $z, -text => sprintf($tick_format, $l), + $x1 - $tl, $y2 - $z, -text => $tick_format_sub->($l), %args, -fill => $tcolor, -font => $tfont, -anchor => $an, ); @@ -1127,7 +1134,7 @@ sub _create_plot_axis # start and end point of the axis, other args a => b { $self -> createText ( - $z + $x1, $y1 + $tl, -text => sprintf($tick_format, $l), + $z + $x1, $y1 + $tl, -text => $tick_format_sub->($l), %args, -fill => $tcolor, -font => $tfont, -anchor => $an, ); @@ -2793,7 +2800,11 @@ sub _log_range # min, max # for values less than zero and '1e+%2.2d' will be used for values of zero # or more. my ($self, $min, $max, %args) = @_; - my $tick_format = delete $args{-tickFormat}; + my $tick_format_sub = do + { + my $tick_format = delete $args{-tickFormat}; + ref $tick_format eq 'CODE' ? $tick_format : $tick_format ? sub { sprintf $tick_format, $_[0] } : undef; + }; unless (defined($min) and defined($max)) { @@ -2823,9 +2834,9 @@ sub _log_range # min, max { my $n = 10.0 ** $t; # print "_log_range: <$n> <$t>\n"; - if ($tick_format) + if ($tick_format_sub) { - $f = sprintf($tick_format, $t); + $f = $tick_format_sub->($t); } elsif ($t < 0) {