|
getHTMLImageMap not working properly, truncating map. Memory allocation? |
Posted by Andreas Lachner on May-13-2011 00:23 |
|
Hi there,
we are evaluating the ChartDirector and so far everything looks fine.
However, there is a serious issue with getHTMLImageMap, using plain VC++.
Take a look at the following code, straightforward:
ImageMapHandler *pImageMapHandler;
const char *imageMap = 0;
pCupsChart->makeChart();
imageMap = pCupsChart->getHTMLImageMap("");
pImageMapHandler = new ImageMapHandler(imageMap);
But the Handler does only work on the last few Bars, not all of them.
In fact, when you output the imageMap string, its simply truncated:
<area shape="poly" coords="428,194,450,194,454,190,454,190,432,190,428,194" href="SPICE?x=5&xLabel=F&dataSet=1&dataSetName=New%20Order&value=0">
<area shape="poly" coords="399,194,421,194,425,190,425,186,403,186,399,190" href="SPICE?x=5&xLabel=F&dataSet=0&dataSetName=Historic&value=1.311475">
<area shape="poly" coords="358,194,380,194,384,190,384,190,362,190,358,194" href="SPICE?x=4&xLabel=E&dataSet=1&dataSetName=New%20Order&value=0">
<area shape="poly" coords="329,194,351,194,355,190,355,172,333,172,329,176" href="SPICE?x=4&xLabel=E&dataSet=0&dataSetName=Historic&value=5.57377">
<area shape="poly" coords="288,194,310,194,314,190,314,110,292,110,288,114" href="SPICE?x=3&xLabel=D&dataSet=1&dataSetName=New%20Order&value=24.516129">
<area shape="poly" coords="259,194,281,194,285,190,285,96,263,96,259,100" href="SPICE?x=3&xLabel=D&dataSet=0&dataSetName=Historic&value=28.52459">
<area shape="poly" coords="218,194,240,194,244,190,244,78,222,78,218,82" href="SPICE?x=2&xLabel=C&dataSet=1&dataSetName=New%20Order&valu
As you can see, the rest is missing. Somehow it looks like the DLL does not allocate enough internal memory for the map. Or I am missing something stupid.
Needless to say, that the Chart itself renders perfectly.
Can you take a look into that? Its the thing preventing us from purchasing.
Thanks
Andreas
|
Re: getHTMLImageMap not working properly, truncating map. Memory allocation? |
Posted by Peter Kwan on May-13-2011 03:02 |
|
Hi Andreas,
Many of the ChartDirector MFC sample code generates image map that are much longer than the one you are using, so I believe memory is not the cause of the problem.
For your case, would you mind to clarify how do you obtain the image map in text form? Are you using the debugger to look at the variable "imageMap" (eg. using the TRACE macro)? Note that the debugger may only display the first 1K characters, so the text displayed by the debugger may not be the complete image map. I suggest you may save the image map to a file and then open it using a text editor to verify the actual image map generated.
ImageMapHandler *pImageMapHandler;
const char *imageMap = 0;
pCupsChart->makeChart();
imageMap = pCupsChart->getHTMLImageMap("");
FILE *f = fopen("c:/test.txt", "w");
fwrite(imageMap, strlen(imageMap), 1, f);
fclose(f);
pImageMapHandler = new ImageMapHandler(imageMap);
For your case, I have not seen how you are using the image map handler. If you think it is not working, could you verify if the coordinates that you pass to it (in getHotSpot) is consistent with the coordinates in the image map? Are you using coordinates that are pixels relative to the top-left corner of the chart image (and not relative to the window or other container)?
Regards
Peter Kwan |
Re: getHTMLImageMap not working properly, truncating map. Memory allocation? |
Posted by Andreas Lachner on May-13-2011 03:32 |
|
Hi Peter,
you are right, when I save as a File, the map is entire.
But when I pass directly to
lpAnaCups->lpvImageMapHandler = new ImageMapHandler(imageMap);
its incomplete. Please look at the enclosed Picture, this is how I test:
int iHotSpot,x,y;
HDC hdc;
hdc=GetDC(hwnd);
for (y=0;y<yClientSize(hwnd);y++)
for (x=0;x<xClientSize(hwnd);x++)
{
iHotSpot=((ImageMapHandler *)lpSpiceAna->saAnaCups.lpvImageMapHandler)->getHotSpot(
x-lpSpiceAna->saAnaCups.iXStart,
y-lpSpiceAna->saAnaCups.iYStart);
if (((ImageMapHandler *)lpSpiceAna->saAnaCups.lpvImageMapHandler)->getKey(iHotSpot)!=NULL)
SetPixel(hdc,x,y,RGB(255,0,0));
}
ReleaseDC(hwnd,hdc);
As you can see, only the rightmost Areas are recognized.
Strange also, that there is a slight offset to the right?
Thanks
Andreas
|
Re: getHTMLImageMap not working properly, truncating map. Memory allocation? |
Posted by Peter Kwan on May-13-2011 17:31 |
|
Hi Andreas,
The method you use to test the existance of the hot spot is incorrect.
The iHotSpot is a number representing the hot spot. You can consider it as a "handle" to the hot spot (similar to the file handler FILE * when you open a file). As according to the ChartDirector documentation, a value of -1 means the coordinates (x, y) is not on a hot spot, otherwise iHotSpot can assume any arbitrary value.
For each hot spot, there can be a number of attributes describing the hot spot. For example, there may be an attribute for the data value, data set name, x-position, etc.. You can retrieve them using getKey, by passing 0, 1, 2, .... for the first, second, third .... attributes. If there are 5 attributes, and you pass a number larger than 4, then ChartDirector will return null, as there is no such attribute.
You should not use iHotSpot in getKey, because iHotSpot is an "arbitrary number" for valid hot spot (you can assume it is a random number), and -1 for non hotspot. The iHotSpot is only used to determine if the mouse is over a hot spot, and if two hot spots are in fact the same hot spot (by checking if their iHotSpot is the same).
For your case, the text code should be:
int iHotSpot,x,y;
HDC hdc;
hdc=GetDC(hwnd);
for (y=0;y<yClientSize(hwnd);y++)
for (x=0;x<xClientSize(hwnd);x++)
{
iHotSpot=((ImageMapHandler *)lpSpiceAna->saAnaCups.lpvImageMapHandler)->getHotSpot(
x-lpSpiceAna->saAnaCups.iXStart,
y-lpSpiceAna->saAnaCups.iYStart);
if (iHotSpot != -1)
SetPixel(hdc,x,y,RGB(255,0,0));
}
ReleaseDC(hwnd,hdc);
The hot spot is offsetted because your code offsetted the hot spot incorrectly. You can using (x-lpSpiceAna->saAnaCups.iXStart, y-lpSpiceAna->saAnaCups.iYStart)" to test for the hot spot, but you are plotting (x, y) in SetPixel. The lpSpiceAna->saAnaCups.iXStart and lpSpiceAna->saAnaCups.iYStart probably are the incorrect offsets to use.
Hope this can help.
Regards
Peter Kwan |
|