summaryrefslogtreecommitdiff
path: root/public/js/mv/chart.js
diff options
context:
space:
mode:
authorFreeyorp <TheFreeYorp@NOSPAM.G.m.a.i.l.replace>2013-05-28 16:52:10 +1200
committerFreeyorp <TheFreeYorp@NOSPAM.G.m.a.i.l.replace>2013-05-28 16:52:10 +1200
commitd7634e357e7410484d1e31f3db84fb4f51fdc9c7 (patch)
treeb58542b94f2963f167c250b209362f2ec6f7f716 /public/js/mv/chart.js
parent919ac3f8297f5b5b14809471a5c0f140859e2fa0 (diff)
downloadmanavis-brushable-trellis.tar.gz
manavis-brushable-trellis.tar.bz2
manavis-brushable-trellis.tar.xz
manavis-brushable-trellis.zip
Trellis external filtering and broadcastingbrushable-trellis
This also adjusts the method for comparing filters, allowing a chart to define a "filterCompare" method that will be used to compare filters if available. This finally removes the date chart special case for setting filters. Array instance checking will now use foo instanceof Array instead of typeof(foo) == "array", which was unreliable (sometimes it's "object"). Trellis chart brush containers will now redraw the brush when set externally. renderBrush no longer takes brushG as a parameter. I'm not sure what I was thinking when I made it so. The deselected area will not yet fade. The trellis chart still requires substantial refactoring and consistency fixes; I'm not sure that the parameter specifications are currently correct.
Diffstat (limited to 'public/js/mv/chart.js')
-rw-r--r--public/js/mv/chart.js44
1 files changed, 43 insertions, 1 deletions
diff --git a/public/js/mv/chart.js b/public/js/mv/chart.js
index d2eedd4..ebb62da 100644
--- a/public/js/mv/chart.js
+++ b/public/js/mv/chart.js
@@ -14,6 +14,21 @@ var mv = function(mv) {
.xUnits(d3.time.hours)
.xAxisPadding(2)
;
+ mv.charts.date.filterCompare = function(l, r) {
+ return ((l instanceof Date) ? l : new Date(l))
+ == ((r instanceof Date) ? r : new Date(r));
+ };
+ // Remember the old date filter
+ // FIXME: Find a more elegant way to do this
+ var innerDateFilter = mv.charts.date.filter;
+ mv.charts.date.filter = function(_) {
+ if (!arguments.length) return innerDateFilter();
+ if (!_) return innerDateFilter(_);
+ _ = _ instanceof Array
+ ? _.map(function(d) { return d instanceof Date ? d : new Date(d); })
+ : (_ instanceof Date ? _ : new Date(_));
+ return innerDateFilter(_);
+ }
/* dc's default date format is M/D/Y, which is confusing and not ISO 8901 */
dc.dateFormat = d3.time.format("%Y-%m-%d %H:%M");
mv.charts.blvl = bar(monoGroup(med(dc.barChart("#blvl-chart")), "blvl"))
@@ -52,7 +67,34 @@ var mv = function(mv) {
.title(function(d) { return "Map " + d.key + ":" + d.value.r; })
.renderTitle(true)
;
- mv.charts.stats = trellisChart("#stat-chart", ["str", "agi", "vit", "dex", "int", "luk"].map(function(d) { mv.heap[d].name = d; return mv.heap[d]; }));
+ var attrs = ["str", "agi", "vit", "dex", "int", "luk"];
+ mv.charts.stats = trellisChart("#stat-chart", attrs.map(function(d) { mv.heap[d].name = d; return mv.heap[d]; }));
+ mv.charts.stats.filterCompare = function(l, r) {
+ /* Compare each attribute in turn. FIXME: Duplicated code with connect.js */
+ if (l == null && r == null)
+ return true;
+ if (l == null || r == null)
+ return false;
+ for (var key in attrs) {
+ var attr = attrs[key];
+ if (attr in l && attr in r) {
+ if (l[attr] instanceof Array) {
+ /* Range filter */
+ if (!(r[attr] instanceof Array)
+ || l[attr][0] != r[attr][0]
+ || l[attr][1] != r[attr][1]) {
+ return false;
+ }
+ } else if ((r[attr] instanceof Array) || l[attr] != r[attr]) {
+ /* Exact filter */
+ return false;
+ }
+ } else if (attr in l || attr in r) {
+ return false;
+ }
+ }
+ return true;
+ }
mv.charts.type.filter("KILLXP");
var killxpShown = true;
var killxpCharts = d3.select("#killxp-charts");