How to get a line break in text

1,236 views
Skip to first unread message

Clare Churcher

unread,
May 4, 2017, 6:45:05 PM5/4/17
to vega-js
Sorry if this is a very basic question.

When I click on a point on a graph (see below) I want to display the details.
I'd like to separate out the data onto different lines but am having trouble entering a line break. 

I set up the text as a transform

"type": "formula",
 "as": "detail",
  "expr": "'Date:  '+timeFormat(datum.day,'%e-%b-%y') + ' \\n Score: ' + round(datum.average_sp * 10)/10 "

Thanks '
Clare


Roy I

unread,
May 5, 2017, 11:12:27 AM5/5/17
to vega-js
Vega v3 (3.0.0 beta 30) text mark does not support multiline text or word wrap, but this example shows how to create a multiline tooltip by using a group mark containing text marks (one text mark for each line in the tooltip):

jh...@trifacta.com

unread,
May 5, 2017, 11:14:26 AM5/5/17
to vega-js
Hi Clare!

Vega does not currently support line breaks within text marks, in part because neither SVG nor Canvas support it "natively" (i.e., it requires additional SVG markup or custom text layout in the case of Canvas). The current solution is to either (a) use multiple text marks, one for each line or (b) use HTML-based tooltips, for example by using a plug-in like vega-tooltip (https://github.com/vega/vega-tooltip).

cheers,
-jeff

Roy I

unread,
May 5, 2017, 4:25:01 PM5/5/17
to vega-js
Hi Jeff, A couple of questions:

1. Does vega-tooltip work with Vega v3?  The documenation appears to be for Vega v2 only and the script url links do not work:



2. Could word wrap shown in this D3 example be incorporated into Vega?

Thanks, Roy



On Thursday, May 4, 2017 at 6:45:05 PM UTC-4, Clare Churcher wrote:
Message has been deleted

Sira Horradarn

unread,
May 5, 2017, 6:14:49 PM5/5/17
to vega-js
Hi Roy,

We just updated vega-tooltip to support both vega 3.0 and vega-lite 2.0. I just updated the docs to reflect new changes in API that we introduced and sorry for any inconvenience this might cause. 

Best,
Sira

Clare Churcher

unread,
May 7, 2017, 6:06:39 PM5/7/17
to vega-js
Thank you all for the feedback and suggestions

Cheers
Clare
 
Reply all
Reply to author
Forward
0 new messages