]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Use the correct area to clip for dataset drawing when stacked scales are used (...
authorstockiNail <stocki.nail@gmail.com>
Sat, 1 Oct 2022 18:26:45 +0000 (20:26 +0200)
committerGitHub <noreply@github.com>
Sat, 1 Oct 2022 18:26:45 +0000 (21:26 +0300)
* Use the correct area to clip when stacked scales are used

* adds test cases

* fix CI issue

* apply review

* Update .size-limit.cjs

Co-authored-by: Jacco van den Berg <jaccoberg2281@gmail.com>
Co-authored-by: Jacco van den Berg <jaccoberg2281@gmail.com>
.size-limit.cjs
src/core/core.controller.js
test/fixtures/core.layouts/stacked-boxes-max-index.js [new file with mode: 0644]
test/fixtures/core.layouts/stacked-boxes-max-index.png [new file with mode: 0644]
test/fixtures/core.layouts/stacked-boxes-max.js [new file with mode: 0644]
test/fixtures/core.layouts/stacked-boxes-max.png [new file with mode: 0644]

index 17547708230669a0f1b9fd9a9c08b46c86f0ad0f..f4606e0b791b34105bbeb980e737dfe4aae9d0d0 100644 (file)
@@ -7,7 +7,7 @@ function modifyWebpackConfig(config) {
 module.exports = [
   {
     path: 'dist/chart.js',
-    limit: '77.2 KB',
+    limit: '77.5 KB',
     webpack: false,
     running: false
   },
index 396193a170a42951bbe3cbe8da3d8d8ffcf9466d..9991263b76f4b68d6779488b276a20129f23f8dc 100644 (file)
@@ -101,6 +101,18 @@ function determineLastEvent(e, lastEvent, inChartArea, isClick) {
   return e;
 }
 
+function getDatasetArea(meta) {
+  const {xScale, yScale} = meta;
+  if (xScale && yScale) {
+    return {
+      left: xScale.left,
+      right: xScale.right,
+      top: yScale.top,
+      bottom: yScale.bottom
+    };
+  }
+}
+
 class Chart {
 
   static defaults = defaults;
@@ -784,7 +796,7 @@ class Chart {
     const ctx = this.ctx;
     const clip = meta._clip;
     const useClip = !clip.disabled;
-    const area = this.chartArea;
+    const area = getDatasetArea(meta) || this.chartArea;
     const args = {
       meta,
       index: meta.index,
diff --git a/test/fixtures/core.layouts/stacked-boxes-max-index.js b/test/fixtures/core.layouts/stacked-boxes-max-index.js
new file mode 100644 (file)
index 0000000..60fd5f4
--- /dev/null
@@ -0,0 +1,109 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      datasets: [
+        {data: [{x: 5, y: 1}, {x: 10, y: 2}, {x: 5, y: 3}], borderColor: 'red'},
+        {data: [{x: 5, y: 1}, {x: 10, y: 2}, {x: 5, y: 3}], yAxisID: 'y1', xAxisID: 'x1', borderColor: 'green'},
+        {data: [{x: 5, y: 1}, {x: 10, y: 2}, {x: 5, y: 3}], yAxisID: 'y2', xAxisID: 'x2', borderColor: 'blue'},
+      ],
+      labels: ['tick1', 'tick2', 'tick3']
+    },
+    options: {
+      plugins: false,
+      scales: {
+        x: {
+          type: 'linear',
+          position: 'bottom',
+          stack: '1',
+          offset: true,
+          bounds: 'data',
+          border: {
+            color: 'red'
+          },
+          ticks: {
+            autoSkip: false,
+            maxRotation: 0,
+            count: 3
+          },
+          max: 7
+        },
+        x1: {
+          type: 'linear',
+          position: 'bottom',
+          stack: '1',
+          offset: true,
+          bounds: 'data',
+          border: {
+            color: 'green'
+          },
+          ticks: {
+            autoSkip: false,
+            maxRotation: 0,
+            count: 3
+          },
+          max: 7
+        },
+        x2: {
+          type: 'linear',
+          position: 'bottom',
+          stack: '1',
+          offset: true,
+          bounds: 'data',
+          border: {
+            color: 'blue'
+          },
+          ticks: {
+            autoSkip: false,
+            maxRotation: 0,
+            count: 3
+          },
+          max: 7
+        },
+        y: {
+          type: 'linear',
+          position: 'left',
+          stack: '1',
+          offset: true,
+          border: {
+            color: 'red'
+          },
+          ticks: {
+            precision: 0
+          }
+        },
+        y1: {
+          type: 'linear',
+          position: 'left',
+          stack: '1',
+          offset: true,
+          border: {
+            color: 'green'
+          },
+          ticks: {
+            precision: 0
+          }
+        },
+        y2: {
+          type: 'linear',
+          position: 'left',
+          stack: '1',
+          offset: true,
+          border: {
+            color: 'blue',
+          },
+          ticks: {
+            precision: 0
+          }
+        }
+      }
+    }
+  },
+  options: {
+    spriteText: true,
+    canvas: {
+      height: 384,
+      width: 384
+    }
+  }
+};
diff --git a/test/fixtures/core.layouts/stacked-boxes-max-index.png b/test/fixtures/core.layouts/stacked-boxes-max-index.png
new file mode 100644 (file)
index 0000000..60c829a
Binary files /dev/null and b/test/fixtures/core.layouts/stacked-boxes-max-index.png differ
diff --git a/test/fixtures/core.layouts/stacked-boxes-max.js b/test/fixtures/core.layouts/stacked-boxes-max.js
new file mode 100644 (file)
index 0000000..43fd9d3
--- /dev/null
@@ -0,0 +1,109 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      datasets: [
+        {data: [{x: 1, y: 5}, {x: 2, y: 10}, {x: 3, y: 5}], borderColor: 'red'},
+        {data: [{x: 1, y: 5}, {x: 2, y: 10}, {x: 3, y: 5}], yAxisID: 'y1', xAxisID: 'x1', borderColor: 'green'},
+        {data: [{x: 1, y: 5}, {x: 2, y: 10}, {x: 3, y: 5}], yAxisID: 'y2', xAxisID: 'x2', borderColor: 'blue'},
+      ],
+      labels: ['tick1', 'tick2', 'tick3']
+    },
+    options: {
+      plugins: false,
+      scales: {
+        x: {
+          type: 'linear',
+          position: 'bottom',
+          stack: '1',
+          offset: true,
+          bounds: 'data',
+          border: {
+            color: 'red'
+          },
+          ticks: {
+            autoSkip: false,
+            maxRotation: 0,
+            count: 3
+          }
+        },
+        x1: {
+          type: 'linear',
+          position: 'bottom',
+          stack: '1',
+          offset: true,
+          bounds: 'data',
+          border: {
+            color: 'green'
+          },
+          ticks: {
+            autoSkip: false,
+            maxRotation: 0,
+            count: 3
+          }
+        },
+        x2: {
+          type: 'linear',
+          position: 'bottom',
+          stack: '1',
+          offset: true,
+          bounds: 'data',
+          border: {
+            color: 'blue'
+          },
+          ticks: {
+            autoSkip: false,
+            maxRotation: 0,
+            count: 3
+          }
+        },
+        y: {
+          type: 'linear',
+          position: 'left',
+          stack: '1',
+          offset: true,
+          border: {
+            color: 'red'
+          },
+          ticks: {
+            precision: 0
+          },
+          max: 7
+        },
+        y1: {
+          type: 'linear',
+          position: 'left',
+          stack: '1',
+          offset: true,
+          border: {
+            color: 'green'
+          },
+          ticks: {
+            precision: 0
+          },
+          max: 7
+        },
+        y2: {
+          type: 'linear',
+          position: 'left',
+          stack: '1',
+          offset: true,
+          border: {
+            color: 'blue',
+          },
+          ticks: {
+            precision: 0
+          },
+          max: 7
+        }
+      }
+    }
+  },
+  options: {
+    spriteText: true,
+    canvas: {
+      height: 384,
+      width: 384
+    }
+  }
+};
diff --git a/test/fixtures/core.layouts/stacked-boxes-max.png b/test/fixtures/core.layouts/stacked-boxes-max.png
new file mode 100644 (file)
index 0000000..b136ab0
Binary files /dev/null and b/test/fixtures/core.layouts/stacked-boxes-max.png differ