Skip to content

Commit c7153ca

Browse files
committed
ensure min < max in case both defined
1 parent 113ec69 commit c7153ca

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

src/plots/cartesian/autorange.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,15 +630,50 @@ function lessOrEqual(v0, v1) { return v0 <= v1; }
630630
function greaterOrEqual(v0, v1) { return v0 >= v1; }
631631

632632
function applyAutorangeMinOptions(v, ax) {
633-
if(ax.autorangemin !== undefined) return ax.autorangemin;
634-
if(ax.autorangeclipmin === undefined) return v;
635-
return Math.max(v, ax.d2l(ax.autorangeclipmin));
633+
if(
634+
ax.autorangemin !== undefined &&
635+
hasValidMinAndMax(ax, ax.autorangemin, ax.autorangemax)
636+
) {
637+
return ax.autorangemin;
638+
}
639+
640+
if(
641+
ax.autorangeclipmin !== undefined &&
642+
hasValidMinAndMax(ax, ax.autorangeclipmin, ax.autorangeclipmax)
643+
) {
644+
return Math.max(v, ax.d2l(ax.autorangeclipmin));
645+
}
646+
return v;
636647
}
637648

638649
function applyAutorangeMaxOptions(v, ax) {
639-
if(ax.autorangemax !== undefined) return ax.autorangemax;
640-
if(ax.autorangeclipmax === undefined) return v;
641-
return Math.min(v, ax.d2l(ax.autorangeclipmax));
650+
if(
651+
ax.autorangemax !== undefined &&
652+
hasValidMinAndMax(ax, ax.autorangemin, ax.autorangemax)
653+
) {
654+
return ax.autorangemax;
655+
}
656+
657+
if(
658+
ax.autorangeclipmax !== undefined &&
659+
hasValidMinAndMax(ax, ax.autorangeclipmin, ax.autorangeclipmax)
660+
) {
661+
return Math.min(v, ax.d2l(ax.autorangeclipmax));
662+
}
663+
return v;
664+
}
665+
666+
function hasValidMinAndMax(ax, min, max) {
667+
// in case both min and max are defined, ensure min < max
668+
if(
669+
min !== undefined &&
670+
max !== undefined
671+
) {
672+
min = ax.d2l(ax.autorangeclipmin);
673+
max = ax.d2l(ax.autorangeclipmax);
674+
return min < max;
675+
}
676+
return true;
642677
}
643678

644679
// this function should be (and is) called before reversing the range

0 commit comments

Comments
 (0)