11import { group } from "d3-array" ;
22import { create } from "d3-selection" ;
33import { line } from "d3-shape" ;
4+ import { indexOf , identity } from "../channels.js" ;
45import { Curve } from "../curve.js" ;
56import { defined } from "../defined.js" ;
67
7- const indexOf = ( d , i ) => i ;
8- const identity = d => d ;
9-
108class Line {
11- constructor ( {
12- x,
13- y,
14- z, // grouping for multiple series
15- curve,
16- fill = "none" ,
17- fillOpacity,
18- stroke = "currentColor" ,
19- strokeWidth = z ? 1 : 1.5 ,
20- strokeMiterlimit = 1 ,
21- strokeLinecap,
22- strokeLinejoin,
23- strokeDasharray,
24- strokeOpacity,
25- mixBlendMode
26- } = { } ) {
9+ constructor (
10+ data ,
11+ {
12+ x,
13+ y,
14+ z, // grouping for multiple series
15+ curve,
16+ fill = "none" ,
17+ fillOpacity,
18+ stroke = "currentColor" ,
19+ strokeWidth = z ? 1 : 1.5 ,
20+ strokeMiterlimit = 1 ,
21+ strokeLinecap,
22+ strokeLinejoin,
23+ strokeDasharray,
24+ strokeOpacity,
25+ mixBlendMode
26+ } = { }
27+ ) {
28+ this . data = data ;
2729 this . curve = Curve ( curve ) ;
2830 this . fill = fill ;
2931 this . fillOpacity = fillOpacity ;
@@ -41,7 +43,7 @@ class Line {
4143 z : z && { value : z }
4244 } ;
4345 }
44- render ( { x : { scale : x } , y : { scale : y } } ) {
46+ render ( I , { x : { scale : x } , y : { scale : y } } ) {
4547 const {
4648 curve,
4749 fill,
@@ -63,7 +65,6 @@ class Line {
6365 const { length} = X ;
6466 if ( length !== Y . length ) throw new Error ( "X and Y are different length" ) ;
6567 if ( Z && length !== Z . length ) throw new Error ( "X and Z are different length" ) ;
66- const I = Array . from ( X , ( _ , i ) => i ) ;
6768
6869 function style ( ) {
6970 if ( fill != null ) this . setAttribute ( "fill" , fill ) ;
@@ -106,13 +107,13 @@ class Line {
106107}
107108
108109export class LineX extends Line {
109- constructor ( { x = identity , y = indexOf , ...options } = { } ) {
110- super ( { ...options , x, y} ) ;
110+ constructor ( data , { x = identity , y = indexOf , ...options } = { } ) {
111+ super ( data , { ...options , x, y} ) ;
111112 }
112113}
113114
114115export class LineY extends Line {
115- constructor ( { x = indexOf , y = identity , ...options } = { } ) {
116- super ( { ...options , x, y} ) ;
116+ constructor ( data , { x = indexOf , y = identity , ...options } = { } ) {
117+ super ( data , { ...options , x, y} ) ;
117118 }
118119}
0 commit comments