@@ -7,7 +7,8 @@ import {Mark} from "../mark.js";
77import { maybeAnchor , maybeFrameAnchor , maybeTuple , number , string } from "../options.js" ;
88import { applyDirectStyles , applyFrameAnchor , applyIndirectStyles , applyTransform , impliedString } from "../style.js" ;
99import { inferTickFormat } from "./axis.js" ;
10- import { applyIndirectTextStyles , cut , defaultWidth , ellipsis , monospaceWidth } from "./text.js" ;
10+ import { applyIndirectTextStyles , defaultWidth , ellipsis , monospaceWidth } from "./text.js" ;
11+ import { cut , clipper , splitter , maybeTextOverflow } from "./text.js" ;
1112
1213const defaults = {
1314 ariaLabel : "tip" ,
@@ -16,7 +17,7 @@ const defaults = {
1617} ;
1718
1819// These channels are not displayed in the tip; TODO allow customization.
19- const ignoreChannels = new Set ( [ "geometry" , "title" , " href", "src" , "ariaLabel" ] ) ;
20+ const ignoreChannels = new Set ( [ "geometry" , "href" , "src" , "ariaLabel" ] ) ;
2021
2122export class Tip extends Mark {
2223 constructor ( data , options = { } ) {
@@ -38,6 +39,7 @@ export class Tip extends Mark {
3839 lineWidth = 20 ,
3940 frameAnchor,
4041 textAnchor = "start" ,
42+ textOverflow,
4143 textPadding = 8 ,
4244 pointerSize = 12 ,
4345 pathFilter = "drop-shadow(0 3px 4px rgba(0,0,0,0.2))"
@@ -64,13 +66,16 @@ export class Tip extends Mark {
6466 this . pathFilter = string ( pathFilter ) ;
6567 this . lineHeight = + lineHeight ;
6668 this . lineWidth = + lineWidth ;
69+ this . textOverflow = maybeTextOverflow ( textOverflow ) ;
6770 this . monospace = ! ! monospace ;
6871 this . fontFamily = string ( fontFamily ) ;
6972 this . fontSize = number ( fontSize ) ;
7073 this . fontStyle = string ( fontStyle ) ;
7174 this . fontVariant = string ( fontVariant ) ;
7275 this . fontWeight = string ( fontWeight ) ;
7376 for ( const key in defaults ) if ( key in this . channels ) this [ key ] = defaults [ key ] ; // apply default even if channel
77+ this . splitLines = splitter ( this ) ;
78+ this . clipLine = clipper ( this ) ;
7479 }
7580 render ( index , scales , channels , dimensions , context ) {
7681 const mark = this ;
@@ -106,6 +111,13 @@ export class Tip extends Mark {
106111 const formatFy = fy && inferTickFormat ( fy ) ;
107112
108113 function * format ( sources , i ) {
114+ if ( "title" in sources ) {
115+ const text = sources . title . value [ i ] ;
116+ for ( const line of mark . splitLines ( formatDefault ( text ) ) ) {
117+ yield [ "" , mark . clipLine ( line ) ] ;
118+ }
119+ return ;
120+ }
109121 for ( const key in sources ) {
110122 if ( key === "x1" && "x2" in sources ) continue ;
111123 if ( key === "y1" && "y2" in sources ) continue ;
0 commit comments