From 45659706727b2da138e9905e7704084927093f91 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Wed, 10 Sep 2014 12:06:40 +0100 Subject: [PATCH] add support for hidden facets in facetview, plus some minor tweaks to reportview --- jquery.facetview2.js | 18 ++++++++++++++++-- jquery.reportview.js | 12 +++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/jquery.facetview2.js b/jquery.facetview2.js index 2a4347c..a37268c 100644 --- a/jquery.facetview2.js +++ b/jquery.facetview2.js @@ -285,7 +285,8 @@ function facetList(options) { * none - no requirements for specific classes and ids * * should (not must) respect the following config - * + * + * options.facet[x].hidden - whether the facet should be displayed in the UI or not * options.render_terms_facet - renders a term facet into the list * options.render_range_facet - renders a range facet into the list * options.render_geo_facet - renders a geo distance facet into the list @@ -295,6 +296,11 @@ function facetList(options) { var thefilters = ''; for (var idx = 0; idx < filters.length; idx++) { var facet = filters[idx] + // if the facet is hidden do not include it in this list + if (facet.hidden) { + continue; + } + var type = facet.type ? facet.type : "terms" if (type === "terms") { thefilters += options.render_terms_facet(facet, options) @@ -1199,6 +1205,7 @@ function getUrlVars() { "display" : "", // display name for the UI "type": "term|range|geo_distance", // the kind of facet this will be "open" : true|false, // whether the facet should be open or closed (initially) + "hidden" : true|false // whether the facet should be displayed at all (e.g. you may just want the data for a callback) // terms facet only @@ -1241,6 +1248,7 @@ function getUrlVars() { // be initialised to the default "default_facet_type" : "terms", "default_facet_open" : false, + "default_facet_hidden" : false, "default_facet_size" : 10, "default_facet_operator" : "AND", // logic "default_facet_order" : "count", @@ -1503,6 +1511,7 @@ function getUrlVars() { var facet = provided_options.facets[i] if (!("type" in facet)) { facet["type"] = provided_options.default_facet_type } if (!("open" in facet)) { facet["open"] = provided_options.default_facet_open } + if (!("hidden" in facet)) { facet["hiddel"] = provided_options.default_facet_hidden } if (!("size" in facet)) { facet["size"] = provided_options.default_facet_size } if (!("logic" in facet)) { facet["logic"] = provided_options.default_facet_operator } if (!("order" in facet)) { facet["order"] = provided_options.default_facet_order } @@ -1551,6 +1560,9 @@ function getUrlVars() { // for each facet, set the facet size, order and and/or status for (var i=0; i < options.facets.length; i=i+1) { var f = options.facets[i] + if (f.hidden) { + continue; + } setUIFacetSize({facet : f}) setUIFacetSort({facet : f}) setUIFacetAndOr({facet : f}) @@ -2150,7 +2162,9 @@ function getUrlVars() { facet["values"] = records.slice(0, size) // set the results on the page - setUIFacetResults(facet) + if (!facet.hidden) { + setUIFacetResults(facet) + } } // set the facet visibility diff --git a/jquery.reportview.js b/jquery.reportview.js index 05f593d..7b7dc84 100644 --- a/jquery.reportview.js +++ b/jquery.reportview.js @@ -138,7 +138,7 @@ function renderPie(params) { var transition_duration = options.pie_transition_duration // set the space up for the new chart - $(selector, context).empty() + //$(selector).empty() // generate the pie nv.addGraph(function() { @@ -183,12 +183,14 @@ function renderMultiBar(params) { var y_tick_format = params.multibar_y_tick_format var transition_duration = params.multibar_transition_duration + var controls = options.multibar_controls // set the space up for the new chart - $(selector, context).empty() + //$(selector).empty() nv.addGraph(function() { var chart = nv.models.multiBarChart() + .showControls(controls) chart.yAxis .tickFormat(d3.format(y_tick_format)); @@ -219,7 +221,10 @@ function renderHorizontalMultiBar(params) { var controls = options.horizontal_multibar_controls var y_tick_format = options.horizontal_multibar_y_tick_format var transition_duration = options.horizontal_multibar_transition_duration - + + // set the space up for the new chart + //$(selector).empty() + nv.addGraph(function() { var chart = nv.models.multiBarHorizontalChart() .x(function(d) { return d.label }) @@ -272,6 +277,7 @@ function renderHorizontalMultiBar(params) { "multibar_convert" : convertMultiBar, "multibar_y_tick_format" : ',.0f', "multibar_transition_duration" : 500, + "multibar_controls" : false, // convert/render functions for horizontal bar chart "horizontal_multibar_render" : renderHorizontalMultiBar,