Skip to content

Commit d2858e4

Browse files
author
sfeam
committed
fix problem with autogeneration of linked axis tics if mapping inverse the axis sense
1 parent be3bf80 commit d2858e4

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2017-09-09 Ethan A Merritt <[email protected]>
2+
3+
* src/axis.c( gen_tics ) src/axis.h( reorder_if_necessary ):
4+
New macro to reorder the min/max of axis ranges (but could be used
5+
elsewhere). If the mapping function of linked axes inverts the
6+
axis direction, tics were not being generated because min > max.
7+
E.g. set link x2 via 100-x inv 100-x; set x2tics; plot [50:40] x
8+
19
2017-09-05 Ethan A Merritt <[email protected]>
210

311
* src/axis.c src/axis.h src/datafile.c src/gp_time.h src/gp_types.h

src/axis.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: axis.c,v 1.242 2017-09-05 20:18:58 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: axis.c,v 1.243 2017-09-10 03:40:01 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - axis.c */
@@ -196,12 +196,8 @@ check_log_limits(struct axis *axis, double min, double max)
196196
void
197197
axis_invert_if_requested(struct axis *axis)
198198
{
199-
if (((axis->range_flags & RANGE_IS_REVERSED))
200-
&& (axis->autoscale != 0) && (axis->max > axis->min) ) {
201-
double temp = axis->min;
202-
axis->min = axis->max;
203-
axis->max = temp;
204-
}
199+
if (((axis->range_flags & RANGE_IS_REVERSED)) && (axis->autoscale != 0))
200+
reorder_if_necessary(axis->min, axis->max);
205201
}
206202

207203

@@ -1087,16 +1083,12 @@ gen_tics(struct axis *this, tic_callback callback)
10871083
double user; /* in user co-ords */
10881084
double start, step, end;
10891085
int nsteps;
1090-
double lmin = this->min, lmax = this->max;
10911086
double internal_min, internal_max; /* to allow for rounding errors */
10921087
double ministart = 0, ministep = 1, miniend = 1; /* internal or user - depends on step */
1088+
double lmin = this->min, lmax = this->max;
1089+
1090+
reorder_if_necessary(lmin, lmax);
10931091

1094-
if (lmax < lmin) {
1095-
/* hmm - they have set reversed range for some reason */
1096-
double temp = lmin;
1097-
lmin = lmax;
1098-
lmax = temp;
1099-
}
11001092
/* {{{ choose start, step and end */
11011093
switch (def->type) {
11021094
case TIC_SERIES:
@@ -1127,6 +1119,7 @@ gen_tics(struct axis *this, tic_callback callback)
11271119
if (nonlinear(this)) {
11281120
lmin = this->linked_to_primary->min;
11291121
lmax = this->linked_to_primary->max;
1122+
reorder_if_necessary(lmin, lmax);
11301123
this->ticstep = make_tics(this->linked_to_primary, 20);
11311124
/* It may be that we _always_ want ticstep = 1.0 */
11321125
if (this->ticstep < 1.0)
@@ -1157,15 +1150,8 @@ gen_tics(struct axis *this, tic_callback callback)
11571150
}
11581151
/* }}} */
11591152

1160-
/* {{{ ensure ascending order */
1161-
if (end < start) {
1162-
double temp;
1163-
temp = end;
1164-
end = start;
1165-
start = temp;
1166-
}
1153+
reorder_if_necessary(start, end);
11671154
step = fabs(step);
1168-
/* }}} */
11691155

11701156
if ((minitics != MINI_OFF) && (this->miniticscale != 0)) {
11711157
FPRINTF((stderr,"axis.c: %d start = %g end = %g step = %g base = %g\n",

src/axis.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $Id: axis.h,v 1.177 2017-09-05 20:18:58 sfeam Exp $
2+
* $Id: axis.h,v 1.178 2017-09-10 03:40:01 sfeam Exp $
33
*
44
*/
55

@@ -622,4 +622,9 @@ double eval_link_function __PROTO((AXIS *, double));
622622
ticlevel < MAX_TICLEVEL ? ticscale[ticlevel] : \
623623
0)
624624

625+
/* convenience macro to make sure min < max */
626+
#define reorder_if_necessary( min, max ) \
627+
do { if (max < min) { double temp = min; min = max; max = temp; } \
628+
} while (0)
629+
625630
#endif /* GNUPLOT_AXIS_H */

0 commit comments

Comments
 (0)