]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
_boundSegments did not work on rising line (#8838)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Wed, 7 Apr 2021 11:32:28 +0000 (14:32 +0300)
committerGitHub <noreply@github.com>
Wed, 7 Apr 2021 11:32:28 +0000 (07:32 -0400)
src/helpers/helpers.segment.js
test/specs/helpers.segment.tests.js

index 9a3ce5ec84b988fd6b860d1a4454f04505443a0b..b68582312489bb1c2d128347141042bb6663f9c6 100644 (file)
@@ -14,7 +14,7 @@ function propertyFn(property) {
     };
   }
   return {
-    between: (n, s, e) => n >= s && n <= e,
+    between: (n, s, e) => n >= Math.min(s, e) && n <= Math.max(e, s),
     compare: (a, b) => a - b,
     normalize: x => x
   };
index c0ac630260324072037a4e14ada288cff1293ec6..eca3c3fab7f332332c4a80424602fc393f7eaa74 100644 (file)
@@ -40,5 +40,14 @@ describe('helpers.segments', function() {
     it('should find segment from after the line', function() {
       expect(_boundSegment(segment, points, {property: 'x', start: 25, end: 35})).toEqual([{start: 1, end: 2, loop: false}]);
     });
+
+    it('should find multiple segments', function() {
+      const points2 = [{x: 0, y: 100}, {x: 1, y: 50}, {x: 2, y: 70}, {x: 4, y: 80}, {x: 5, y: -100}];
+      expect(_boundSegment({start: 0, end: 4, loop: false}, points2, {property: 'y', start: 60, end: 60})).toEqual([
+        {start: 0, end: 1, loop: false},
+        {start: 1, end: 2, loop: false},
+        {start: 3, end: 4, loop: false},
+      ]);
+    });
   });
 });