Skip to content

Commit b03bd2b

Browse files
author
sfeam
committed
Refactor parse_range() to handle in-line ranges for linked or nonlinear axes
1 parent d2858e4 commit b03bd2b

File tree

2 files changed

+52
-39
lines changed

2 files changed

+52
-39
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
axis direction, tics were not being generated because min > max.
77
E.g. set link x2 via 100-x inv 100-x; set x2tics; plot [50:40] x
88

9+
* src/axis.c (parse_range): Refactor parse_range() to handle
10+
in-line ranges for linked or nonlinear axes.
11+
Bug #1964
12+
913
2017-09-05 Ethan A Merritt <[email protected]>
1014

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

src/axis.c

Lines changed: 48 additions & 39 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.243 2017-09-10 03:40:01 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: axis.c,v 1.244 2017-09-10 03:49:31 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - axis.c */
@@ -2226,49 +2226,58 @@ int
22262226
parse_range(AXIS_INDEX axis)
22272227
{
22282228
struct axis *this_axis = &axis_array[axis];
2229+
int dummy_token = -1;
22292230

2230-
if (equals(c_token, "[")) {
2231-
int dummy_token = -1;
2232-
c_token++;
2233-
/* If the range starts with "[var=" return the token of the named variable. */
2234-
if (isletter(c_token) && equals(c_token + 1, "=")) {
2235-
dummy_token = c_token;
2236-
c_token += 2;
2237-
}
2238-
this_axis->autoscale =
2239-
load_range(this_axis, &this_axis->min, &this_axis->max, this_axis->autoscale);
2240-
if (this_axis->linked_to_primary) {
2241-
AXIS *primary = this_axis->linked_to_primary;
2242-
primary->min = eval_link_function(primary, this_axis->min);
2243-
primary->max = eval_link_function(primary, this_axis->max);
2244-
}
2231+
/* No range present */
2232+
if (!equals(c_token, "["))
2233+
return 0;
22452234

2246-
/* DEBUG 2 Sep 2017
2247-
* This handles (imperfectly) the problem case
2248-
* set link x2 via f(x) inv g(x)
2249-
* plot [x=min:max][] something that involves x2
2250-
* Other cases of in-line range changes on a linked axis may fail
2251-
*/
2252-
else if (this_axis->linked_to_secondary) {
2253-
AXIS *secondary = this_axis->linked_to_secondary;
2254-
if (secondary->link_udf != NULL && secondary->link_udf->at != NULL)
2255-
clone_linked_axes(this_axis, secondary);
2256-
}
2235+
/* Empty brackets serve as a place holder */
2236+
if (equals(c_token, "[]")) {
2237+
c_token += 2;
2238+
return 0;
2239+
}
22572240

2258-
if (axis == SAMPLE_AXIS || axis == T_AXIS || axis == U_AXIS || axis == V_AXIS) {
2259-
this_axis->SAMPLE_INTERVAL = 0;
2260-
if (equals(c_token, ":")) {
2261-
c_token++;
2262-
this_axis->SAMPLE_INTERVAL = real_expression();
2263-
}
2241+
/* If the range starts with "[var=" return the token of the named variable. */
2242+
c_token++;
2243+
if (isletter(c_token) && equals(c_token + 1, "=")) {
2244+
dummy_token = c_token;
2245+
c_token += 2;
2246+
}
2247+
2248+
this_axis->autoscale = load_range(this_axis, &this_axis->min, &this_axis->max,
2249+
this_axis->autoscale);
2250+
2251+
/* Nonlinear axis - find the linear range equivalent */
2252+
if (this_axis->linked_to_primary) {
2253+
AXIS *primary = this_axis->linked_to_primary;
2254+
clone_linked_axes(this_axis, primary);
2255+
}
2256+
2257+
/* This handles (imperfectly) the problem case
2258+
* set link x2 via f(x) inv g(x)
2259+
* plot [x=min:max][] something that involves x2
2260+
* Other cases of in-line range changes on a linked axis may fail
2261+
*/
2262+
else if (this_axis->linked_to_secondary) {
2263+
AXIS *secondary = this_axis->linked_to_secondary;
2264+
if (secondary->link_udf != NULL && secondary->link_udf->at != NULL)
2265+
clone_linked_axes(this_axis, secondary);
2266+
}
2267+
2268+
if (axis == SAMPLE_AXIS || axis == T_AXIS || axis == U_AXIS || axis == V_AXIS) {
2269+
this_axis->SAMPLE_INTERVAL = 0;
2270+
if (equals(c_token, ":")) {
2271+
c_token++;
2272+
this_axis->SAMPLE_INTERVAL = real_expression();
22642273
}
2274+
}
22652275

2266-
if (!equals(c_token, "]"))
2267-
int_error(c_token, "']' expected");
2268-
c_token++;
2269-
return dummy_token;
2270-
} else
2271-
return 0;
2276+
if (!equals(c_token, "]"))
2277+
int_error(c_token, "']' expected");
2278+
c_token++;
2279+
2280+
return dummy_token;
22722281
}
22732282

22742283
/* Called if an in-line range is encountered while inside a zoom command */

0 commit comments

Comments
 (0)