ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Problem with clicking hotspots
Posted by Medic89 on Jan-18-2023 02:07
Hello Peter,

I have a chart with multiple hotspots. When I hover the cursor on one of those points, I get a tooltip as expected. When I click the hotspot, the desired menu opens and everything works as expected. However, my charts updates every 10 seconds, so if there is an update between moving the mouse over the hotspot and clicking the hotspot, it looks like, ChartDirector doesn't recognise Im over a hotspot. Do you have a solution for this? I already created a Global variable (ImageMapHandler* hotSpotData) and whenever the charts gets rebuild, I try to update this variable as well (hotSpotData = c_DiagrammA->getImageMapHandler();), but no luck unfortunately. Within my OnClickHotSpot function, I use the date of the global variable to proceed.

  Re: Problem with clicking hotspots
Posted by Peter Kwan on Jan-19-2023 03:52
Hi Medic89,

As far as I know, if the ImageMapHandler is correct, and the mouse coordinates you pass to the ImageMapHandler is correct, it can always return the correct hot spot. It does not depend on what is displayed on the screen.

I will need to set up a similar test program and try it myself. I will update you later.

Best Regards
Peter Kwan

  Re: Problem with clicking hotspots
Posted by Medic89 on Jan-20-2023 01:26
As a workaround, I created a CRect vector array and I build a function, that extracts all the coordinated from the imagemap string. when I click on the chart I check my array, if the current mouse coordinates are inside in any of the rectangles (each rectangle represents one hotspot).

  Re: Problem with clicking hotspots
Posted by Peter Kwan on Jan-20-2023 02:24
Hi Medic89,

After reading your message again, I am thinking, when your chart is updated, have you also update the image map?

You mentioned that you use the following code:

hotSpotData = c_DiagrammA->getImageMapHandler();

I assume c_DiagrammA is a CChartViewer object. When you update the chart, you should have two lines like:

c_DiagrammA->setChart(myNewChart);
c_DiagrammA->setImageMap(myNewChart->getHTMLImageMap(.....));

When the chart is updated, ChartDirector does not assume the new chart is the same as the old chart. As a result, ChartDirector will clear the old image map, as it would not be applicable to the new chart. If the new chart does have hot spots, your code would need to set the image map after setting the new chart.

Have your code set the image map as well? Setting the image map before setting the new chart has no effect as the image map will be cleared when setting the new chart.

Best Regards
Peter Kwan

  Re: Problem with clicking hotspots
Posted by Peter Kwan on Jan-20-2023 04:16
Hi Medic89,

I have just tried myself, and I think I may have found the cause of the issue.

The ImageMapHandler has a "getHotSpot" method. Basically, you can pass the x and y coordinates to the ImageMapHandler, and it will find the hot spot at that position and set it as the "current hot spot".

https://www.advsofteng.com/doc/cdcpp.htm#ImageMapHandler.getHotSpot.htm

You can then use ImageMapHandler::getKey and ImageMapHandler::getValue to retrieve the attributes of the current hot spot.

I realize in our sample code, we never call getHotSpot. It is because the CChartViewer will automatically call it whenever the mouse coordinate changes. So the current hot spot should track the mouse.

But your case is an exception. When you update the chart, the current image map is cleared, so there is no current hot spot. Then a new image map is assigned to the CChartViewer. If the mouse is then clicked without moving it first, ChartDirector will not automatically call getHotSpot, and there will be no current hot spot.

To solve the problem, you can call getHotSpot yourself with the current mouse coordinates before retrieve the hot spot attributes. In MFC, it is like:

// Note: Code based on ChartDirector 7
POINT p;
if (GetCursorPos(&p))   // Get Cursor screen coordinate
{
     // Convert to coordinate relative to CChatViewer
     myChartViewer->ScreenToClient(&p);
     myChartViewer->getImageMapHandler()->getHotSpot(p.x, p.y, myChartViewer->getChart());
}

Hope this can help.

Regards
Peter Kwan

  Re: Problem with clicking hotspots
Posted by Medic89 on Jan-21-2023 04:15
Hello Peter,

your solution worked, except I skipped creating a CPoint element, I used the getPlotAreaMouseX() and getPlotAreaMouseY() functions to retrieve the mouse position.

  Re: Problem with clicking hotspots
Posted by Medic89 on Jan-21-2023 04:18
The only problem is, that when there are no hotspots yet, there is no imagemap and therefore, clicking on the diagram brings an error message when I call the getImageMapHandler() function.

  Re: Problem with clicking hotspots
Posted by Peter Kwan on Jan-21-2023 23:04
Hi Medic89,

The getImageMapHandler should not produce any error. It just returns null if there is no image map.

To handle the possibility that the chart can have no image map for some time, you can check for null return before using the ImageMapHandler:

ImageMapHandler *h = myChartViewer->getImageMapHandler();
if (0 != h) {
    h->getHotSpot(p.x, p.y, myChartViewer->getChart());
}

Hope this can help.

Regards
Peter Kwan

  Re: Problem with clicking hotspots
Posted by Medic89 on Jan-26-2023 22:29
Solution works as expected, thanks Peter!:)