Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying String Values #5

Open
ajaywazir opened this issue May 6, 2020 · 13 comments
Open

Displaying String Values #5

ajaywazir opened this issue May 6, 2020 · 13 comments

Comments

@ajaywazir
Copy link

Hi
I am using Scadavis Synoptic IO panel in Grafana.
I want display some string values but unable to do so using %s.
How to write string values e.g serial number that is read from database

Ajay

@riclolsen
Copy link
Owner

riclolsen commented May 6, 2020

Hi Ajay,
Currently (v.1.0.4), the plugin can only obtain numeric data from Grafana time series.
I intend to support String values in some future version.
Best regards
Ricardo

@ajaywazir
Copy link
Author

Thanks

@ajaywazir
Copy link
Author

Hi
GET property of a text element is set to TAG '%q'
How to retrieve the tag value in Scripts
I want to run some calculation on the tag value before presenting it on UI.
Regards
Ajay

@riclolsen
Copy link
Owner

Hi Ajay, you can use the !EVAL trick in place of a tag.
!EVAL expression
Evaluates a Javascript expression (use $V("TAG") to obtain tag values in the expression).
Example, to obtain the square of TAG1 value, use in the Get|TAG or in the Group Faceplate|Value
!EVAL $V("TAG1")*$V("TAG1")

@ajaywazir
Copy link
Author

Hi,
I am not sure I get you clearly.
I think I need to be a bit clear on what I need to achieve.
Since you are not able to render string TAG values, I need to send numeric values and manipulate in SCRIPTS using pure JavaSCript like this:
var _tag_value = numeric_tag_value; //how to get from %n
var string_to_show = "SENSOR" + _tag_value ;
document.getElementbyID("text_box_1234").text(_string_to_show );

Is this possible at all. I need to retrieve numeric tag value from %n etc.
I tried this on mouse_down event
console.log ("Hello Testing"); // works ok
console.log (!EVAL $V("TAG1") ; throws error
console.log ($V("TAG1") ; Also throws error
console.log ($V("%n") ; Also throws error
Thanks
Ajay

@riclolsen
Copy link
Owner

Maybe an example can be clearer:
https://codepen.io/ricardolo/pen/NWxWoKz
The 2 bottom values are produced with !EVAL in the faceplate tab.
The second is a string concatenated with value as you need.
The SVG file is here
https://raw.githubusercontent.com/riclolsen/displayfiles/master/evaltest.svg

@ajaywazir
Copy link
Author

Thanks.
I got it running...
I have one more question
How to create a fault dictionary where number of items is more than 8
for tag with less than 8 different values, I can use TEXT to translate values to text
I have a 32 bit error code, with each bit denoting a particular error

How to do this in javascript? Any suggestions

Thanks in advance

Ajay

@riclolsen
Copy link
Owner

Yes, TEXT won't do it for more than 8 values.
There are many ways to do it, but a simple one can be using the same !EVAL expression as in the previous case.
You can test each bit and return the corresponding text.
Like in
!EVAL if ($V("@1")&0x01) { "TEXT FOR BIT 0" } else if ($V("@1")&0x02) { "TEXT FOR BIT 1" }

@ajaywazir
Copy link
Author

Hi
Thanks
I will give it a try
Ajay

@ajaywazir
Copy link
Author

Hi
I tested it
I am using a model based tags. my %q is derived from face plate
!EVAL if ($V("%q")&0x01) { "TEXT FOR BIT 1" } else if ($V("%q")&0x02) { "TEXT FOR BIT 2" }
only first if condition is evaluated
I believe, %q is not re-evaluated after ist evaluation.

I also tried
!EVAL
var tt = $V("%q");
if (tt&0x01) {
"TEXT FOR BIT 0"
}
if (tt&0x02) {
"TEXT FOR BIT 1"
}
if (tt&0x04) {
"TEXT FOR BIT 2"
}
This also did not work
Is there another way?

Ajay

@ajaywazir
Copy link
Author

ajaywazir commented Jun 6, 2020

Hi
This works for me
!EVAL
var tt = $V("%q");
if (tt&0x01) {
"TEXT FOR BIT 0"
}
else if (tt&0x02) {
"TEXT FOR BIT 1"
}
else if (tt&0x04) {
"TEXT FOR BIT 2"
}
else
{"KK"}

However, this works with only 1 tag (First one only)
var tt = $V("%q");
var tt2 = $V("%r");
tt2 is always evaluated to 0.

Consequenty, this one also does not work as the 2nd instance of %q is always evaluated to 0
!EVAL if ($V("%q")&0x01) { "TEXT FOR BIT 1" } else if ($V("%q")&0x02) { "TEXT FOR BIT 2" } else
{"KK"}

Thanks and Best Regards
Ajay

@riclolsen
Copy link
Owner

Hi AJay,
Confirmed, the !EVAL expression when applied inside a group with indirect variables as in %n, %q... substitutes only the first one, others will cause undefined behavior. It works if you do not use multiple variables in the same expression. I must solve this problem in some future version.
For now, I recommend using !EVAL with multiple tags only in the faceplate of the top-level group. With this, you can achieve the same desired results.
Thanks for spotting this!
Best regards,
Ricardo

@ajaywazir
Copy link
Author

Hi Ricardo,
Thanks.
let me try to give the faceplate EVAL a spin

Regards
Ajay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants