|
HTML image map, convert the resulting HTML text to plain text? |
Posted by TonyVSUK on Nov-25-2021 20:30 |
|
I've got a graph with a clickable legend. The click works fine, and once I intercept the click, the text I get is like this.
"dataSet=0ndataSetName=Pension%20Savings:test03"
What I really want is plain text, not something where "%20" has been substituted for a space.
Is there an easy way to do this?
Thanks in advance,
Tony. |
Re: HTML image map, convert the resulting HTML text to plain text? |
Posted by Peter Kwan on Nov-26-2021 00:52 |
|
Hi TonyVSUK,
I assume you are writing a non-web application (a desktop application or a command line or batch application). Would you mind to clarify which framework (MFC, Qt or some other frameworks) that you are using?
The image map is supposed to be passed to an ImageMapHandler object. In the on click event handler, we can use the ImageMapHandler to read back the parameters. It will unescape the %20 back to the space character. For example:
const char *myDataSetName = myImageMapHandler->getValue("dataSetName");
should return "Pension Savings:test03", with the %20 unescaped back to a space character.
See:
https://www.advsofteng.com/doc/cdcpp.htm#ImageMapHandler.htm
In our CChartViewer (for MFC) or QChartViewer (for Qt), when your code use CChartViewer::setImageMap or QChartViewer::setImageMap to set an image map, it will create an ImageMapHandler internally. Everytime the mouse moves, it will update the ImageMapHandler with the mouse coordinates, and check if the mouse is over a hot spot and display tooltip if necessary. In the on click event handler, your code can use CChartViewer::getImageMapHandler or QChartViewer::getImageMapHandler to obtain the internal ImageMapHandler, and read the parameters using it. The parameters will be unescaped, so you get back the original parameters.
Hope this can help.
Regards
Peter Kwan |
Re: HTML image map, convert the resulting HTML text to plain text? |
Posted by TonyVSUK on Nov-26-2021 01:31 |
|
Thanks. I'm using wxWidgets (and wxChartDir).
I've got the image ImageMapHandler, but when I try what you suggest, it returns NULL.
ImageMapHandler* handler = m_wxChartViewer->getImageMapHandler();
if (handler != NULL)
{
// Query the ImageMapHandler to see if the mouse is on a clickable hot spot. We
// consider the hot spot as clickable if its href ("path") parameter is not empty.
const char *path = handler->getValue("path");
const char *myDataSetName = handler->getValue("dataSetName");
if ((0 != path) && (0 != *path))
{
int nDebug = 1;
}
}
Experimented some more, if I change the HTML image map from
wxString strHTMLMapThing = "dataSet={dataSet}ndataSetName={dataSetName}";
to
wxString strHTMLMap = "dataSetName={dataSetName}";
Now I get "myDataSetName" populated correctly. I'm guessing the "n" is causing problems and should be "&"?
All the best,
Tony. |
Re: HTML image map, convert the resulting HTML text to plain text? |
Posted by Peter Kwan on Nov-26-2021 11:01 |
|
Hi TonyVSUK,
Yes, the separator should be "&".
We used the HTML syntax to define hot spots because it is an open standard, and it allows developers to add custom hot spots to the chart by including extra <area> tags to the chart. In some applications, developers will add custom buttons and objects to the chart and make them clickable or have tooltips.
The HTML syntax requires "&" as the delimiter. The "%20" is also the HTML syntax for escaping certain characters. The ImageMapHandler can understand these syntax and recover the original parameters.
Regards
Peter Kwan |
|