Vega-lite: Line break or word wrap for labels in axis - word-wrap

I was trying to wrap the labels of x-axis on next line as the labels length is quite long. So is there any way to achieve it. I tried using calculate and labelExpr by breaking the label string and then concatenating them using '\n' but that doesn't seem to work.
Is there any other config which will help me achieve this use case or any workaround ?
You can refer the config here - vega-lite.

Newline characters in strings cannot be used to display line breaks. You can generate a line break in most Vega-Lite strings by instead passing a list of strings.
For your chart, you can generate line breaks using the split() operation in a calculate transform:
"transform": [{"calculate": "split(datum.address, ' ')", "as": "address"}],
The result looks like this (view in editor):

Related

How to separate numbers from text using SPLIT/LEFT/RIGHT function in Google Sheets

I have a google sheets documents with data in this format:
Some data 10:5 Somemore Data
I am trying to separate the text from the numbers in separate columns based on the colon sign so that the output looks like this:
Some data | 10 | 5 | Somemore Data
I tried the SPLIT and RIGHT/LEFT functions but I can't get it to work.
This is what I have so far
=LEFT(C2,FIND(":",C2)-3)
This separates the text on the LEFT but using it on the right side doesn't work. My formula also doesn't separate the numbers. Looking for a formula that can achieve the above desired result.
My spreadsheet - https://docs.google.com/spreadsheets/d/1EmL4kzCGxRbwvNJntwMokqgt8yjjAqnZuUidTbZe6Z8/edit?usp=sharing
Thanks.
There is already a solution in your shared sheet with SPLIT and REGEXREPLACE.
Here is one a bit simpler with REGEXEXTRACT:
=ARRAYFORMULA(IF(A2:A="", "", REGEXEXTRACT(A2:A,"^(.+?)[ ]+(\d+)[ ]*:[ ]*(\d+)[ ]+(.+)$")))
Every group will be a cell in a row to the right.
Regex description and demo: link.
Edit: stripped spaces. You have a nasty chars in your strings - nonbreaking space bar which is indistinguishable from the regular space. Could not understand why a simpler regex (^(.+?)\s+(\d+)\s*:\s*(\d+)\s+(.+)$) did not work. All because of this nbsp (char 160). Thus [ ] (nbsp and a regular space) instead of just \s.

Freemarker <compress> tag is trimming data inside ${} also

I have code like this :
FTL:
<#compress>
${doc["root/uniqCode"]}
</#compress>
Input is XML Nodemodel
The xml element is having data like: ID_234 567_89
When it is processed the out is: "ID_234 567_89"
The three white spaces between 234 and 567 is trimmed down to one white-space and lost all the white spaces at the end of the value.
I need the value as it is :"ID_234 567_89 "
When i removed the tags it works as expected irrespective of newFactory.setIgnoringElementContentWhitespace(true).
Why should tag trims data resulted from ${}?
Please help.
You could simply replace the characters you don't want manually (in the following example tabs, carriage returns and newlines), e.g.
${doc["root/uniqCode"]?replace("[\\t\\r\\n]", "", "rm")}
See ?replace built-in for strings: http://freemarker.org/docs/ref_builtins_string.html#ref_builtin_replace

Sort lines by html attribute in vim

I have a bunch of lines in a row that look like text and I want to reorder them into alphabetical order, using the alt attribute to sort. Is there a slick one or two lines of vimscript that I could use to get this? For concreteness, there are no line breaks in any of the entries and the relevant lines are 17-35.
You can use a regular expression as argument to the built-in :sort command:
:17,35sort /.*alt="\zs/

Using Ruby on a string, how can I slice between two parts of the string using RegEx?

I just want to save the text between two specific points in a string into a variable. The text would look like this:
..."content"=>"The text I want to save to a variable"}]...
I suppose I would have to use scan or slice, but not exactly sure how to pull out just the text without grabbing the RegEx identifiers before and after the text. I tried this, but it didn't work:
var = mystring.slice(/\"content\"\=\>\".\"/)
This should do the job
var = mystring[/"content"=>"(.*)"/, 1]
Note that:
.slice aliases []
none of the characters you escaped are special regexp characters where you're using them
you can "group" the bit you want to keep with ()
.slice / [] take a second parameter to pick a matched group
your_text = '"content"=>"The text I want to save to a variable"'
/"content"=>"(?<hooray>.*)"/ =~ your_text
Afterwards, hooray local variable will be magically set to contain your text. Can be used to set multiple variables.
This regex will match your string:
/\"content\"=>\"(.*)\"/
you can try rubular.com for testing
It looks like you're trying to truncate a sentence. You can split the sentence either on punctuation, or even on words.
mystring.split(".")
mystring.split("word")

Block Indent Regex

I'm having problems about a regexp.
I'm trying to implement a regex to select just the tab indent blocks, but i cant find a way of make it work:
Example:
INDENT(1)
INDENT(2)
CONTENT(a)
CONTENT(b)
INDENT(3)
CONTENT(c)
So I need blocks like:
INDENT(2)
CONTENT(a)
CONTENT(b)
AND
INDENT(3)
CONTENT(c)
How I can do this?
really tks, its almost that, here is my original need:
table
tr
td
"joao"
"joao"
td
"marcos"
I need separated "td" blocks, could i adapt your example to that?
It depends on exactly what you are trying to do, but maybe something like this:
^(\t+)(\S.*)\n(?:\1\t.*\n)*
Working example: http://www.rubular.com/r/qj3WSWK9JR
The pattern searches for:
^(\t+)(\S.*)\n - a line that begins with a tab (I've also captured the first line in a group, just to see the effect), followed by
(?:\1\t.*\n)* - lines with more tabs.
Similarly, you can use ^( +)(\S.*)\n(?:\1 .*\n)* for spaces (example). Mixing spaces and tabs may be a little problematic though.
For the updated question, consider using ^(\t{2,})(\S.*)\n(?:\1\t.*\n)*, for at least 2 tabs at the beginning of the line.
You could use the following regex to get the groups...
[^\s]*.*\r\n(?:\s+.*\r*\n*)*
this requires that your lines not begin with white space for the beginning of the blocks.

Resources