Vega text mark renders "undefined" when not hovering - vega

I'm trying to create a simple bar chart using Vega on the Vega editor.
To re-create my issue, navigate to this bar chart example on vega site, and try to change the text property of the text mark as follows:
Original: "text": {"signal": "tooltip.amount"},
Modify to: "text": {"signal": "tooltip.amount + ' + ' + tooltip.category"},
This leads to undefined + undefined displayed on the top left corner of the chart when no hover event occurs. How do I get around this issue to make sure its not displayed? (issue depicted below)
I think this is something to do with how the scales and the text mark are functioning, but I was not able to figure out the solution. Tried adding a default value in mouse hover events by setting category to null and testing it while configuring mark opacity, but it didn't work. Code for this (only specifying updates to the raw example on site):
"signals": [
{
"name": "tooltip",
"value": {"category":null},
"on": [
{"events": "rect:mouseover", "update": "datum"},
{"events": "rect:mouseout", "update": "{'category':null}"}
]
}
],
...
"marks": [
...
{
"type": "text",
"encode": {
...
"update": {
"text": {"signal": "tooltip.amount + ' + ' tooltip.category"},
"fillOpacity": [
{"test": "datum === tooltip && tooltip.category!=null", "value": 0},
{"value": 1}
]
}
}
}

Thanks to a friend for helping me with the answer:
"text": [
{
"signal": "tooltip.amount + ' + ' + tooltip.category",
"test": "tooltip.amount"
},
{"value": ""}
],
The issue was when you hover out the tooltip object does not have a value
since we are concatenating the values with the ' + ' string. The undefined object is coerced to the 'undefined' string.
Updating the string value to an empty string again is what is required.

Related

VEGA Sunburst highlight current node and parent path

I am trying to highlight node and all linked parents when we hover with a mouse.
So I ask VEGA : " is my datum.currentNode of my arc mark a parent of my currently hovered node ?"
{
"name": "hoveredArcDetail",
"on": [
{"trigger": "hoveredArcIn", "toggle": "hoveredArcIn"},
{"trigger": "hoveredText", "toggle": "hoveredText"}
],
"transform": [
{"type": "flatten", "fields": ["myTreeAncestorList"]},
{
"type": "formula",
"expr": "datum.myTreeAncestorList.currentNodeAndAncestors",
"as": "nodeToCheckIfParentOfCurrentNode"
}
]
},
"fillOpacity": [
{
"test": "indata('hoveredTextDetail','nodeToCheckIfParentOfCurrentNode',datum.currentNodeAndAncestors)||indata('hoveredArcDetail','nodeToCheckIfParentOfCurrentNode',datum.currentNodeAndAncestors)",
"value": 1
},
{
"test": "((isHoveredOnArc==true)||(isHoveredOnText==true))&&!indata('hoveredArcDetail','nodeToCheckIfParentOfCurrentNode',datum.currentNodeAndAncestors)",
"value": 0.5
}
]
Yet the problem is that, when my toggle trigger empties my data when we don't hoover, my transform flatten and formula throws me an error ( as expected ) saying that we cant find such data.
Does anyone have an idea to handle this error ? Thank you !
Full spec is available here
https://vega.github.io/editor/#/gist/ab2b39162b7c3240aa2cbe84d42aa6fb/spec.json
The issue has been solved by setting interactivity for text mark as false:
{
"type": "text",
"from": {
"data": "nodeLabels"
},
"interactive":false

How to position fields in Pandadoc

I need to use Pandadoc to upload a document (PDF) and sign it.
I'm able to upload the document with values binded from my backend, but I can't find a way to position the signature boxes in the layout.
Is there a way to do it without the Pandadoc web editor? All I see in the documentation is:
"fields": {
"name": {
"value": "John",
"role": "user"
},
"like": {
"value": true,
"role": "user"
}
},
Thanks!

Microsoft adaptive card choiceset iteration

i have a adaptive card choice set like below, as you can see am trying to get the value under title from a variable which is an array, is there a way i can iterate the choice set automatically because i don't know how many values the array has i want to show all the values inside the array in the choice set title
{
"type" : "Input.ChoiceSet",
"isMultiSelect": true,
"id": "myColor",
"style": "compact",
"value": "1",
"choices": [
{
"title": vars.responsedata.items[0].topic,
"value": "1"
},
{
"title": vars.responsedata.items[1].topic,
"value": "2"
},
{
"title": "Recording 3 sample",
"value": "3"
}
]
}
You can use the map() function.
Example in DataWeave:
{
choices: vars.responsedata.items map {
title: $.topic,
value: $$
}
}

Access scale value in Vega

I have a simple scale like this:
{
"name": "x",
"type": "linear",
"nice": true,
"zero": true,
"domain": {
"data": "source",
"field": "x"
},
"range": {
"signal": "x_range"
}
}
How can I access the x-position for a value inside the domain?
I guessed I can do something like scale('x')(10) but that doesn't work.
I know normally one can use scale and value to achieve the most but I would like to compute something based on the pixel value.
Answering myself:
Usage: scale('x', 10)
Documentation: https://vega.github.io/vega/docs/expressions/#scale

data.tables is empty - community visualization in DataStudio

I'm trying to draw custom graph with Google DataStudio community visualization and BigQuery source.
But even if data is exist and valid(check with other basic chart), input data of my drawViz function is empty.
See below Javascript code:
function drawViz(data) {
let rowData = data.tables.DEFAULT;
var metricName = data.fields['barMetric'][0].name;
var dimensionName = data.fields['barDimension'][0].name;
title = metricName + ' by ' + dimensionName + '2';
console.log(rowData , title )
}
Console output:
> {DEFAULT : Array(0)} "my metrics by my dimension"
Is there any restriction using community visualization functionality with bigquery?
Or need any additional setting except in codelab (https://codelabs.developers.google.com/codelabs/community-visualization/#0) ?
** update
manifest.json : https://storage.googleapis.com/vd-qoe-bucket/test/manifest.json
myViz.json : https://storage.googleapis.com/vd-qoe-bucket/test/myViz.json
From your links:
The "data" part of your config appears to be invalid:
"data": [
{
"id": "concepts",
"label": "Concepts",
"elements": [ // setting metric and dimension counts
{
"id": "barDimension",
"label": "Dimension",
"type": "DIMENSION",
"options": {
"min": 1,
"max": 2
}
},
{
"id": "barMetric",
"label": "Metric",
"type": "METRIC",
"options": {
"min": 1,
"max": 2
}
}
]
}
]
Removing the comment // setting dimensions... should work.