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

Message ListMessage List     Post MessagePost Message

  Clickable shape
Posted by Rand on Jan-07-2022 05:19
I am creating a selector on a chart.  The idea is that if a triangle indicator is present then there are other data sets to view by right clicking the triangle.
I need this to draw on the chart and to produce an image map line from chart->getHTMLImageMap("") so the mouse right click handler can identify the spot.
I generate a line and add it to chart->getHTMLImageMap() and then call view_port->setImageMap() with the result. I attempt to verify the added line by calling view_port->getChart()->getHTMLImageMap("").  The result does not contain the line I added but does contain all of the custom data point lines.
ImgageMap 1 and ImageMap 2 below should be identical, or not?
I just need to tag this triangle so it can be used to inititate the drawing of the data set names list for the user to select.

// Draw inverted triangle, bright green border with blue fill
auto int_array = std::vector{ left_x2, top_y, right_x, top_y, center_x, bottom_y };
chart->getDrawArea()->polyShape( {, (int)int_array.size() }, COLOR_CHART_BORDER, COLOR_CHART_INDICATOR_ARROW );
// Get the image map line for this shape, use the bounding rect
auto fmt_str( R"(<area shape="rect" coords='{},{},{},{}' title='{}' href="{}">)" );
m_state.img_map_str = fmt::format( fmt_str, left_x, top_y, right_x, bottom_y, title, href ) += "n"; // format works like python
// Final steps
m_view_port->setChart( chart ); // m_view_port->getImageMapHandler() == nullptr, create new
DoSetImageMapForViewPort( chart );

void DoSetImageMapForViewPort( XYChart* chart )
auto* img_map = chart->getHTMLImageMap( "" );
if( img_map )
std::string image_map_str{ img_map };
image_map_str += m_state.img_map_str ;
m_view_port->setImageMap( image_map_str.c_str() );
m_log->trace( "IMAGE MAP:n{}", image_map_str ); // ImgageMap 1 below
DoLogViewPortChartImageMap(); // ImgageMap 2 below. Uses m_view_port->getChart()->getHTMLImageMap() to get string to log

-- Single data point for brevity, the data point below is the final in both listings
ImageMap 1

<area shape="poly" coords="52,167,88,134,84,130,52,159" title='<*block,color=33CC33,bgColor=121212,edgeColor=33CC33,margin=5*>Y Position: 1061 mm<*br*>Hole Size: 47 mm²' href="data_point?x=0&xLabel=0&dataSet=2&dataSetName=3&value=1061" />
<area shape="rect" coords='52,18,307,28' title='suite_selector' href="suite_selector"> -- this is the added line

ImageMap 2
<area shape="poly" coords="52,167,88,134,84,130,52,159" title='<*block,color=33CC33,bgColor=121212,edgeColor=33CC33,margin=5*>Y Position: 1061 mm<*br*>Hole Size: 47 mm²' href="data_point?x=0&xLabel=0&dataSet=2&dataSetName=3&value=1061" />

  Re: Clickable shape
Posted by Peter Kwan on Jan-07-2022 14:17
Hi Rand,

The ImageMap1 and ImageMap2 should not be the identical. So the result you see is normal.

The m_view_port->getChart()->getHTMLImageMap() should be identical to chart->getHTMLImageMap( "" ). They are both image maps that come from the chart object.

The ImageMap1 is created by combining chart->getHTMLImageMap( "" ) with another image map m_state.img_map_str. So it is not the same as chart->getHTMLImageMap( "" ) or m_view_port->getChart()->getHTMLImageMap().

Have you tried if the custom hot spot is working normally? You can try to set the title to
title="<*cdml*>suite_selector", then check if you can see the tooltip when the mouse is over your shape.

Peter Kwan

  Re: Clickable shape
Posted by Rand on Jan-08-2022 05:09
I am drawing on the chart DrawArea, not the plot area. My image map was always returning 0 for the hot spot number because I was using getPlotAreaMouse...
The docs should be updated, it appears that 0 rather than -1 is returned for no hot spot found.  Ref:

I added an OnMouseMoveChart() handler which uses getChartMouse... rather than getPlotAreaMouse... and the hotspot now works.

My right click handler uses both methods to check for a hot spot with plot area having priority.  Will that work as expected or is there overlap between the two get mouse methods?

  Re: Clickable shape
Posted by Peter Kwan on Jan-10-2022 20:30
Hi Rand,

Sorry for the incorrect documentation. I checked our code, and it does return 0 for no hot spot.

The getChartMouse... returns the chart pixel coordinates of the mouse. The getPlotAreaMouse.... starts from the same chart pixel coordinates, but adjusted them if necessary so that they are within the plot area. If the mouse is inside the plot area, the two coordinates should be identical. If you hot spot is outside the plot area, the getPlotAreaMouse... will never hit your hot spot, as it can only return a coordinate inside the plot area.

For hot spot testing, getChartMouse... should be used, because you want to know the actual mouse coordinates.

The getPlotAreaMouse... is designed for track cursor applications. It makes it easy to position the track cursor at the edges of the plot area. It is difficult to move the mouse to the edge exactly, as it is difficult to move the mouse at pixel precision. With getPlotAreaMouse..., even if the mouse moves past the plot area right edge, it will be adjusted so that the right edge coordinates will be returned.

Peter Kwan