Skip to content

Commit

Permalink
#535 implement field bounds for quick filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Aug 15, 2018
1 parent d60c4b2 commit f67afd5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions plugins/quick-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const d3 = {
var utils = Taucharts.api.utils;
var REFRESH_DELAY = 0;

function QuickFilter(xSettings) {
function QuickFilter(xSettings = {}) {

var log10 = function (x) {
return Math.log(x) / Math.LN10;
Expand Down Expand Up @@ -44,13 +44,13 @@ const d3 = {
var spec = this._chart.getSpec();
var sources = spec.sources['/'];

var fields = (xSettings && xSettings.fields || xSettings);
var fields = (xSettings.fields || xSettings);

this._fields = ((Array.isArray(fields) && fields.length > 0) ?
(fields) :
(Object.keys(sources.dims)));

this._applyImmediately = Boolean(xSettings && xSettings.applyImmediately);
this._fieldBounds = xSettings.fieldBounds || {};
this._applyImmediately = Boolean(xSettings.applyImmediately);

var chartData = self._chart.getChartModelData();

Expand All @@ -70,7 +70,13 @@ const d3 = {
self._data[dim] = chartData.map(function (x) {
return x[dim];
});
self._bounds[dim] = d3.extent(self._data[dim]);
const fieldRange = self._fieldBounds[dim];
if(fieldRange) {
self._bounds[dim] = [fieldRange.min, fieldRange.max];
} else {
self._bounds[dim] = d3.extent(self._data[dim]);
}

self._filter[dim] = self._bounds[dim];

self._filtersContainer.insertAdjacentHTML('beforeend', self._filterWrapper({name: dim}));
Expand Down

0 comments on commit f67afd5

Please sign in to comment.