From: Florian Forster Date: Wed, 22 Dec 2010 18:04:03 +0000 (+0100) Subject: share/collection.js: Add legend label formatter. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=100679c57df004d9cb816438d2339a2e6c692a45;p=collection4.git share/collection.js: Add legend label formatter. --- diff --git a/share/collection.js b/share/collection.js index 1a62f6e..05ca9ba 100644 --- a/share/collection.js +++ b/share/collection.js @@ -299,6 +299,51 @@ function instance_draw (inst, def, data_list) /* {{{ */ }, endOnTick: false }; + chart_opts.legend = + { + labelFormatter: function () + { + var series = this; + var min = Number.MAX_VALUE; + var max = Number.NEGATIVE_INFINITY; + var num = 0; + var sum = 0; + var avg; + var i; + + for (i = 0; i < this.data.length; i++) + { + var v; + + v = this.data[i].y; + if (v == null) + continue; + + if (min > v) + min = v; + if (max < v) + max = v; + + sum += v; + num++; + } + + if (num == 0) + { + min = null; + max = null; + avg = null; + } + else + { + avg = sum / num; + } + + return (this.name + " (" + value_to_string (min) + " min, " + + value_to_string (avg) + " avg, " + + value_to_string (max) + " max)"); + } + }; chart_opts.series = new Array (); if (def.title)