Working example to custom-format a column title/header? - tabulator

I have a formatter that works for column data, using column parameter formatter. Using the same formatter with column parameter titleformatter, I get the error noted below. Also, I don't understand why HTML in title parameter text seems not to work for <b> ... </b> but does work for other things (e.g., <i> ... </i>. A working custom formatter example would help. (I don't see this in Tabulator documentation.) See this montage combining a column header and row header screenshot with common cell text---'bold' in the row looks bolder to me.
Cell text comparison screenshot montage
I've tried emulating some posted sample code, but I get the same error as reported by #dagroj in his comment to #Oli Folkerd's answer (to the question) about titleformatter --- viz. tabulator.min.js:2 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. (Mentioning that here because I don't yet have the reputation to comment there.)
Here is a rendering of my CPT, without the titleformatter.
Corresponding table constructor:
"columnVertAlign": "bottom",
"height": "100%",
"layout": "fitColumns",
"columns": [
{
"title": "<i> absolute_T<--T (noisyAnd)</i>",
"columns": [
{
"title": "<b> NotCorrAnd_EffectiveHyp</b>",
"field": "label",
"align": "right",
"headerSort": false
}
]
},
{
"title": "NotB_EffectiveHyp",
"columns": [
{
"title": "<b>T</B>",
"field": "true",
"align": "center",
"headerSort": false
},
{
"title": "<i>F</i>",
"field": "false",
"align": "center",
"headerSort": false
}
]
},
{
"title": "<b> Belief </b>",
"columns": [
{
"title": "odds",
"field": "odds",
"align": "center",
"headerSort": false
},
{
"title": "log<sub>2</sub> odds",
"field": "log2odds",
"align": "center",
"headerSort": false
}
]
}
]
}
Formatter:
function truthFormatter(cell, formatterParams, onRendered) {
var cellValue = cell.getValue();
var cellElement = cell.getElement();
if (cellValue == "T") {
cellElement.style.backgroundColor = "#0000B3";
cellElement.style.color = "#FFFFFF";
cellElement.style.textAlign = "center";
cellElement.style.fontWeight = "bold";
}
else if (cellValue == "F") {
cellElement.style.backgroundColor = "#B30000";
cellElement.style.color = "#FFFFFF";
cellElement.style.textAlign = "center";
cellElement.style.fontWeight = "bold";
}
else cellElement.style.color = "#000000";
return cell.getValue();
}

Column headers are by default styled to be bold, so adding a bold or strong tag will not make them any bolder. On a side not you are using a mix of lowercase and uppercase "b" in your tags
If you are getting that error it means that your formatter is not returning a valid value, it must either be a string/number or a DOM element of type Node.

Related

Syntax for JSONPath filtering to not return array

