allowHtml in setCell google charts table visualization - google-visualization

Please explain this: setCell(rowIndex, columnIndex [, value [, formattedValue [, properties]]])
I want to allowHtml in table cell values.
My version of setcell is
data.setCell(0, 0, facebook.video_title, '<a href=' + "http://www.facebook.com/" + facebook.video_id + '>' + facebook.video_title + '</a>');
My aim is to open a video link on click of video title. So I am putting an a tag there. And I am calling the draw method like this: google.charts.setOnLoadCallback(drawTable(story_data, {allowHtml:true}));
By running this sample, I am getting whole HTML tag syntax as it is in my visualized table.

hard to say without seeing drawTable
but I don't think the arguments are being passed properly, try it like this...
google.charts.setOnLoadCallback(function () {
drawTable(story_data, {allowHtml:true});
});

Related

How can I identify tags that do not have CSS selectors with Html.Table?

I am writing a query for work for a report that has some poorly written HTML code where only some of the tags have a CSS selector I can use for creating my columns but others don't. (Guess who wrote it?) I wrote some workarounds using nth-child and describing each step to the desired tab but, as expected, when scaled up to all the other reports it causes issues because not every table is alike with what it contains.
My working code:
{"Rule ID", "td[class='rule-id']"}
However the next column I used this:
{"Time", "div[class='panel-body'] > TABLE > TBODY > TR:nth-child(6) > TD:nth-child(2)"}
Which in some of the tables does grab the time, but in others it grabs the wrong tag. I'm wondering if there's a way I can refer to the information in-between the tags. The time code looks like this:
<table>
...
<tr>
<td>Time</td>
<td>2022-04-28T10:01:15+00:00</td>
</tr>
...
</table>
I tried this but it results in a 100% empty column:
{"Time", "td[contains='Time']"}
This is my first project in Power BI so I'm learning as I go and have found answers to most of my questions through Google but I couldn't quite phrase this question properly to find a good result. All of the code is on my GFE so I can't get it over here to share, hopefully the bits I could share are enough.
Thank you in advance for your help!
If you link the site I can give a better answer.
There's an optional 3rd parameter, that gives you more access to attributes.
{"Name", "Selector"} would become {"Name", "Selector", each _ }, ex:
= Html.Table(Source,
{
{"Name", "Selector", each _ }
}
)
selector
td[contains='Time']
This isn't looking for what your html, it would match this. Here's a good reference/cheatsheet
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors
<td contains='Time'>
Testing Selectors in a browser
In the web console, you can use a CSS Selector query to preview what it will select.
Firefox has shorthand using the function $ and $$ . otherwise use document.querySelector() and document.querySelectorAll()
Your RowSelector
If you were to use $$("TABLE.table > * > TR") as your RowSelector
Your columnNameSelectorPairs
And then TABLE.table > * > TR > :nth-child(1)
From:
ninmonkeys.com/Select_Tables_using_your_own_CSS_Selectors
https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

How to extract a column based on it's content in PowerBI

I have a column in my table which looks like below.
ResourceIdentifier
------------------
arn:aws:ec2:us-east-1:7XXXXXX1:instance/i-09TYTYTY79716
arn:aws:glue:us-east-1:5XXXXXX85:devEndpoint/etl-endpoint
i-075656565f7fea3
i-02c3434343f22
qa-271111145-us-east-1-raw
prod-95756565631-us-east-1-raw
prod-957454551631-us-east-1-isin-repository
i-02XXXXXXf0
I want a new column called 'Trimmed Resource Identifier' which looks at ResourceIdentifier and if the value starts with "arn", then returns value after last "/", else returns the whole string.
For eg.
arn:aws:ec2:us-east-1:7XXXXXX1:instance/i-09TYTYTY79716  ---> i-09TYTYTY797168
i-02XXXXXXf0 --> i-02XXXXXXf0
How do I do this ? I tried creating a new column called "first 3 letters" by extracting first 3 letters of the ResourceIdentifier column but I am getting stuck at the step of adding conditional column. Please see the image below.
Is there a way I can do all of this in one step using DAX instead of creating a new intermediate column ?
Many Thanks
The GUI is too simple to do exactly what you want but go ahead and use it to create the next step, which we can then modify to work properly.
Filling out the GUI like this
will produce a line of code that looks like this (turn on the Formula Bar under the View tab in the query editor if you don't see this formula).
= Table.AddColumn(#"Name of Previous Step Here", "Custom",
each if Text.StartsWith([ResourceIdentifier], "arn") then "output" else [ResourceIdentifier])
The first three letters bit is already handled with the operator I chose, so all that remains is to change the "output" placeholder to what we actually want. There's a handy Text.AfterDelimiter function we can use for this.
Text.AfterDelimiter([ResourceIdentifier], "/", {0, RelativePosition.FromEnd})
This tells it to take the text after the first / (starting from the end). Replace "output" with this expression and you should be good to go.

Regex (re2 googlesheets) multiple values in multiline cell

Getting stuck on how to read and pretty up these values from a multiline cell via arrayformula.
Im using regex as preceding line can vary.
just formulas please, no custom code
The first column looks like a set of these:
```
[config]
name = the_name
texture = blah.dds
cost = 1000
[effect0]
value = 1000
type = ATTR_A
[effect1]
value = 8
type = ATTR_B
[feature0]
name = feature_blah
[components]
0 = comp_one,1
[resources]
res_one = 1
res_five = 1
res_four = 1
<br/>
Where to be useful elsewhere, at minimum it needs each [tag] set ([effect\d], [feature\d], ect) to be in one column each, for example the 'effects' column would look like:
ATTR_A:1000,ATTR_B:8
and so on.
Desired output can also be seen in the included spreadsheet
<br/>
<b>Here is the example spreadsheet:</b>
https://docs.google.com/spreadsheets/d/1arMaaT56S_STTvRr2OxCINTyF-VvZ95Pm3mljju8Cxw/edit?usp=sharing
**Current REGEXREPLACE**
Kinda works, finds each 'type' and 'value' great, just cant figure out how to extract just that from the rest, tried capture (and non-capturing) groups before and after but didnt work
=ARRAYFORMULA(REGEXREPLACE($A3:$A,"[\n.][effect\d][\n.](.)\n(.)","1:$1 2:$2"))
**Current SUBSTITUTE + REGEXEXTRACT + REGEXREPLACE**
A different approach entirely, also kinda works, longer form though and left with having to parse the values out of that string, where got stuck again. Idea was to use this to simplify, then regexreplace like above. Getting stuck removing content around the final matches though, and if can do that then above approach is fine too.
// First ran a substitute
=ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE($A3:$A,char(10),";"),";;",char(10)))
// Then variation of this (gave up on single line 'effect/d' so broke it up to try and get it working)
=ARRAYFORMULA(IF(A3:A<>"",IFERROR(REGEXEXTRACT(A3:A,"(?m)^(?:[effect0]);(.)$")&";;")&""&IFERROR(REGEXEXTRACT(A3:A,"(?m)^(?:[effect1]);(.)$")&";;")&""&IFERROR(REGEXEXTRACT(A3:A,"(?m)^(?:[effect2]);(.)$")&";;"),""))
// Then use regexreplace like above
=ARRAYFORMULA(REGEXREPLACE($B3:$B,"value = (.);type = (.);;","1:$1 2:$2"))
**--EDIT--**
Also, as my updated 'Desired Output' sheet shows (see timestamped comment below), bonus kudos if you can also extract just the values of matching 'type's to those extra columns (see spreadsheet).
All good if you cant though, just realized would need that too for lookups.
**--END OF EDIT--**
<br/>
Ive tried dozens of things, discarding each in turn, had a quick look in version history to grab out two promising attempts and shared them in separate sheets.
One of these also used SUBSTITUTE to simplify input column, im happy for a solution using either RAW or the SUBSTITUTE results.
<br/>
**Potentially Useful links:**
https://github.com/google/re2/wiki/Syntax
<br/>
<b>Just some more words:</b>
I also have looked at dozens of stackoverflow and google support pages, so tried both REGEXEXTRACT and REGEXREPLACE, both promising but missing that final tweak. And i tried dozens of tweaks already on both.
Any help would be great, and hopefully help others in future since examples with spreadsheets are great since every new REGEX seems to be a new adventure ;)
<br/>
P.S. if we can think of better title for OP, please say in comment or your answer :)
paste in B3:
=ARRAYFORMULA(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
IF(C3:E<>"", C2:E2&":"&C3:E, )),,999^99))), " ", ", "))
paste in C3:
=ARRAYFORMULA(IFNA(REGEXEXTRACT($A3:$A, "(\d+)\ntype = "&C2)))
paste in D3:
=ARRAYFORMULA(IFNA(REGEXEXTRACT($A3:$A, "(\d+)\ntype = "&D2)))
paste in E3:
=ARRAYFORMULA(IFNA(REGEXEXTRACT($A3:$A, "(\d+)\ntype = "&E2)))
paste in F3:
=ARRAYFORMULA(IFNA(REGEXEXTRACT(A3:A, "\[feature\d+\]\nname = (.*)")))
paste in G3:
=ARRAYFORMULA(IFNA(REGEXEXTRACT(A3:A, "\[components\]\n\d+ = (.*)")))
paste in H3:
=ARRAYFORMULA(IFNA(REGEXREPLACE(INDEX(SPLIT(REGEXEXTRACT(
REGEXREPLACE(A3:A, "\n", ", "), "\[resources\], (.*)"), "["),,1), ", , $", )))
spreadsheet demo
This was a fun exercise. :-)
Caveat first: I have added some "input data". Examples:
[feature1]
name = feature_active_spoiler2
[components]
0 = spoiler,1
1 = spoilerA, 2
So the output has "extra" output.
See the tab ADW's Solution.

web browser innertext data how received in textbox?

I have posted my HTML below. In which I want to get the name value from within my textbox area. I've tried several processes and I'm still not getting any valid solution. Please check my HTML and code snippet, and show me a possible solution.
The name prefix will always stay the same when I refresh the page. However, the last name within the "name" area will change, but will always contain the literal "mr." as the first 3 digits. regex as ([mM]r.\ ) - Four digits if you consider the literal space. Below is my table example.
<table>
<tr><td><b>Your Name is </b> mr. kamrul</td></tr>
<tr><td><b>your age </b> 12</td></tr>
<tr><td><b>Email:</b>kennethdasma30#gmail.com</td></tr>
<tr><td><b>job title</b> sales man</td></tr>
</table>
As shown below I am trying this process using listbox but I am not receiving anything.
HtmlElementCollection bColl =
webBrowser1.Document.GetElementsByTagName("table");
foreach (HtmlElement bEl in bColl)
{
if (bEl.GetAttribute("table") != null)
{
listBox1.Items.Add(bEl.GetAttribute("table"));
}
}
If anyone ca give me an idea of how I am able to receive all in the browser window as ("mr. " + text) within my list box I would appreciate it. Also, if you can explain the answer verbosely and with good comments I would appreciate it, as I'd like to understand the answer in greater detail as well.
Here is one simple way using Regex, assuming that the format of your html page doesn't change.
Regex re = new Regex(#"(?<=<tr><td><b>Your\sName\sis\s?</b>\s?)[mM]r\.\s.+?(?=</td></tr>)", RegexOptions.Singleline);
foreach (Match match in re.Matches(webBrowser1.DocumentText))
{
listBox1.Items.Add(match.Value);
}

Calculated text column for Google Line Chart x-axis not working

Changing my Line Chart's x-axis labels from one bit of text to another bit of text isn't working; what am I doing wrong, please?
I have a Line Chart whose discrete x-axis is labeled with text representations of the date.
(I'm using corechart; I've created a dataTable, created a dataView based off of that, and have created the chart as a ChartWrapper).
I'm filtering the dataView based on the textual date, so my initial x-axis domain values are in the format 2013-09-01... and that works. But now I need to change the x-axis labels to the format 9/2013. The examples I've found on this seem clear, but the chart isn't drawn but is replaced by an error: "c is null". Googling that, the problem sounds like my domain column is the wrong data type, but I don't see how that's possible.
Can you please point out my error? Below, I've gotten the list of columns that I need displayed; that would be a list like [0,3,5] where 0 is the domain column. I remove it first so I can set the new, formatted column:
// Format the x-axis as n/Y
// remove unformatted column 0;
view_col_list.splice(0, 1);
data_displayed.setColumns([
{
role: 'domain',
calc: function(dataTable, row) {
var my_date = new Date(dataTable.getValue(row, 0));
console.info('the date I want to format: %o',my_date);
// this does in fact produce "9/2013"
console.info('the date I want to show' + my_date.getMonth() + '/' + my_date.getFullYear());
return my_date.getMonth() + '/' + my_date.getFullYear();
},
type: 'string',
sourceColumn: 0,
id: 0
},
view_col_list
]);
I would guess that your dates are probably not the problem, but there are a few things I would recommend changing with them: remove the "sourceColumn" attribute, as it isn't needed; and change the way you are constructing your new date string, as converting a string to a Date object is inconsistent across browsers. Also, the #getMonth method returns the 0-indexed month, so "2013-09-01" would get turned into "8/2013" in your code (assuming the date string conversion works). There is an easier way that doesn't involve converting to Date objects and back into strings:
var dateArray = dataTable.getValue(row, 0).split('-');
return dateArray[1] + '/' + dateArray[0];
I suspect the problem is caused by this:
view_col_list.splice(0, 1);
data_displayed.setColumns([{...}, view_col_list]);
which is equivalent to data_displayed.setColumns([{...}, [...]]); which definitely won't work. Rather than splice the first element from the view_col_list, replace it with your object:
view_col_list[0] = {...};
data_displayed.setColumns(view_col_list);