1- import { create , sum , area as shapeArea , range , min , max } from "d3" ;
1+ import { create , extent , range , sum , area as shapeArea } from "d3" ;
22import { identity , indexOf , maybeZ } from "../options.js" ;
33import { Mark } from "../plot.js" ;
44import { 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
7674export 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
8078function linearRegressionF ( I , X , Y ) {
0 commit comments