Receive email notifications by changing your settings.
Click on your picture in the top right corner, go to Preferences and select your notification preferences.
Thank you for contributing to our forum!
Please keep in mind:
1. To only comment on the topic where the discussion is about. Do you have a new question or topic? Please start a new discussion.
2. Be kind to other users!

API set legend

Hi,

Is it possible to change required input to set the colors in a legend for an overlay?

I use R to work with th API. To create a text string you use "...". For the colors I need to include "argb". It is impossible to create a string with " in it. It closes the string.

Since I always have to use "argb", would it be possible to just drop this in the required input? The input would just be the colorcode (and default in the "argb" system, so no need to include it).

https://engine.tygron.com/api/session/event/editoroverlay/add_custom_gridoverlay_legend_entry/

[ [ 1, 2, 3 ], [ true, false, true ], [ "Name A", "Name B", "Name C" ], [ {  "argb" : 734200486}, {  "argb" : -794947287}, {  "argb" : -585062813} ], [ 1.0, 1.5, 2.0 ] ]

Tagged:

Comments

  • Hi Ward,

    I haven't experimented with setting legends via the API all that much yet, but the following details will probably help you find the right approach.

    First, the API indicates a color can be set as a TColor, with argb values in the example. However, as the computed argb values you currently see in the examples can be rather terse, they will not neccesarily be the only method of defining color codes forever. For example: at least when dealing with COLOR attributes the same single-value color definition was our standard for a long time, but since the addition of array values in attributes we have allowed setting the COLOR attribute with separate R, G, and B values as well, making the setup more readable for human and code alike. I wouldn't be supprised if some similar syntax would already be accepted here as well, although I haven't looked into it yet.

    ( For anyone interested in more information in our color format, please see our wiki: https://support.tygron.com/wiki/Color )

    Further, in most languages the challenge of encoding special characters in a string, especially string-closing characters, is a solved problem. Virtually all languages include the ability to escape characters ( "I'm using a \" in my string!" ), and many also allow you to enclose a string in single quotes as well ( 'I\'m using a " in my string!' ). See if the way you are constructing your parameters allows for this.

    Alternatively, although the described structure has double quotes in the array entries, those array entries are actually mappings in-and-of themselves, with a single key "argb", and a single value. If creating a string of that entire mapping is undesirable or not possible, another way could also be to create a map object (or its R-equivalent), add a key value pair with "argb" being the key and the color value being the value, and then json_encoding that for the desired string. Although I would recommend where possible to assemble your parameters as an array of arrays and objects, and then encoding it in 1 go at the end, than to assemble a complete parameter string manually. Your milage may vary, of course.

    Regards!

Sign In or Register to comment.