|
Wrong URL in getHTMLImageMap |
Posted by David on Jun-21-2012 03:41 |
|
Hi -
I am creating clickable line charts in python. I want both the legend and the line to be clickable. Below is how I create my image maps
chartImageMap = self.c.getHTMLImageMap("createChart.py?col=%s&item=%s" %(col,item), "", "title='{dataSetName} Click to drill down'")
legendImageMap = self.LegendBox.getHTMLImageMap("createChart.py?col=%s&item=%s" % (col,item), "", "title='{dataSetName}; Click to drill down'")
When my charts are displayed, if I hover over the line or legend, the URL shown in the lower left corner of mozilla is not correct. The 'item' value in the URL is incorrect. If I do a view source on the web page, the URL is correct. I have also printed out the value of the variable 'col' right before the getHTMLImageMap calls and it is correct.
Any idea what I have done wrong?
Thanks in advance. |
Re: Wrong URL in getHTMLImageMap |
Posted by Peter Kwan on Jun-22-2012 00:38 |
|
Hi David,
In your case, all the URLs should include the same col and item, which is the item and col you use when you created the URL. To further diagnose the problem, please change your code to:
myToolTip = "title='{dataSetName} Click to drill down (%s, %s)'" % (col, item)
chartImageMap = self.c.getHTMLImageMap("createChart.py?col=%s&item=%s" %(col, item), "", myToolTip)
With the above code, there should be a copy of (col, item) in every tooltip. Does the value in the tooltip matches that of the URL?
Regards
Peter Kwan |
Re: Wrong URL in getHTMLImageMap |
Posted by David on Jun-22-2012 02:25 |
|
I don't get it. When I print the toolTip to the screen, it prints the correct value for item. The tooltips show the incorrect value as does the URL. When I do a 'view source' on the webpage, the values within the <area> tags are correct.
myToolTip = "title='{dataSetName} values: (%s, %s)'" % (col, item)
print 'myToolTip', myToolTip
chartImageMap = self.c.getHTMLImageMap("createChart.py?col=%s&item=%s" %(col, item), "", myToolTip)
legendImageMap = self.LegendBox.getHTMLImageMap("createChart.py?col=%s&item=%s" %(col, item), "", myToolTip)
I loop through this code several times to create multiple clickable charts. Each time I loop through the item should be different. But it stays at the value of the item from the first chart.
Thank you,
David |
Re: Wrong URL in getHTMLImageMap |
Posted by Peter Kwan on Jun-23-2012 01:28 |
|
Hi David,
The myToolTip variable is not created by ChartDirector. It is created by Python itself. (The line that created myToolTip does not use any ChartDirector features.) The same myToolTip variable is then used in both your "print" statement, and also in ChartDirector. So they should produce identical results.
In your case, you mentioned "loop through this code several times to create multiple clickable charts", and "it stays at the value of the item from the first chart". I suspect it is because your code only output the value item of the first chart. Although the code that generates the chartImageMap and legendImageMap is looped through several times, it does not necessarily mean they are outputted to the web page. I would need to see your complete code to see how the image map is outputted.
Also, for debugging, I suggest you use:
myToolTip = "title='{dataSetName} values: (%s, %s)'" % (col, item)
print "=========================================="
print 'myToolTip', myToolTip
chartImageMap = self.c.getHTMLImageMap("createChart.py?col=%s&item=%s" %(col, item), "", myToolTip)
print chartImageMap
legendImageMap = self.LegendBox.getHTMLImageMap("createChart.py?col=%s&item=%s" %(col, item), "", myToolTip)
print legendImageMap
print "=========================================="
With the above code, you can immediately see what is myToolTip, and what is the image map generated by ChartDirector. If the image map generated by ChartDirector is correct, but the image map in the final output is incorrect, it means the image map generated is not outputted.
Regards
Peter Kwan |
Re: Wrong URL in getHTMLImageMap |
Posted by David on Jun-25-2012 20:46 |
|
Hi Peter -
I put in the print statements as you suggested. The myToolTip will print correctly. Nothing prints for chartImageMap or legendImageMap. I pasted some additional code below. I'm hoping that is enough to give you insight into what I'm doing wrong.
Thanks
David
for key in boxes.keys():
x = ClickableChart(col, key, byPartNum)
chartURL, chartImageMap, legendImageMap = x.buildChart()
print "<b>Click on legend to drill down</b>
"
print """<img src="getchart.py?img=/tmp/tmpcharts/%s" border="0" usemap="#map1"><map name="map1"> %s %s""" % (chartURL, chartImageMap, legendImageMap)
x = ClickableChart(col, key, bySerialNum)
chartURL, chartImageMap, legendImageMap = x.buildChart()
print "<b>Click on legend to drill down</b>
"
print """<img src="getchart.py?img=/tmp/tmpcharts/%s" border="0" usemap="#map2"><map name="map2"> %s %s""" % (chartURL, chartImageMap, legendImageMap)
def buildChart():
# there is a bunch of code to organize data, set up axis labels, set chart title etc
# which I'm not showing
self.LegendBox = self.c.addLegend(90, 20, 0, self.TitleFont, 9)
self.LegendBox.setBackground(Transparent)
self.LineLayer = self.c.addLineLayer2()
self.LineLayer.setLineWidth(2)
for data in dataSet:
dataSetLayer = self.LineLayer.addDataSet(data[1], -1, data[0])
chartURL = self.c.makeTmpFile("/tmp/tmpcharts")
myToolTip = "title='{dataSetName} params (%s, %s)'" % (col, item)
print "============================================"
print 'myToolTip', myToolTip
chartImageMap = self.c.getHTMLImageMap("createChart.py?col=%s&item=%s" %(col, item), "", myToolTip)
print 'chartImageMap ', chartImageMap
legendImageMap = self.LegendBox.getHTMLImageMap("createChart.py?col=%s&item=%s" %(col, item), "", myToolTip)
print 'legendImageMap', legendImageMap
print "============================================"
return (chartURL, chartImageMap , legendImageMap) |
Re: Wrong URL in getHTMLImageMap |
Posted by Peter Kwan on Jun-25-2012 23:00 |
|
Hi David,
In your case, your code should print the chartImageMap and legendImageMap out. In your original code, it is not clear how you are displaying the printing. In your most recent code, it seems you intend to display the printing by insert it as part of the HTML to be sent to the browser. It means the browser will interpret the printing, and not necessarily displays it. For example, if you include <b>xxx</b> in the printing, the browser will only display "xxx", and not the <b> or </b>, as they are HTML tags. That's why you do not see the chartImageMap, as they are image maps (<area> tags). However, you can still see them if you right click on the web page, and choose "View Source". Please let me know what is the output.
If I understand your code correct, it seems you are using the same name for multiple maps. For example, you are using "map1" and "map2" as the names of the <map>, but there are probably more than 2 images and hence more than 2 <map> tags in your code (that means at least one or both of the names must have been repeatedly for multiple <map> tags). Note that according to HTML standard, each map must have a unique name.
To ensure your code is valid HTML, please use a unique name for each <map>. The actual name is not important, as long as it compiles to the HTML standard.
Another thing I found is that your code does not seem to have the </map> tag, which is also in violation of the HTML standard.
You may consider to use something like the followings:
i = 0
for key in boxes.keys():
x = ClickableChart(col, key, byPartNum)
i = i + 1
chartURL, chartImageMap, legendImageMap = x.buildChart()
print """<img src="getchart.py?img=/tmp/tmpcharts/%s" border="0" usemap="#map%d"><map name="map%d"> %s %s</map>""" % (chartURL, i, i, chartImageMap, legendImageMap)
x = ClickableChart(col, key, bySerialNum)
i = i + 1
chartURL, chartImageMap, legendImageMap = x.buildChart()
print """<img src="getchart.py?img=/tmp/tmpcharts/%s" border="0" usemap="#map%d"><map name="map%d"> %s %s</map>""" % (chartURL, i, i, chartImageMap, legendImageMap)
To trouble-shoot further, please look at the actual HTML output (not what your browser displays on the screen, which does not contain the HTML tags, but use "view source" to see the actual HTML).
Regards
Peter Kwan |
Re: Wrong URL in getHTMLImageMap |
Posted by David on Jun-26-2012 03:10 |
|
Ughhhh, you told me the rule about each <map> having a unique name before. At that time I changed to use map1 and map2 when I created the 2 charts but it never occurred to me that each time I'm looping through to create another set of 2 charts I'd be repeating the <map> names. Once I made changes to ensure each <map> had a unique name, my charts work perfectly!
Thanks very much for all the help!
David |
|