ããã°ãªã©ã§ã¡ãã£ã¨ããã°ã©ãã表示ããããå ´å、Google Chart APIã使ã£ã¦ãã。ããã、æä½æ¥ã§å
¥åããã®ã¯ããªãé¢åã 。ã¦ã§ãä¸ã«ã¯ã°ã©ãããã£ã¼ããä½æãããµã¼ãã¹ãªã©ãããã、ç»é²ãå¿
è¦ã ã£ãã、æé ãé¢åã ã£ããã¨、å人çã«ã¯ãã¾ãæ軽ã ã¨æããªã。æ°å¤ãã³ãã¼&ãã¼ã¹ããã¦ã¯ãªãã¯ä¸ã¤ã§ã°ã©ããä½æãããã®ã 。ããã§、使ããããµã¼ãã¹ã¯èªåã§ä½ã£ã¦ãã¾ãã¨ãããã¨ã§、Google App Engine (GAE)ã¨Google Chart APIã使ã£ã¦ç°¡åã«ã°ã©ã・ãã£ã¼ããä½æããã¦ã§ãã¢ããªãä½ã£ã¦ã¿ã。
å³å¸ã§ä½æããã¦ã§ãã¢ããªãªã®ã§ä¸åãªç¹ãããã、åãæ¢ããèªåã§ä½¿ãåã«ã¯ãã®ç¨åº¦ã§ååãªã®ã§GAEã«ç»é²ãã¦ããã。æ°ãåãããæ©è½ãæ¡å¼µãã¦ãããããããªã。
以ä¸ã«ä½¿ãæ¹ã示ã。
使ãæ¹
ã¾ã、以ä¸ã®ãã¼ã¿ãããã¹ãã¨ãªã¢ã«å ¥ãã¦ã¿ã。
1.2 2.2 3.5 5.6 2.8
次ã«、「ä½æ」ãã¿ã³ãæ¼ã。ãã£ã¼ãã®ç¨®é¡ã「æãç·ã°ã©ãX」ã«ãªã£ã¦ããã°、å ¥åãã¼ã¿ããã¨ã«ä»¥ä¸ã®ãããªã°ã©ããæããã。
ã°ã©ãã®X軸、Y軸ã®ä¸éã¨ä¸é、ããã³ãã®ç®çãåå²ã¯èªåã§è¡ããã。ãã¡ãã、æåã§ã®è¨å®ãã§ããã、èªåã§è¨å®ãããæ°å¤ãä¿®æ£ãããã¨ãå¯è½ã 。ã¾ã、åºåç»åãã¡ã¤ã«ã®å¤§ããã、ã°ã©ãã®è²(16é²æ°6æ¡[RGB]ã§è¡¨ç¤º)ãå¤æ´ã§ãã。ã¿ã¤ãã«ã表示ããããã°ã¿ã¤ãã«æ¬ã«å ¥åããã°ãã。å ã¿ã«ã¿ã¤ãã«ãæ¹è¡ãããã«ã¯ | ãå ¥ãã。ããã«、ä¸è¨ã®ãããªGoogle Chart APIã«ããURLã表示ããããã«ãã。ãã®URLãç»åURLã¨ãã¦ããã°ãªã©ã§å©ç¨ããã°、ä¸ã®ã°ã©ãã表示ãããã®ãç°¡åã 。
http://chart.apis.google.com/chart?chs=300x200&chd=t:1.2,2.2,3.5,5.6,2.8&chds=1,6&cht=lc&chco=4d89f9,c6d9fd&chxt=y&chxl=0:|1|2|3|4|5|6
ç¾æç¹ã§å©ç¨ã§ããã°ã©ãã®ç¨®é¡ã¯、「æãç·ã°ã©ãX」、「æãç·ã°ã©ãXY」、「ã¹ãã¼ã¯ã©ã¤ã³」、「ç©ä¸æ¨ªæ£ã°ã©ã」、「ç©ä¸ç¸¦æ£ã°ã©ã」、「éå横æ£ã°ã©ã」、「éå縦æ£ã°ã©ã」、「åã°ã©ã」、「3Dåã°ã©ã」、「æ£å¸å³」ã®10種é¡ã 。2ã«ã©ã 以ä¸ã®ãã¼ã¿ãå¿ è¦ãªã°ã©ãã¯、「æãç·ã°ã©ãXY」ã¨「æ£å¸å³」ã§、ã»ãã¯1ã«ã©ã 以ä¸ã®ãã¼ã¿ã¨ãªã。ã¾ã、「転置」ãã§ãã¯ããã¯ã¹ã«ãã§ãã¯ãå ¥ããã¨è¡ã¨åãå ¥ãæ¿ãããã¨ãã§ã、「ã©ãã«」ãã§ãã¯ããã¯ã¹ã«ãã§ãã¯ãå ¥ããã¨、å ¥åãã¼ã¿ã®1ã«ã©ã ç®ãã©ãã«ã¨ãªã。ã©ãã«å ã«ç©ºç½ãå ¥ãããå ´åã¯、空ç½ã+ã«ç½®ãæãããã¨。
ãã¼ã¿A 0.113 ãã¼ã¿B 0.243 ãã¼ã¿C 0.543 ãã¼ã¿D 0.443
ä¸è¨ã®ãã¼ã¿ãå ¥åã、「éå横æ£ã°ã©ã」ã§ä½æããã¨、以ä¸ã®æ£ã°ã©ããæç»ããã。å ã¿ã«æ¨ªæ£ã°ã©ãã«ã¤ãã¦ã¯、X軸ã¨Y軸ãå ¥ãæ¿ããã®ã§æ³¨æãã¦æ¬²ãã。
ã¾ã、「åã°ã©ã」、「3Dåã°ã©ã」ã§ä½æããã¨ä»¥ä¸ã®åºåã«ãªã。
2ã«ã©ã ã®æ°å¤ãã¼ã¿ã¨ãã¦ä»¥ä¸ã®ãã¼ã¿ãå ¥åãã。
0.113 0.223 0.343 0.285 0.443 0.386 0.543 0.192 0.723 0.256
ããã、「æãç·ã°ã©ãXY」ã§ä½æããã¨、以ä¸ã®æãç·ã°ã©ããåºåãã。
ããã«、åããã¼ã¿ã¾ã¾、「ç©ä¸æ¨ªæ£ã°ã©ã」ãä½æ。
ããã¦、「æ£å¸å³」ã¯æ¬¡ã®ããã«ãªã。
以ä¸ã«ã½ã¼ã¹ã³ã¼ãã示ã。
# ç°¡æã°ã©ã・ãã£ã¼ãä½æ class Chart(webapp.RequestHandler): def __init__(self): self.chart_url = "" self.chart_html = "" self.chart_form = "" self.width = 300 self.height = 200 self.has_label = False self.is_trans = False self.title = "" self.color = "4d89f9,c6d9fd" self.is_clear_x = False self.is_clear_y = False self.min_x = None self.max_x = None self.step_x = None self.min_y = None self.max_y = None self.step_y = None self.html = u""" <html> <head> <link type="text/css" rel="stylesheet" href="/stylesheets/chart.css" /> <title>ç°¡æã°ã©ã・ãã£ã¼ãä½æ</title> </head> <body> <div class="NoBoxedItem"> <form action="/chart" method="post"> <div><select name="chart"> <option value="lc">æãç·ã°ã©ã X</option> <option value="lxy">æãç·ã°ã©ã XY</option> <option value="ls">ã¹ãã¼ã¯ã©ã¤ã³</option> <option value="bhs">ç©ä¸æ¨ªæ£ã°ã©ã</option> <option value="bvs">ç©ä¸ç¸¦æ£ã°ã©ã</option> <option value="bhg">éå横æ£ã°ã©ã</option> <option value="bvg">éå縦æ£ã°ã©ã</option> <option value="p">åã°ã©ã</option> <option value="p3">3Dåã°ã©ã</option> <option value="s">æ£å¸å³</option> </select> å¹ :<input type="text" name="width" size="4" value="%d"></text> é«ã:<input type="text" name="height" size="4" value="%d"></text></div> <div>ã¿ã¤ãã«: <input type="text" name="title" size="40" value="%s"></text></div> <div><textarea name="content" rows="10" cols="60">%s</textarea></div> <div>X (ã¯ãªã¢<input type="checkbox" name="clear_x" value="clear_x" />): ä¸é:<input type="text" name="min_x" size="3" value="%s"></text> ä¸é:<input type="text" name="max_x" size="3" value="%s"> åå²:<input type="text" name="step_x" size="2" value="%s"></div> <div>Y (ã¯ãªã¢<input type="checkbox" name="clear_y" value="clear_y" />): ä¸é:<input type="text" name="min_y" size="3" value="%s"></text> ä¸é:<input type="text" name="max_y" size="3" value="%s"> åå²:<input type="text" name="step_y" size="2" value="%s"></div> <div>è²: <input type="text" name="color" size="40" value="%s"></text></div> <div><input type="submit" value="ä½æ" /> <input type="checkbox" name="label" value="label" />ã©ãã« <input type="checkbox" name="trans" value="trans" />転置 <span><a href="./chart" onclick="window.open('./chart'); return false;">æ°è¦</a> <a href="http://handasse.blogspot.com/2009/07/google-app-engine.html" onclick="window.open('http://handasse.blogspot.com/2009/07/google-app-engine.html'); return false;">ãã«ã</a></span></div> </form> </div> <div class="NoBoxedItem"> %s %s </div> <div class="Contents"><span style="font-size:x-small;color:#666666;">Copyright © 2009 <a href="http://handasse.blogspot.com/">nox</a>. All rights reserved.</span></div> </body> </html>""" def get(self): self.response.out.write(self.html % (self.width, self.height, "", "", "", "", "", "", "", "", self.color, "", "")) def get_scale(self, min_data, max_data, axis): stepsize_log = math.log10(max_data - min_data) stepsize = 10**int(stepsize_log) if stepsize_log < 0: stepsize = Decimal(str(stepsize)) * Decimal("0.1") scalesize = float(Decimal("100") / stepsize) stepsize = float(stepsize) else: scalesize = 1 min_scale = min_data // stepsize * stepsize redun = 1 if Decimal(str(max_data)) % Decimal(str(stepsize)) == Decimal("0"): redun = 0 max_scale = float((Decimal("%.10f" % max_data) // Decimal("%.10f" % stepsize) + redun) * Decimal("%.10f" % stepsize)) if stepsize_log >= 0 and stepsize_log == int(stepsize_log): stepsize *= 0.1 if stepsize < 1: scalesize = 100.0 / stepsize if axis == "x": if self.is_clear_x or self.min_x == None or self.max_x == None or self.step_x == None: self.min_x = min_scale self.max_x = max_scale self.step_x = int(Decimal(str(max_scale - min_scale)) / Decimal(str(stepsize))) else: min_scale = self.min_x max_scale = self.max_x stepsize = float(Decimal(str(max_scale - min_scale)) / Decimal(str(self.step_x))) if stepsize < 1: scalesize = 100.0 / stepsize elif axis == "y": if self.is_clear_y or self.min_y == None or self.max_y == None or self.step_y == None: self.min_y = min_scale self.max_y = max_scale self.step_y = int(Decimal(str(max_scale - min_scale)) / Decimal(str(stepsize))) else: min_scale = self.min_y max_scale = self.max_y stepsize = float(Decimal(str(max_scale - min_scale)) / Decimal(str(self.step_y))) if stepsize < 1: scalesize = 100.0 / stepsize return min_scale, max_scale, stepsize, scalesize def post(self): try: content = cgi.escape(self.request.get('content')) cht = cgi.escape(self.request.get('chart')) self.width = int(cgi.escape(self.request.get('width'))) self.height = int(cgi.escape(self.request.get('height'))) self.title = cgi.escape(self.request.get('title')).strip() if self.title: chtt = "&chtt=%s" % self.title.replace(" ", "+") else: chtt = "" min_x = cgi.escape(self.request.get('min_x')) if min_x: self.min_x = float(min_x) max_x = cgi.escape(self.request.get('max_x')) if max_x: self.max_x = float(max_x) step_x = cgi.escape(self.request.get('step_x')) if step_x: self.step_x = int(step_x) min_y = cgi.escape(self.request.get('min_y')) if min_y: self.min_y = float(min_y) max_y = cgi.escape(self.request.get('max_y')) if max_y: self.max_y = float(max_y) step_y = cgi.escape(self.request.get('step_y')) if step_y: self.step_y = int(step_y) self.color = cgi.escape(self.request.get('color')).replace(" ", "") if self.request.get('clear_x') == 'clear_x': self.is_clear_x = True if self.request.get('clear_y') == 'clear_y': self.is_clear_y = True if self.request.get('label') == 'label': self.has_label = True else: self.has_label = False if self.request.get('trans') == 'trans': self.is_trans = True else: self.is_trans = False if content: lines = [x.strip().replace(",", " ").replace("\t", " ") for x in content.rstrip().split("\n")] sdata = [[d for d in l.split()] for l in lines] if not self.is_trans: sdata = map(list, zip(*sdata)) if self.has_label: labels = sdata[0] sdata = sdata[1:] data = [[float(d) for d in sd] for sd in sdata] if cht == "lxy" or cht == "s": min_data_x, max_data_x = data[0][0], data[0][0] d = data[0] min_data_x, max_data_x = min(min_data_x, min(d)), max(max_data_x, max(d)) min_scale_x, max_scale_x, stepsize_x, scalesize_x = self.get_scale(min_data_x, max_data_x, "x") min_data_y, max_data_y = data[1][0], data[1][0] d = data[1] min_data_y, max_data_y = min(min_data_y, min(d)), max(max_data_y, max(d)) min_scale_y, max_scale_y, stepsize_y, scalesize_y = self.get_scale(min_data_y, max_data_y, "y") min_data_x, max_data_x = "%f" % min_scale_x, "%f" % max_scale_x min_data_y, max_data_y = "%f" % min_scale_y, "%f" % max_scale_y elif cht == "bhs" or cht == "bvs": tdata = map(sum, map(list, zip(*data))) min_data_y, max_data_y = tdata[0], tdata[0] for d in tdata: min_data_y, max_data_y = min(min_data_y, d), max(max_data_y, d) min_data_y = 0 min_scale_y, max_scale_y, stepsize_y, scalesize_y = self.get_scale(min_data_y, max_data_y, "y") min_data_y, max_data_y = "%f" % min_scale_y, "%f" % max_scale_y else: min_data_y, max_data_y = data[0][0], data[0][0] for d in data: min_data_y, max_data_y = min(min_data_y, min(d)), max(max_data_y, max(d)) if cht == "bhg" or cht == "bvg" or cht == "p" or cht == "p3": min_data_y = 0 min_scale_y, max_scale_y, stepsize_y, scalesize_y = self.get_scale(min_data_y, max_data_y, "y") min_data_y, max_data_y = "%f" % min_scale_y, "%f" % max_scale_y sdata = [",".join(d) for d in sdata] chd = "t:" + "|".join(sdata) if cht == "lxy" or cht == "s": chds = "%s,%s,%s,%s" % (min_data_x.rstrip("0").rstrip("."), max_data_x.rstrip("0").rstrip("."), min_data_y.rstrip("0").rstrip("."), max_data_y.rstrip("0").rstrip(".")) else: chds = "%s,%s" % (min_data_y.rstrip("0").rstrip("."), max_data_y.rstrip("0").rstrip(".")) chco = self.color if cht == "bhg" or cht == "bhs": if self.has_label: chxt = "x,y" chxl = "0:|" + "|".join([str(n / scalesize_y) for n in range(int(min_scale_y * scalesize_y), int(max_scale_y * scalesize_y) + 1, int(stepsize_y * scalesize_y))]) chxl += "|1:|" + "|".join(labels) else: chxt = "x" chxl = "0:|" + "|".join([str(n / scalesize_y) for n in range(int(min_scale_y * scalesize_y), int(max_scale_y * scalesize_y) + 1, int(stepsize_y * scalesize_y))]) elif cht == "lxy" or cht == "s": chxt = "x,y" chxl = "0:|" + "|".join([str(n / scalesize_x) for n in range(int(min_scale_x * scalesize_x), int(max_scale_x * scalesize_x) + 1, int(stepsize_x * scalesize_x))]) chxl += "|1:|" + "|".join([str(n / scalesize_y) for n in range(int(min_scale_y * scalesize_y), int(max_scale_y * scalesize_y) + 1, int(stepsize_y * scalesize_y))]) elif cht == "p" or cht == "p3": if self.has_label: chxt = "x" chxl = "0:|" + "|".join(labels) else: chxt = "" chxl = "" else: if self.has_label: chxt = "y,x" chxl = "0:|" + "|".join([str(n / scalesize_y) for n in range(int(min_scale_y * scalesize_y), int(max_scale_y * scalesize_y) + 1, int(stepsize_y * scalesize_y))]) chxl += "|1:|" + "|".join(labels) else: chxt = "y" chxl = "0:|" + "|".join([str(n / scalesize_y) for n in range(int(min_scale_y * scalesize_y), int(max_scale_y * scalesize_y) + 1, int(stepsize_y * scalesize_y))]) self.chart_url = "http://chart.apis.google.com/chart?chs=%dx%d&chd=%s&chds=%s&cht=%s&chco=%s&chxt=%s&chxl=%s%s" % (self.width, self.height, chd, chds, cht, chco, chxt, chxl, chtt) self.chart_html = '<div><img src="%s" /></div>' % self.chart_url self.chart_form = u""" <form name="form" action="/chart" method="post"> <div><textarea name="content" rows="5" cols="60">%s</textarea></div> <div><input type="button" onclick="document.form.content.select()" value="é¸æ" /></div> </form>""" % self.chart_url if self.min_x == None or self.max_x == None or self.step_x == None: min_x = max_x = step_x = "" else: min_x, max_x, step_x = (str(self.min_x), str(self.max_x), str(self.step_x)) if self.min_y == None or self.max_y == None or self.step_y == None: min_y = max_y = step_y = "" else: min_y, max_y, step_y = (str(self.min_y), str(self.max_y), str(self.step_y)) if self.has_label: self.html = self.html.replace(u"label\"", u"label\" checked") if self.is_trans: self.html = self.html.replace(u"trans\"", u"trans\" checked") self.response.out.write(self.html.replace("\"%s\"" % cht, "\"%s\" selected" % cht) % (self.width, self.height, self.title, content, min_x, max_x, step_x, min_y, max_y, step_y, self.color, self.chart_html, self.chart_form)) except: self.response.out.write(self.html.replace(u"\"%s\"" % cht, u"\"%s\" selected" % cht) % (self.width, self.height, self.title, content, min_x, max_x, step_x, min_y, max_y, step_y, self.color, u"ã¨ã©ã¼ãçºçãã¾ãã。ãã¼ã¿ããã³è¨å®ã確èªãã¦ãã ãã。", ""))
å³å¸ã§ä½æããã¦ã§ãã¢ããªãªã®ã§ä¸åãªç¹ãããã、åãæ¢ããèªåã§ä½¿ãåã«ã¯ãã®ç¨åº¦ã§ååãªã®ã§GAEã«ç»é²ãã¦ããã。æ°ãåãããæ©è½ãæ¡å¼µãã¦ãããããããªã。
以ä¸ã«ä½¿ãæ¹ã示ã。
使ãæ¹
ã¾ã、以ä¸ã®ãã¼ã¿ãããã¹ãã¨ãªã¢ã«å ¥ãã¦ã¿ã。
1.2 2.2 3.5 5.6 2.8
次ã«、「ä½æ」ãã¿ã³ãæ¼ã。ãã£ã¼ãã®ç¨®é¡ã「æãç·ã°ã©ãX」ã«ãªã£ã¦ããã°、å ¥åãã¼ã¿ããã¨ã«ä»¥ä¸ã®ãããªã°ã©ããæããã。
ã°ã©ãã®X軸、Y軸ã®ä¸éã¨ä¸é、ããã³ãã®ç®çãåå²ã¯èªåã§è¡ããã。ãã¡ãã、æåã§ã®è¨å®ãã§ããã、èªåã§è¨å®ãããæ°å¤ãä¿®æ£ãããã¨ãå¯è½ã 。ã¾ã、åºåç»åãã¡ã¤ã«ã®å¤§ããã、ã°ã©ãã®è²(16é²æ°6æ¡[RGB]ã§è¡¨ç¤º)ãå¤æ´ã§ãã。ã¿ã¤ãã«ã表示ããããã°ã¿ã¤ãã«æ¬ã«å ¥åããã°ãã。å ã¿ã«ã¿ã¤ãã«ãæ¹è¡ãããã«ã¯ | ãå ¥ãã。ããã«、ä¸è¨ã®ãããªGoogle Chart APIã«ããURLã表示ããããã«ãã。ãã®URLãç»åURLã¨ãã¦ããã°ãªã©ã§å©ç¨ããã°、ä¸ã®ã°ã©ãã表示ãããã®ãç°¡åã 。
http://chart.apis.google.com/chart?chs=300x200&chd=t:1.2,2.2,3.5,5.6,2.8&chds=1,6&cht=lc&chco=4d89f9,c6d9fd&chxt=y&chxl=0:|1|2|3|4|5|6
ç¾æç¹ã§å©ç¨ã§ããã°ã©ãã®ç¨®é¡ã¯、「æãç·ã°ã©ãX」、「æãç·ã°ã©ãXY」、「ã¹ãã¼ã¯ã©ã¤ã³」、「ç©ä¸æ¨ªæ£ã°ã©ã」、「ç©ä¸ç¸¦æ£ã°ã©ã」、「éå横æ£ã°ã©ã」、「éå縦æ£ã°ã©ã」、「åã°ã©ã」、「3Dåã°ã©ã」、「æ£å¸å³」ã®10種é¡ã 。2ã«ã©ã 以ä¸ã®ãã¼ã¿ãå¿ è¦ãªã°ã©ãã¯、「æãç·ã°ã©ãXY」ã¨「æ£å¸å³」ã§、ã»ãã¯1ã«ã©ã 以ä¸ã®ãã¼ã¿ã¨ãªã。ã¾ã、「転置」ãã§ãã¯ããã¯ã¹ã«ãã§ãã¯ãå ¥ããã¨è¡ã¨åãå ¥ãæ¿ãããã¨ãã§ã、「ã©ãã«」ãã§ãã¯ããã¯ã¹ã«ãã§ãã¯ãå ¥ããã¨、å ¥åãã¼ã¿ã®1ã«ã©ã ç®ãã©ãã«ã¨ãªã。ã©ãã«å ã«ç©ºç½ãå ¥ãããå ´åã¯、空ç½ã+ã«ç½®ãæãããã¨。
ãã¼ã¿A 0.113 ãã¼ã¿B 0.243 ãã¼ã¿C 0.543 ãã¼ã¿D 0.443
ä¸è¨ã®ãã¼ã¿ãå ¥åã、「éå横æ£ã°ã©ã」ã§ä½æããã¨、以ä¸ã®æ£ã°ã©ããæç»ããã。å ã¿ã«æ¨ªæ£ã°ã©ãã«ã¤ãã¦ã¯、X軸ã¨Y軸ãå ¥ãæ¿ããã®ã§æ³¨æãã¦æ¬²ãã。
ã¾ã、「åã°ã©ã」、「3Dåã°ã©ã」ã§ä½æããã¨ä»¥ä¸ã®åºåã«ãªã。
2ã«ã©ã ã®æ°å¤ãã¼ã¿ã¨ãã¦ä»¥ä¸ã®ãã¼ã¿ãå ¥åãã。
0.113 0.223 0.343 0.285 0.443 0.386 0.543 0.192 0.723 0.256
ããã、「æãç·ã°ã©ãXY」ã§ä½æããã¨、以ä¸ã®æãç·ã°ã©ããåºåãã。
ããã«、åããã¼ã¿ã¾ã¾、「ç©ä¸æ¨ªæ£ã°ã©ã」ãä½æ。
ããã¦、「æ£å¸å³」ã¯æ¬¡ã®ããã«ãªã。
以ä¸ã«ã½ã¼ã¹ã³ã¼ãã示ã。
# ç°¡æã°ã©ã・ãã£ã¼ãä½æ class Chart(webapp.RequestHandler): def __init__(self): self.chart_url = "" self.chart_html = "" self.chart_form = "" self.width = 300 self.height = 200 self.has_label = False self.is_trans = False self.title = "" self.color = "4d89f9,c6d9fd" self.is_clear_x = False self.is_clear_y = False self.min_x = None self.max_x = None self.step_x = None self.min_y = None self.max_y = None self.step_y = None self.html = u""" <html> <head> <link type="text/css" rel="stylesheet" href="/stylesheets/chart.css" /> <title>ç°¡æã°ã©ã・ãã£ã¼ãä½æ</title> </head> <body> <div class="NoBoxedItem"> <form action="/chart" method="post"> <div><select name="chart"> <option value="lc">æãç·ã°ã©ã X</option> <option value="lxy">æãç·ã°ã©ã XY</option> <option value="ls">ã¹ãã¼ã¯ã©ã¤ã³</option> <option value="bhs">ç©ä¸æ¨ªæ£ã°ã©ã</option> <option value="bvs">ç©ä¸ç¸¦æ£ã°ã©ã</option> <option value="bhg">éå横æ£ã°ã©ã</option> <option value="bvg">éå縦æ£ã°ã©ã</option> <option value="p">åã°ã©ã</option> <option value="p3">3Dåã°ã©ã</option> <option value="s">æ£å¸å³</option> </select> å¹ :<input type="text" name="width" size="4" value="%d"></text> é«ã:<input type="text" name="height" size="4" value="%d"></text></div> <div>ã¿ã¤ãã«: <input type="text" name="title" size="40" value="%s"></text></div> <div><textarea name="content" rows="10" cols="60">%s</textarea></div> <div>X (ã¯ãªã¢<input type="checkbox" name="clear_x" value="clear_x" />): ä¸é:<input type="text" name="min_x" size="3" value="%s"></text> ä¸é:<input type="text" name="max_x" size="3" value="%s"> åå²:<input type="text" name="step_x" size="2" value="%s"></div> <div>Y (ã¯ãªã¢<input type="checkbox" name="clear_y" value="clear_y" />): ä¸é:<input type="text" name="min_y" size="3" value="%s"></text> ä¸é:<input type="text" name="max_y" size="3" value="%s"> åå²:<input type="text" name="step_y" size="2" value="%s"></div> <div>è²: <input type="text" name="color" size="40" value="%s"></text></div> <div><input type="submit" value="ä½æ" /> <input type="checkbox" name="label" value="label" />ã©ãã« <input type="checkbox" name="trans" value="trans" />転置 <span><a href="./chart" onclick="window.open('./chart'); return false;">æ°è¦</a> <a href="http://handasse.blogspot.com/2009/07/google-app-engine.html" onclick="window.open('http://handasse.blogspot.com/2009/07/google-app-engine.html'); return false;">ãã«ã</a></span></div> </form> </div> <div class="NoBoxedItem"> %s %s </div> <div class="Contents"><span style="font-size:x-small;color:#666666;">Copyright © 2009 <a href="http://handasse.blogspot.com/">nox</a>. All rights reserved.</span></div> </body> </html>""" def get(self): self.response.out.write(self.html % (self.width, self.height, "", "", "", "", "", "", "", "", self.color, "", "")) def get_scale(self, min_data, max_data, axis): stepsize_log = math.log10(max_data - min_data) stepsize = 10**int(stepsize_log) if stepsize_log < 0: stepsize = Decimal(str(stepsize)) * Decimal("0.1") scalesize = float(Decimal("100") / stepsize) stepsize = float(stepsize) else: scalesize = 1 min_scale = min_data // stepsize * stepsize redun = 1 if Decimal(str(max_data)) % Decimal(str(stepsize)) == Decimal("0"): redun = 0 max_scale = float((Decimal("%.10f" % max_data) // Decimal("%.10f" % stepsize) + redun) * Decimal("%.10f" % stepsize)) if stepsize_log >= 0 and stepsize_log == int(stepsize_log): stepsize *= 0.1 if stepsize < 1: scalesize = 100.0 / stepsize if axis == "x": if self.is_clear_x or self.min_x == None or self.max_x == None or self.step_x == None: self.min_x = min_scale self.max_x = max_scale self.step_x = int(Decimal(str(max_scale - min_scale)) / Decimal(str(stepsize))) else: min_scale = self.min_x max_scale = self.max_x stepsize = float(Decimal(str(max_scale - min_scale)) / Decimal(str(self.step_x))) if stepsize < 1: scalesize = 100.0 / stepsize elif axis == "y": if self.is_clear_y or self.min_y == None or self.max_y == None or self.step_y == None: self.min_y = min_scale self.max_y = max_scale self.step_y = int(Decimal(str(max_scale - min_scale)) / Decimal(str(stepsize))) else: min_scale = self.min_y max_scale = self.max_y stepsize = float(Decimal(str(max_scale - min_scale)) / Decimal(str(self.step_y))) if stepsize < 1: scalesize = 100.0 / stepsize return min_scale, max_scale, stepsize, scalesize def post(self): try: content = cgi.escape(self.request.get('content')) cht = cgi.escape(self.request.get('chart')) self.width = int(cgi.escape(self.request.get('width'))) self.height = int(cgi.escape(self.request.get('height'))) self.title = cgi.escape(self.request.get('title')).strip() if self.title: chtt = "&chtt=%s" % self.title.replace(" ", "+") else: chtt = "" min_x = cgi.escape(self.request.get('min_x')) if min_x: self.min_x = float(min_x) max_x = cgi.escape(self.request.get('max_x')) if max_x: self.max_x = float(max_x) step_x = cgi.escape(self.request.get('step_x')) if step_x: self.step_x = int(step_x) min_y = cgi.escape(self.request.get('min_y')) if min_y: self.min_y = float(min_y) max_y = cgi.escape(self.request.get('max_y')) if max_y: self.max_y = float(max_y) step_y = cgi.escape(self.request.get('step_y')) if step_y: self.step_y = int(step_y) self.color = cgi.escape(self.request.get('color')).replace(" ", "") if self.request.get('clear_x') == 'clear_x': self.is_clear_x = True if self.request.get('clear_y') == 'clear_y': self.is_clear_y = True if self.request.get('label') == 'label': self.has_label = True else: self.has_label = False if self.request.get('trans') == 'trans': self.is_trans = True else: self.is_trans = False if content: lines = [x.strip().replace(",", " ").replace("\t", " ") for x in content.rstrip().split("\n")] sdata = [[d for d in l.split()] for l in lines] if not self.is_trans: sdata = map(list, zip(*sdata)) if self.has_label: labels = sdata[0] sdata = sdata[1:] data = [[float(d) for d in sd] for sd in sdata] if cht == "lxy" or cht == "s": min_data_x, max_data_x = data[0][0], data[0][0] d = data[0] min_data_x, max_data_x = min(min_data_x, min(d)), max(max_data_x, max(d)) min_scale_x, max_scale_x, stepsize_x, scalesize_x = self.get_scale(min_data_x, max_data_x, "x") min_data_y, max_data_y = data[1][0], data[1][0] d = data[1] min_data_y, max_data_y = min(min_data_y, min(d)), max(max_data_y, max(d)) min_scale_y, max_scale_y, stepsize_y, scalesize_y = self.get_scale(min_data_y, max_data_y, "y") min_data_x, max_data_x = "%f" % min_scale_x, "%f" % max_scale_x min_data_y, max_data_y = "%f" % min_scale_y, "%f" % max_scale_y elif cht == "bhs" or cht == "bvs": tdata = map(sum, map(list, zip(*data))) min_data_y, max_data_y = tdata[0], tdata[0] for d in tdata: min_data_y, max_data_y = min(min_data_y, d), max(max_data_y, d) min_data_y = 0 min_scale_y, max_scale_y, stepsize_y, scalesize_y = self.get_scale(min_data_y, max_data_y, "y") min_data_y, max_data_y = "%f" % min_scale_y, "%f" % max_scale_y else: min_data_y, max_data_y = data[0][0], data[0][0] for d in data: min_data_y, max_data_y = min(min_data_y, min(d)), max(max_data_y, max(d)) if cht == "bhg" or cht == "bvg" or cht == "p" or cht == "p3": min_data_y = 0 min_scale_y, max_scale_y, stepsize_y, scalesize_y = self.get_scale(min_data_y, max_data_y, "y") min_data_y, max_data_y = "%f" % min_scale_y, "%f" % max_scale_y sdata = [",".join(d) for d in sdata] chd = "t:" + "|".join(sdata) if cht == "lxy" or cht == "s": chds = "%s,%s,%s,%s" % (min_data_x.rstrip("0").rstrip("."), max_data_x.rstrip("0").rstrip("."), min_data_y.rstrip("0").rstrip("."), max_data_y.rstrip("0").rstrip(".")) else: chds = "%s,%s" % (min_data_y.rstrip("0").rstrip("."), max_data_y.rstrip("0").rstrip(".")) chco = self.color if cht == "bhg" or cht == "bhs": if self.has_label: chxt = "x,y" chxl = "0:|" + "|".join([str(n / scalesize_y) for n in range(int(min_scale_y * scalesize_y), int(max_scale_y * scalesize_y) + 1, int(stepsize_y * scalesize_y))]) chxl += "|1:|" + "|".join(labels) else: chxt = "x" chxl = "0:|" + "|".join([str(n / scalesize_y) for n in range(int(min_scale_y * scalesize_y), int(max_scale_y * scalesize_y) + 1, int(stepsize_y * scalesize_y))]) elif cht == "lxy" or cht == "s": chxt = "x,y" chxl = "0:|" + "|".join([str(n / scalesize_x) for n in range(int(min_scale_x * scalesize_x), int(max_scale_x * scalesize_x) + 1, int(stepsize_x * scalesize_x))]) chxl += "|1:|" + "|".join([str(n / scalesize_y) for n in range(int(min_scale_y * scalesize_y), int(max_scale_y * scalesize_y) + 1, int(stepsize_y * scalesize_y))]) elif cht == "p" or cht == "p3": if self.has_label: chxt = "x" chxl = "0:|" + "|".join(labels) else: chxt = "" chxl = "" else: if self.has_label: chxt = "y,x" chxl = "0:|" + "|".join([str(n / scalesize_y) for n in range(int(min_scale_y * scalesize_y), int(max_scale_y * scalesize_y) + 1, int(stepsize_y * scalesize_y))]) chxl += "|1:|" + "|".join(labels) else: chxt = "y" chxl = "0:|" + "|".join([str(n / scalesize_y) for n in range(int(min_scale_y * scalesize_y), int(max_scale_y * scalesize_y) + 1, int(stepsize_y * scalesize_y))]) self.chart_url = "http://chart.apis.google.com/chart?chs=%dx%d&chd=%s&chds=%s&cht=%s&chco=%s&chxt=%s&chxl=%s%s" % (self.width, self.height, chd, chds, cht, chco, chxt, chxl, chtt) self.chart_html = '<div><img src="%s" /></div>' % self.chart_url self.chart_form = u""" <form name="form" action="/chart" method="post"> <div><textarea name="content" rows="5" cols="60">%s</textarea></div> <div><input type="button" onclick="document.form.content.select()" value="é¸æ" /></div> </form>""" % self.chart_url if self.min_x == None or self.max_x == None or self.step_x == None: min_x = max_x = step_x = "" else: min_x, max_x, step_x = (str(self.min_x), str(self.max_x), str(self.step_x)) if self.min_y == None or self.max_y == None or self.step_y == None: min_y = max_y = step_y = "" else: min_y, max_y, step_y = (str(self.min_y), str(self.max_y), str(self.step_y)) if self.has_label: self.html = self.html.replace(u"label\"", u"label\" checked") if self.is_trans: self.html = self.html.replace(u"trans\"", u"trans\" checked") self.response.out.write(self.html.replace("\"%s\"" % cht, "\"%s\" selected" % cht) % (self.width, self.height, self.title, content, min_x, max_x, step_x, min_y, max_y, step_y, self.color, self.chart_html, self.chart_form)) except: self.response.out.write(self.html.replace(u"\"%s\"" % cht, u"\"%s\" selected" % cht) % (self.width, self.height, self.title, content, min_x, max_x, step_x, min_y, max_y, step_y, self.color, u"ã¨ã©ã¼ãçºçãã¾ãã。ãã¼ã¿ããã³è¨å®ã確èªãã¦ãã ãã。", ""))
ã³ã¡ã³ã
ãã、ãæéã®æã«ã¬ã¼ãã¼ãã£ã¼ãã
追å ãã¦ããã ãããã¨ã¦ãå¬ããã§ã。