@@ -2,37 +2,22 @@ import * as Plot from "@observablehq/plot";
2
2
import * as d3 from "d3" ;
3
3
import { feature , mesh } from "topojson-client" ;
4
4
5
- function tipped ( mark , options = { } , pointer = Plot . pointer ) {
6
- return Plot . marks ( mark , Plot . tip ( mark . data , pointer ( derive ( mark , options ) ) ) ) ;
7
- }
8
-
9
- function tippedX ( mark , options = { } ) {
10
- return tipped ( mark , options , Plot . pointerX ) ;
11
- }
12
-
13
- function tippedY ( mark , options = { } ) {
14
- return tipped ( mark , options , Plot . pointerY ) ;
15
- }
16
-
17
- function derive ( mark , options = { } ) {
18
- return Plot . initializer ( { ...options , x : null , y : null } , ( data , facets , channels , scales , dimensions , context ) => {
19
- return ( context as any ) . getMarkState ( mark ) ;
20
- } ) ;
21
- }
22
-
23
5
export async function tipBar ( ) {
24
6
const olympians = await d3 . csv < any > ( "data/athletes.csv" , d3 . autoType ) ;
25
- return tippedY ( Plot . barX ( olympians , Plot . groupY ( { x : "count" } , { y : "sport" , sort : { y : "x" } } ) ) ) . plot ( { marginLeft : 100 } ) ;
7
+ return Plot . plot ( {
8
+ marginLeft : 100 ,
9
+ marks : [ Plot . barX ( olympians , Plot . groupY ( { x : "count" } , { y : "sport" , sort : { y : "x" } , tip : true } ) ) ]
10
+ } ) ;
26
11
}
27
12
28
13
export async function tipBin ( ) {
29
14
const olympians = await d3 . csv < any > ( "data/athletes.csv" , d3 . autoType ) ;
30
- return tippedX ( Plot . rectY ( olympians , Plot . binX ( { y : "count" } , { x : "weight" } ) ) ) . plot ( ) ;
15
+ return Plot . rectY ( olympians , Plot . binX ( { y : "count" } , { x : "weight" , tip : true } ) ) . plot ( ) ;
31
16
}
32
17
33
18
export async function tipBinStack ( ) {
34
19
const olympians = await d3 . csv < any > ( "data/athletes.csv" , d3 . autoType ) ;
35
- return tippedX ( Plot . rectY ( olympians , Plot . binX ( { y : "count" } , { x : "weight" , fill : "sex" } ) ) ) . plot ( ) ;
20
+ return Plot . rectY ( olympians , Plot . binX ( { y : "count" } , { x : "weight" , fill : "sex" , tip : true } ) ) . plot ( ) ;
36
21
}
37
22
38
23
export async function tipCell ( ) {
@@ -41,7 +26,7 @@ export async function tipCell() {
41
26
height : 400 ,
42
27
marginLeft : 100 ,
43
28
color : { scheme : "blues" } ,
44
- marks : [ tippedY ( Plot . cell ( olympians , Plot . group ( { fill : "count" } , { x : "sex" , y : "sport" } ) ) ) ]
29
+ marks : [ Plot . cell ( olympians , Plot . group ( { fill : "count" } , { x : "sex" , y : "sport" , tip : "y" } ) ) ]
45
30
} ) ;
46
31
}
47
32
@@ -51,18 +36,18 @@ export async function tipCellFacet() {
51
36
height : 400 ,
52
37
marginLeft : 100 ,
53
38
color : { scheme : "blues" } ,
54
- marks : [ tippedY ( Plot . cell ( olympians , Plot . groupY ( { fill : "count" } , { fx : "sex" , y : "sport" } ) ) ) ]
39
+ marks : [ Plot . cell ( olympians , Plot . groupY ( { fill : "count" } , { fx : "sex" , y : "sport" , tip : "y" } ) ) ]
55
40
} ) ;
56
41
}
57
42
58
43
export async function tipDodge ( ) {
59
44
const penguins = await d3 . csv < any > ( "data/penguins.csv" , d3 . autoType ) ;
60
- return tipped ( Plot . dot ( penguins , Plot . dodgeY ( { x : "culmen_length_mm" , r : "body_mass_g" } ) ) ) . plot ( { height : 160 } ) ;
45
+ return Plot . dot ( penguins , Plot . dodgeY ( { x : "culmen_length_mm" , r : "body_mass_g" , tip : true } ) ) . plot ( { height : 160 } ) ;
61
46
}
62
47
63
48
export async function tipDot ( ) {
64
49
const penguins = await d3 . csv < any > ( "data/penguins.csv" , d3 . autoType ) ;
65
- return tipped ( Plot . dot ( penguins , { x : "culmen_length_mm" , y : "culmen_depth_mm" , stroke : "sex" } ) ) . plot ( ) ;
50
+ return Plot . dot ( penguins , { x : "culmen_length_mm" , y : "culmen_depth_mm" , stroke : "sex" , tip : true } ) . plot ( ) ;
66
51
}
67
52
68
53
export async function tipDotFacets ( ) {
@@ -74,25 +59,27 @@ export async function tipDotFacets() {
74
59
interval : "10 years"
75
60
} ,
76
61
marks : [
77
- tipped (
78
- Plot . dot ( athletes , {
79
- x : "weight" ,
80
- y : "height" ,
81
- fx : "sex" ,
82
- fy : "date_of_birth" ,
83
- channels : { name : "name" , sport : "sport" }
84
- } )
85
- )
62
+ Plot . dot ( athletes , {
63
+ x : "weight" ,
64
+ y : "height" ,
65
+ fx : "sex" ,
66
+ fy : "date_of_birth" ,
67
+ channels : { name : "name" , sport : "sport" } ,
68
+ tip : true
69
+ } )
86
70
]
87
71
} ) ;
88
72
}
89
73
90
74
export async function tipDotFilter ( ) {
91
75
const penguins = await d3 . csv < any > ( "data/penguins.csv" , d3 . autoType ) ;
92
76
const xy = { x : "culmen_length_mm" , y : "culmen_depth_mm" , stroke : "sex" } ;
93
- const [ dot1 , tip1 ] = tipped ( Plot . dot ( penguins , { ...xy , filter : ( d ) => d . sex === "MALE" } ) , { anchor : "left" } ) ;
94
- const [ dot2 , tip2 ] = tipped ( Plot . dot ( penguins , { ...xy , filter : ( d ) => d . sex === "FEMALE" } ) , { anchor : "right" } ) ;
95
- return Plot . marks ( dot1 , dot2 , tip1 , tip2 ) . plot ( ) ;
77
+ return Plot . plot ( {
78
+ marks : [
79
+ Plot . dot ( penguins , { ...xy , filter : ( d ) => d . sex === "MALE" , tip : true } ) ,
80
+ Plot . dot ( penguins , { ...xy , filter : ( d ) => d . sex === "FEMALE" , tip : true } )
81
+ ]
82
+ } ) ;
96
83
}
97
84
98
85
export async function tipGeoCentroid ( ) {
@@ -119,12 +106,12 @@ export async function tipGeoCentroid() {
119
106
120
107
export async function tipHexbin ( ) {
121
108
const olympians = await d3 . csv < any > ( "data/athletes.csv" , d3 . autoType ) ;
122
- return tipped ( Plot . hexagon ( olympians , Plot . hexbin ( { r : "count" } , { x : "weight" , y : "height" } ) ) ) . plot ( ) ;
109
+ return Plot . hexagon ( olympians , Plot . hexbin ( { r : "count" } , { x : "weight" , y : "height" , tip : true } ) ) . plot ( ) ;
123
110
}
124
111
125
112
export async function tipLine ( ) {
126
113
const aapl = await d3 . csv < any > ( "data/aapl.csv" , d3 . autoType ) ;
127
- return tippedX ( Plot . lineY ( aapl , { x : "Date" , y : "Close" } ) ) . plot ( ) ;
114
+ return Plot . lineY ( aapl , { x : "Date" , y : "Close" , tip : true } ) . plot ( ) ;
128
115
}
129
116
130
117
export async function tipRaster ( ) {
@@ -135,11 +122,11 @@ export async function tipRaster() {
135
122
height : 484 ,
136
123
projection : { type : "reflect-y" , inset : 3 , domain} ,
137
124
color : { type : "diverging" } ,
138
- marks : [ tipped ( Plot . raster ( ca55 , { x : "GRID_EAST" , y : "GRID_NORTH" , fill : "MAG_IGRF90" , interpolate : "nearest" } ) ) ]
125
+ marks : [ Plot . raster ( ca55 , { x : "GRID_EAST" , y : "GRID_NORTH" , fill : "MAG_IGRF90" , interpolate : "nearest" , tip : true } ) ]
139
126
} ) ;
140
127
}
141
128
142
129
export async function tipRule ( ) {
143
130
const penguins = await d3 . csv < any > ( "data/penguins.csv" , d3 . autoType ) ;
144
- return tippedX ( Plot . ruleX ( penguins , { x : "body_mass_g" } ) ) . plot ( ) ;
131
+ return Plot . ruleX ( penguins , { x : "body_mass_g" , tip : true } ) . plot ( ) ;
145
132
}
0 commit comments