|
HELP: use of addExtraField to fill tooltip not always working |
Posted by John Vella on May-02-2024 06:03 |
|
I'm using the C++ version of CD.
In my chart I have a single LineLayer with multiple datasets creating my graph content.
I'm using layer->addExtraField to define some custom info that I want to present within the tooltip that is shown while hovering over the dataset lines.
Each of the datasets can have a varying number of points. Each point will have defined for it the custom info I want to show (in my case the info is called "engine").
To define the array of custom values for the call to addExtraField I simply add the "engine" value for each dataset. So if dataset 0 has two points in it, and dataset 1 has three, then my array will have five fields, something like this:
{ds0_pt1, ds0_pt2, ds1_pt1, ds1_pt2, ds1_pt3}
Here's the problem: depending on which of the two datasets is added first impacts the ability of the tooltip to correctly display the "engine" value. My tooltip text looks like this:
"<*ENGINE={dsdiField0}*>"
So what I'm seeing in the tooltip is "{dsdiField0}" sometimes for the dataset which is added second. If the order is switched so that dataset "1" happens to be added first, then all of the custom engine values are shown correctly.
I feel like this is a long-winded description that may or may not be clear. Please push back on me for additional information. |
Re: HELP: use of addExtraField to fill tooltip not always working |
Posted by Peter Kwan on May-02-2024 23:23 |
|
Hi John,
For a layer with multiple data sets with different extra fields, the code should be like:
LineLayer* layer = c->addLineLayer();
layer->addDataSet(DoubleArray(data0, data0_size), 0xff0000, "AAAA");
layer->addExtraField(DoubleArray(extra0, extra0_size));
layer->addDataSet(DoubleArray(data1, data1_size), 0x008800, "BBBB");
layer->addExtraField(DoubleArray(extra1, extra1_size));
layer->addDataSet(DoubleArray(data2, data2_size), 0x008800, "CCCC");
layer->addExtraField(DoubleArray(extra2, extra2_size));
Each dataset should have its own extra field array. The extra field can then be referenced using {dsdiField0}
I'm using layer->addExtraField to define some custom info that I want to present within the tooltip that is shown while hovering over the dataset lines.
Best Regards
Peter Kwan |
Re: HELP: use of addExtraField to fill tooltip not always working |
Posted by John Vella on May-03-2024 01:15 |
|
Peter Kwan wrote:
Hi John,
For a layer with multiple data sets with different extra fields, the code should be like:
LineLayer* layer = c->addLineLayer();
layer->addDataSet(DoubleArray(data0, data0_size), 0xff0000, "AAAA");
layer->addExtraField(DoubleArray(extra0, extra0_size));
layer->addDataSet(DoubleArray(data1, data1_size), 0x008800, "BBBB");
layer->addExtraField(DoubleArray(extra1, extra1_size));
layer->addDataSet(DoubleArray(data2, data2_size), 0x008800, "CCCC");
layer->addExtraField(DoubleArray(extra2, extra2_size));
Each dataset should have its own extra field array. The extra field can then be referenced using {dsdiField0}
I'm using layer->addExtraField to define some custom info that I want to present within the tooltip that is shown while hovering over the dataset lines.
Best Regards
Peter Kwan
Sadly that's exactly what I'm doing (using "{dsdiFieldN}"), but like I said previously the substitution is happening ok for data0, but not for data1. Would you try following what I mentioned as far as the datasets having different number of values, and also switching the order of when the datasets are added (for example, data0 is added 2nd instead of 1st) and see if your tooltip content gets correct substitutions?? |
Re: HELP: use of addExtraField to fill tooltip not always working |
Posted by John Vella on May-03-2024 01:19 |
|
I should have mentioned that each dataset has multiple sets of extra data (unique to the dataset). So perhaps that is what is causing the issue trying to get "{dsdiFieldN}" to work correctly? |
Re: HELP: use of addExtraField to fill tooltip not always working |
Posted by John Vella on May-04-2024 07:05 |
|
Hi Peter, this has been EXTREMELY frustrating for me as I've spent multiple days trying to figure out the right combination of how to put together the extra fields for the various datasets (not your fault, I know). I AM URGENTLY AWAITING YOUR HELP.
So I thought I would try including the pseudo code that illustrates what I'm doing (the actual code is much too involved to try and include). Again, this is for C++.
// [BEGIN CODE]
auto layer = c->addLineLayer();
FOR-LOOP (iterating over my custom data) {
auto ds0 = layer->addDataSet(...); // DATASET 0
// fill hash table with various info for this dataset
auto ds1 = layer->addDataSet(...); // DATASET 1
// fill hash table with various info for this dataset
}
// At this point I have two datasets, each can have different number of data points.
// Now I will try to get the extra fields added for use in the tooltips.
// NOTE1: each dataset will have a unique name for the dataset
// NOTE2: each of the points within each dataset will have unique values
FOR-LOOP (iterate over layer datasets) {
std::vector<double> uniquePtData;
std::vector<const char*> uniqueDsName;
// Get data from hash table for this specific dataset
for (auto pt : dsPointValues )
uniquePtData.push_back(pt);
uniqueDsName.push_back(dsName);
layer->addExtraField(DoubleArray(&(uniquePtData[0]), uniquePtData.size());
layer->addExtraField(StringArray(&(uniqueDsName[0]), uniqueDsName.size());
}
layer->setHTMLImageMap("", "", "NAME={dsField1}, POINT={dsdiField0}");
// [END CODE]
I fully understand that I'm doing something wrong. It's my hope the above "code" is enough for you to tell me exactly how to achieve what I need. |
Re: HELP: use of addExtraField to fill tooltip not always working |
Posted by Peter Kwan on May-04-2024 23:11 |
|
Hi John,
in your code, the extra fields are:
- unique point data for data set 0 (size of array = size of data set 0)
- unique data set name for data set 0 (size of array = 1 as there is one unique data set name per data set)
- unique point data for data set 1 (size of array = size of data set 0)
- unique data set name for data set (size of array = 1)
Since the since of the unique data set array is always 1, the simplest code should be to add the extra field in the following sequence:
- unique point data for data set 0 (size of array = size of data set 0)
- unique point data for data set 1 (size of array = size of data set 1)
- unique data set names for all data sets (size of array = 2 if there are two data sets)
In this case, the code is like:
std::vector<const char*> uniqueDsName;
FOR-LOOP (iterate over layer datasets) {
std::vector<double> uniquePtData;
// Get data from hash table for this specific dataset
for (auto pt : dsPointValues )
uniquePtData.push_back(pt);
uniqueDsName.push_back(dsName);
layer->addExtraField(DoubleArray(&(uniquePtData[0]), uniquePtData.size());
}
layer->addExtraField(StringArray(&(uniqueDsName[0]), uniqueDsName.size());
layer->setHTMLImageMap("", "", "NAME={dsField2}, POINT={dsdiField0}");
To use dsdiField0, the extra fields must start at the first extra field (index 0) and follow each others. If the unique data value fields interleave with the unique data set name fields, it would not work.
The {dsField2} means the third extra field (at index 2) is indexed by data set. That means the first extra field value is for the first data set, and the second extra field value is for the second data set.
The above is for 2 data sets. If you have N data sets, there should be N unique data values array, and one unique data set name array at {dsFieldN} (N is the number of data set).
Best Regards
Peter Kwan |
Re: HELP: use of addExtraField to fill tooltip not always working |
Posted by John Vella on May-04-2024 23:57 |
|
THANK YOU, THANK YOU, THANK YOU Peter, your explanation finally allowed me to understand what the heck is going on.
Wow, huge relief to get this working - your support and knowledge is always impressive!
-John |
|