Skip to content

Commit f63e9c5

Browse files
committed
remove unnecessary sort
1 parent 95b6600 commit f63e9c5

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/marks/linearRegression.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {create, sum, area as shapeArea, range, min, max} from "d3";
1+
import {create, extent, range, sum, area as shapeArea} from "d3";
22
import {identity, indexOf, maybeZ} from "../options.js";
33
import {Mark} from "../plot.js";
44
import {qt} from "../stats.js";
@@ -49,8 +49,7 @@ class LinearRegressionY extends Mark {
4949
.call(applyDirectStyles, this)
5050
.call(applyGroupedChannelStyles, this, {...channels, stroke: null, strokeOpacity: null, strokeWidth: null})
5151
.attr("d", I => {
52-
const x1 = min(I, i => X[i]);
53-
const x2 = max(I, i => X[i]);
52+
const [x1, x2] = extent(I, i => X[i]);
5453
const f = linearRegressionF(I, X, Y);
5554
const g = confidenceIntervalF(I, X, Y, p, f);
5655
return shapeArea()
@@ -64,8 +63,7 @@ class LinearRegressionY extends Mark {
6463
.call(applyDirectStyles, this)
6564
.call(applyGroupedChannelStyles, this, {...channels, fill: null, fillOpacity: null})
6665
.attr("d", I => {
67-
const x1 = min(I, i => X[i]);
68-
const x2 = max(I, i => X[i]);
66+
const [x1, x2] = extent(I, i => X[i]);
6967
const f = linearRegressionF(I, X, Y);
7068
return `M${x1},${f(x1)}L${x2},${f(x2)}`;
7169
})))
@@ -74,7 +72,7 @@ class LinearRegressionY extends Mark {
7472
}
7573

7674
export function linearRegressionY(data, {x = indexOf, y = identity, stroke, fill = stroke, ...options} = {}) {
77-
return new LinearRegressionY(data, maybeDenseIntervalX({...options, x, y, fill, stroke, sort: {channel: "x"}}));
75+
return new LinearRegressionY(data, maybeDenseIntervalX({...options, x, y, fill, stroke}));
7876
}
7977

8078
function linearRegressionF(I, X, Y) {

test/output/linearRegressionCars.svg

Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)