summaryrefslogtreecommitdiff
path: root/public/js/mv
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
parent919ac3f8297f5b5b14809471a5c0f140859e2fa0 (diff)
downloadmanavis-d7634e357e7410484d1e31f3db84fb4f51fdc9c7.tar.gz
manavis-d7634e357e7410484d1e31f3db84fb4f51fdc9c7.tar.bz2
manavis-d7634e357e7410484d1e31f3db84fb4f51fdc9c7.tar.xz
manavis-d7634e357e7410484d1e31f3db84fb4f51fdc9c7.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')
-rw-r--r--public/js/mv/chart.js44
-rw-r--r--public/js/mv/connect.js26
2 files changed, 56 insertions, 14 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");
diff --git a/public/js/mv/connect.js b/public/js/mv/connect.js
index 6f3101f..a17febb 100644
--- a/public/js/mv/connect.js
+++ b/public/js/mv/connect.js
@@ -105,30 +105,30 @@ var mv = function(mv) {
/* See if there's any difference - if there isn't, don't update. */
var change = false;
var key;
+ function filterCompare(key, l, r) {
+ return ("filterCompare" in mv.charts[key]) ? mv.charts[key].filterCompare(l, r) : l == r;
+ }
/* Check for keys in the filters to apply which are not in our charts. */
for (key in filters) {
- if (key == "date") {
- /*
- * Special case! FIXME: Find a more elegant way to handle this
- */
- filters[key][0] = new Date(filters[key][0]);
- filters[key][1] = new Date(filters[key][1]);
- }
if (!(key in mv.charts))
continue;
- var filter = mv.charts[key].filter();
- if (typeof(filter) == "array") {
+ /* The two filters to compare. */
+ var l = mv.charts[key].filter();
+ var r = filters[key];
+ if (l instanceof Array) {
/* Crossfilter uses arrays to filter ranges. Exactly the first two elements are significant. */
- if (filter[0] == filters[key][0] &&
- filter[1] == filters[key][1]) {
+ if ((r instanceof Array)
+ && filterCompare(key, l[0], r[0])
+ && filterCompare(key, l[1], r[1])) {
continue;
}
- } else if (filter == filters[key]) {
+ } else if (!(r instanceof Array) && filterCompare(key, l, r)) {
+ /* Exact filter */
continue;
}
/* This filter differs. Apply it. */
change = true;
- mv.charts[key].filter(filters[key]);
+ mv.charts[key].filter(r);
}
/* Check for keys in our charts which are not in the filters to apply. */
for (key in mv.charts) {