I'm new to JSONPath and want to write a JSONPath-syntax that retrieves the property value only if a certain condition is met. The value I'm after is not part of an array, but I've managed to make filtering work in the following JSONPath tool: https://www.site24x7.com/tools/json-path-evaluator.html
Given the following JSON, I only want to extract the value of column2.dimValue if column2.attributeId equals B0:
{
"batchId": 279,
"companyId": "40",
"period": 202208,
"taxCode": "1",
"taxSystem": "",
"transactionDate": "2022-08-05T00:00:00.000",
"transactionNumber": 222006089,
"transactionType": "IF",
"year": 2022,
"accountingInformation": {
"account": "4010",
"column1": {
"attributeId": "H9",
"dimValue": "76"
},
"column2": {
"attributeId": "B0",
"dimValue": "2170103"
},
"column3": {
"attributeId": "",
"dimValue": ""
},
"column4": {
"attributeId": "BF",
"dimValue": "217010330"
},
"column5": {
"attributeId": "10",
"dimValue": "3101"
},
"column6": {
"attributeId": "06",
"dimValue": ""
},
"column7": {
"attributeId": "19",
"dimValue": "K"
}
},
"categories": {
"cat1": "H9",
"cat2": "B0",
"cat3": "",
"cat4": "BF",
"cat5": "10",
"cat6": "06",
"cat7": "19",
"dim1": "76",
"dim2": "2170103",
"dim3": "",
"dim4": "217010330",
"dim5": "3101",
"dim6": "",
"dim7": "K"
},
"amounts": {
"amount": 48.24,
"amount3": 0.0,
"amount4": 0.0,
"currencyAmount": 48.24,
"currencyCode": "NOK",
"debitCreditFlag": 1
},
"invoice": {
"customerOrSupplierId": "58118",
"description": "",
"externalArchiveReference": "",
"externalReference": "2170103",
"invoiceNumber": "220238522",
"ledgerType": "P"
},
"additionalInformation": {
"number": 0,
"orderLineNumber": 0,
"orderNumber": 0,
"sequenceNumber": 1,
"status": "",
"value": 0.0,
"valueDate": "2022-08-05T00:00:00.000"
},
"lastUpdated": {
"updatedAt": "2022-09-05T10:59:11.633",
"updatedBy": "HELVES"
}
}
I've used this JSONPath-syntax:
$['accountingInformation']['column2'][?(#.attributeId=='B0')].dimValue
This gives the following result:
[
"2170103"
]
I'm using this result in Azure Data Factory mapping, and it seems that it doesn't work as the result is an array.
Can anyone help me with the syntax to it only returns the actual value? Is that even possible?
I repro'd the same and below is the approach.
Sample Json file is taken as in below image as a source in lookup activity.
If activity is taken to filter the value of column2 with attributeId='B0'. Expression is given as below
#equals(activity('Lookup1').output.value[0].accountingInformation.column2.attributeId ,'B0')
In true case of IF activity, Set Variable is added. New Variable with string type is taken and it is set using below expression.
#activity('Lookup1').output.value[0].accountingInformation.column2.dimvalue
Then Copy activity is added next to IF activity sequentially. In source dummy dataset is taken. +New is click in additional columns
Name: col1
Value: #variables('v2')
In Mapping, Import schemas is clicked. All other columns except the additional column that is added in source are deleted.
Pipeline is debugged and data is copied to sink without error.

Can't get transform_filter to work in Altair

For my teaching notes I am trying to implement this vega-lite example in Altair:
{
"data": {"url": "data/seattle-weather.csv"},
"layer": [{
"params": [{
"name": "brush",
"select": {"type": "interval", "encodings": ["x"]}
}],
"mark": "bar",
"encoding": {
"x": {
"timeUnit": "month",
"field": "date",
"type": "ordinal"
},
"y": {
"aggregate": "mean",
"field": "precipitation",
"type": "quantitative"
},
"opacity": {
"condition": {
"param": "brush", "value": 1
},
"value": 0.7
}
}
}, {
"transform": [{
"filter": {"param": "brush"}
}],
"mark": "rule",
"encoding": {
"y": {
"aggregate": "mean",
"field": "precipitation",
"type": "quantitative"
},
"color": {"value": "firebrick"},
"size": {"value": 3}
}
}]
}
I getting the separate charts (bar and rule to work) was easy, but I run into issues in making mark_rule interactive.
import altair as alt
from vega_datasets import data
df = data.seattle_weather()
selection = alt.selection_interval(encodings=['x'])
base = alt.Chart(df).add_selection(selection)
bar_i = base.mark_bar().encode(
x="month(date):T",
y="mean(precipitation):Q",
opacity=alt.condition(selection, alt.value(1.0), alt.value(0.7)))
rule_i = base.mark_rule().transform_filter(selection).encode(y="mean(precipitation):Q")
(bar_i + rule_i).properties(width=600)
The error reads
Javascript Error: Duplicate signal name: "selector013_scale_trigger"
This usually means there's a typo in your chart specification. See the javascript console for the full traceback.
It looks like the chart you're interested in creating is part of Altair's example gallery: https://altair-viz.github.io/gallery/selection_layer_bar_month.html
import altair as alt
from vega_datasets import data
source = data.seattle_weather()
brush = alt.selection(type='interval', encodings=['x'])
bars = alt.Chart(source).mark_bar().encode(
x='month(date):O',
y='mean(precipitation):Q',
opacity=alt.condition(brush, alt.OpacityValue(1), alt.OpacityValue(0.7)),
).add_selection(
brush
)
line = alt.Chart(source).mark_rule(color='firebrick').encode(
y='mean(precipitation):Q',
size=alt.SizeValue(3)
).transform_filter(
brush
)
bars + line
The error you're seeing comes from the fact that base includes the selection, and both layers are derived from base, so the same selection is declared twice within the single chart.

Using requests, how to iterate dictions to get data

DATA to be search through:
{
"epicUserHandle": "HaaZeeY",
"stats": {
"p2": {
"trnRating": {
"label": "TRN Rating",
"field": "TRNRating",
"category": "Rating",
"valueInt": 1193,
"value": "1193",
"rank": 3210238,
"percentile": 56.0,
"displayValue": "1,193"
},
"top1": {
"label": "Wins",
"field": "Top1",
"category": "Tops",
"valueInt": 46,
"value": "46",
"rank": 15163718,
"percentile": 0.8,
"displayValue": "46"
},
My code:
url = "https://api.fortnitetracker.com/v1/profile/{}/{}".format(platform,
username)
headers = {'TRN-Api-Key' : 'MY API KEY'}
r = requests.get(url, headers=headers)
#p2 = Solo
#p10 = Duo
#p9 = Squad
tempory_dict = {}
result = r.json()['stats']['p2']['top1']
for r in result:
#WHAT DO I PUT HERE
tempory_dict['Wins'] = #VALUE
print(tempory_dict['Wins'])
What do I need to do here? I want it to find the "value" and save that in the tempory_dict['Wins']. I'm new to requests and not sure how to iterate through it all to find value.
Thanks.
You are almost there actually, having:
result = r.json()['stats']['p2']['top1'], you actually assign
{
"label": "Wins",
"field": "Top1",
"category": "Tops",
"valueInt": 46,
"value": "46",
"rank": 15163718,
"percentile": 0.8,
"displayValue": "46"
}
to result variable, so all you need to do is just go one step further and assign:
tempory_dict['Wins'] = result['value']

angular formly hide expression

{
"wrapper": "section",
"className": "row",
"hideExpression":"function($viewValue, $modelValue, scope){ return (scope.model['Application__c']['Years1__c'] && (parseFloat(scope.model['Application__c']['Years1__c']+'x.'+scope.model['Application__c']['Months1__c'])+parseFloat(scope.model['Application__c']['Years__c']+'.'+scope.model['Application__c']['Months__c']))>2); }" ,
"fieldGroup": [ {
"key": "Application__c.City_Prev1__c",
"type": "alphabet",
"hideExpression":"function($viewValue, $modelValue, scope){ return !scope.model['Application__c']['Years1__c'] }" ,
"className": "col-xs-7 col-sm-6 col-md-5 col-lg-5",
"templateOptions": {
"label": "City",
"required": true,
"maxlength": 20,
"objectName": "Application__c",
"fieldName": "City_Prev1__c"
}
}]
}
In the above formly json, how can make hide expression as a function or how can I call a function from outside
Please refer the link below
**Function constructor **
The Function constructor creates a new Function object. Calling the constructor directly can create functions dynamically, but suffers from security and performance issues similar to eval.

node.js jade - Unable to access nested array elements

Sorry if this is a really basic question, but I cannot find any examples similar to the issue I am trying to solve.
Can somebody please explain why I am not able to access a nested array of elements in the following code and also how I can access elements from that array? From the json below, I am not able to get at the "Items" array found from the second result on.
The following json is being returned:
{
"d": {
"results": [
{
"__metadata": {
"uri": "...",
"type": "..."
},
"__index": 1,
"ID": "someID1",
"Name": "Some Name 1"
},
{
"__index": 2,
"Items": [
{
"__metadata": {
"uri": "...",
"type": "..."
},
"ID": "itemID2_1",
"Name": "Item 2_1"
}
]
},
{
"__index": 3,
"Items": [
{
"__metadata": {
"uri": "...",
"type": "..."
},
"ID": "itemID3_1",
"Name": "Item 3_1"
}
]
},
...
Here is the jade layout:
- var results=records, col_type='even';
table#results(style="border-collapse:collapse;")
tr
th.result-header Index
th.result-header ID
th.result-header Name
- each r in results
- col_type=col_type=='even' ? 'odd' : 'even'
tr.result-row
- if (!r.Items)
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.__index}
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.ID}
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.Name}
- else
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.__index}
- each i in r.Items
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{i.ID}
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{i.Name}
The issue here is that your JSON is in this format
{
"d": {
"results": [
...
]
So you need to change this part in your jade template from
- each r in results
- col_type=col_type=='even' ? 'odd' : 'even'
to this,
- each r in results['d']['results']
- col_type=col_type=='even' ? 'odd' : 'even'
This way, your loop will be pass through each array item.
so I just ran across the same problem. My solution was to do:
- each r in results
- each i in r.Items
"... do stuff with i"

Resources