func test(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") //fmt.Fprint(w, util.PrintMap(util.Map_example_right)) // vector max values vMaxVal := []float64{5555.0094, 9400, 0.0094, 1.0, 110.94, 120, 0.00001233} scale_test := Scale_x_vm for _, mv := range vMaxVal { optScale, _, _ := BestScale(mv, scale_test) floatFormat, exp := practicalFormat(mv) funcSpanner := util.GetSpanner() fmt.Fprintf(w, "optimal scale for "+floatFormat+" (exp %d) is <br>", mv, exp) for tick, val := range optScale { dis1 := fmt.Sprint(tick) dis2 := fmt.Sprintf("%s<br>", val) next_idx := tick + 1 if next_idx > len(optScale)-1 { next_idx = len(optScale) - 1 } if util.Stof(val) <= mv && mv <= util.Stof(optScale[next_idx]) { dis2 = fmt.Sprintf("<b>%s</b> <br>", val) } //dis4a := fmt.Sprintf(" %f <= "+floatFormat+" && "+floatFormat+" < %f<br>", util.Stof(val),mv,mv, util.Stof(optScale[next_idx]) ) //fmt.Fprintf(w,funcSpanner(dis4a,433) ) fmt.Fprintf(w, funcSpanner(" ", 64)) fmt.Fprintf(w, funcSpanner(dis1, 120)) fmt.Fprintf(w, funcSpanner(dis2, 233)) fmt.Fprintf(w, "<br>") } //fmt.Fprintf(w,"key %v - pot %v <br> %v",key,pot,msg) fmt.Fprintf(w, "<br>") } fmt.Fprintf(w, printScale(Scale_y_vm)) fmt.Fprintf(w, printScale(Scale_x_vm)) }
// display Legend func disLegend(w http.ResponseWriter, r *http.Request) (b1 *bytes.Buffer, m map[string]string) { //c := appengine.NewContext(r) b1 = new(bytes.Buffer) m = make(map[string]string) cd1 := GetChartDataFromDatastore(w, r, "chart_data_01") cd := *cd1 span := util.GetSpanner() widthLabel := 80 widthColorBox := 120 widthDiv := widthLabel + widthColorBox + 2*4 b1.WriteString(f("<div style='width:%dpx;margin:4px; padding: 4px; line-height:140%%; background-color:#eee;'>", widthDiv)) for langIndex, lang := range cd.VLangs { gci := langIndex % len(colors.GraphColors) // graph color index // %x is the hex format, %2.2x makes padding zeros col := f("%2.2x%2.2x%2.2x", colors.GraphColors[gci][0], colors.GraphColors[gci][1], colors.GraphColors[gci][2]) b1.WriteString(span(lang, widthLabel)) block := f("<div style='display:inline-block;width:%dpx;height:5px; background-color:%s;'></div>", widthColorBox, col) b1.WriteString(span(block, widthColorBox)) b1.WriteString("<br>") m[lang] = col } b1.WriteString("</div>") return }
func showAsTable(w http.ResponseWriter, r *http.Request, m map[string]interface{}) { cd1 := GetChartDataFromDatastore(w, r, "chart_data_01") cd := *cd1 span := util.GetSpanner() // Header row fmt.Fprintf(w, span(" ", 164)) for _, lg := range cd.VLangs { fmt.Fprintf(w, span(lg, 88)) } fmt.Fprintf(w, "<br>") for _, period := range cd.VPeriods { fmt.Fprintf(w, span(period, 164)) for _, lg := range cd.VLangs { fmt.Fprintf(w, span(cd.M[period][lg], 88)) } fmt.Fprintf(w, "<br>") } }