Skip to content

Commit c029b8b

Browse files
committed
Make the axes arrows configurable per axis.
There are times that you don't want the arrows going in both directions on both axes. For instance, if the x-axis doesn't go to the left, but the y-axis does go both up and down.
1 parent 529ce1f commit c029b8b

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

htdocs/js/Plots/plots.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ const PGplots = {
326326
? 'sticky'
327327
: 'static'
328328
: 'fixed',
329-
firstArrow: options.axesArrowsBoth ? { size: 7 } : false,
329+
firstArrow: options.xAxis.arrowsBoth ? { size: 7 } : false,
330330
lastArrow: { size: 7 },
331331
highlight: false,
332332
straightFirst: options.board?.showNavigation ? true : false,
@@ -420,7 +420,7 @@ const PGplots = {
420420
? 'sticky'
421421
: 'static'
422422
: 'fixed',
423-
firstArrow: options.axesArrowsBoth ? { size: 7 } : false,
423+
firstArrow: options.yAxis.arrowsBoth ? { size: 7 } : false,
424424
lastArrow: { size: 7 },
425425
highlight: false,
426426
straightFirst: options.board?.showNavigation ? true : false,

lib/Plots/Axes.pm

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ Default 'middle' or 'center'.
177177
The position in terms of the appropriate variable to draw the axis if the location is
178178
set to 'middle' or 'center'. Default is 0.
179179
180+
=item arrows_both
181+
182+
Configures if arrows should be drawn in both directions (1) or only in the
183+
positive direction (0) at the axis ends. In other words, this is a choice
184+
between the convention that arrows are meant to indicate that the axis lines
185+
continue forever, or the convention that arrows are meant to indicate the
186+
positive direction of the axis only. Default: 0
187+
180188
=item jsx_options
181189
182190
A hash reference of options to be passed to the JSXGraph axis object.
@@ -238,14 +246,6 @@ usually not desirable. A better way is to use the "axis background" C<layer> to
238246
only place the fill on the "axis background" layer, and leave everything else on
239247
top of the axis.
240248
241-
=item axes_arrows_both
242-
243-
Configures if arrows should be drawn in both directions (1) or only in the
244-
positive direction (0) at the axes ends. In other words, this is a choice
245-
between the convention that arrows are meant to indicate that the axes lines
246-
continue forever, or the convention that arrows are meant to indicate the
247-
positive direction of the axes only. Default: 0
248-
249249
=item mathjax_tick_labels
250250
251251
If this is 1, then tick labels will be displayed using MathJax. If this is 0,
@@ -291,7 +291,6 @@ sub new {
291291
grid_alpha => 40,
292292
show_grid => 1,
293293
axis_on_top => 0,
294-
axes_arrows_both => 0,
295294
mathjax_tick_labels => 1,
296295
},
297296
@options
@@ -322,7 +321,8 @@ sub axis_defaults {
322321
tick_num => 5,
323322
major => 1,
324323
minor => 3,
325-
minor_grids => 1
324+
minor_grids => 1,
325+
arrows_both => 0,
326326
);
327327
}
328328

lib/Plots/JSXGraph.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ sub HTML {
116116
}
117117
}
118118

119-
if ($xvisible || $yvisible) {
120-
$options->{mathJaxTickLabels} = $axes->style('mathjax_tick_labels');
121-
$options->{axesArrowsBoth} = $axes->style('axes_arrows_both');
122-
}
119+
$options->{mathJaxTickLabels} = $axes->style('mathjax_tick_labels') if $xvisible || $yvisible;
123120

124121
if ($xvisible) {
125122
$options->{xAxis}{name} = $axes->xaxis('label');
@@ -128,6 +125,7 @@ sub HTML {
128125
$options->{xAxis}{ticks}{labelFormat} = $axes->xaxis('tick_label_format');
129126
$options->{xAxis}{ticks}{labelDigits} = $axes->xaxis('tick_label_digits');
130127
$options->{xAxis}{ticks}{scaleSymbol} = $axes->xaxis('tick_scale_symbol');
128+
$options->{xAxis}{arrowsBoth} = $axes->xaxis('arrows_both');
131129
$options->{xAxis}{overrideOptions} = $axes->xaxis('jsx_options') if $axes->xaxis('jsx_options');
132130
}
133131
if ($yvisible) {
@@ -137,6 +135,7 @@ sub HTML {
137135
$options->{yAxis}{ticks}{labelFormat} = $axes->yaxis('tick_label_format');
138136
$options->{yAxis}{ticks}{labelDigits} = $axes->yaxis('tick_label_digits');
139137
$options->{yAxis}{ticks}{scaleSymbol} = $axes->yaxis('tick_scale_symbol');
138+
$options->{yAxis}{arrowsBoth} = $axes->yaxis('arrows_both');
140139
$options->{yAxis}{overrideOptions} = $axes->yaxis('jsx_options') if $axes->yaxis('jsx_options');
141140
}
142141

lib/Plots/Tikz.pm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,24 @@ sub generate_axes {
188188
my $xaxis_location = $axes->xaxis('location');
189189
my $xaxis_pos = $xaxis_location eq 'middle' ? $axes->xaxis('position') : 0;
190190
my $yaxis_location = $axes->yaxis('location');
191-
my $yaxis_pos = $yaxis_location eq 'center' ? $axes->yaxis('position') : 0;
192-
my $axis_on_top = $axes->style('axis_on_top') ? "axis on top,\n" : '';
193-
my $negativeArrow = $axes->style('axes_arrows_both') ? 'Latex[{round,scale=1.6}]' : '';
191+
my $yaxis_pos = $yaxis_location eq 'center' ? $axes->yaxis('position') : 0;
192+
my $axis_on_top = $axes->style('axis_on_top') ? "axis on top,\n" : '';
193+
my $xNegativeArrow = $axes->xaxis('arrows_both') ? 'Latex[{round,scale=1.6}]' : '';
194+
my $yNegativeArrow = $axes->yaxis('arrows_both') ? 'Latex[{round,scale=1.6}]' : '';
194195
my $tikz_options = $axes->style('tikz_options') // '';
195196

196197
my $xlabel = $xvisible ? $axes->xaxis('label') : '';
197198
my $xaxis_style =
198199
$xvisible
199-
? ",\nx axis line style={$negativeArrow-Latex[{round,scale=1.6}]}"
200+
? ",\nx axis line style={$xNegativeArrow-Latex[{round,scale=1.6}]}"
200201
: ",\nx axis line style={draw=none},\nextra y ticks={0}";
201202
my $xtick_style =
202203
$xvisible && $axes->xaxis('show_ticks') ? ",\nx tick style={line width=0.6pt}" : ",\nx tick style={draw=none}";
203204

204205
my $ylabel = $yvisible ? $axes->yaxis('label') : '';
205206
my $yaxis_style =
206207
$yvisible
207-
? ",\ny axis line style={$negativeArrow-Latex[{round,scale=1.6}]}"
208+
? ",\ny axis line style={$yNegativeArrow-Latex[{round,scale=1.6}]}"
208209
: ",\ny axis line style={draw=none},\nextra x ticks={0}";
209210
my $ytick_style =
210211
$yvisible && $axes->yaxis('show_ticks') ? ",\ny tick style={line width=0.6pt}" : ",\ny tick style={draw=none}";

0 commit comments

Comments
 (0)