Skip to content

Commit

Permalink
Merge pull request #543 from TargetProcess/#535_implement_field_bound…
Browse files Browse the repository at this point in the history
…s_settings

#535 implement field bounds for quick filter
  • Loading branch information
Mavrin authored Aug 15, 2018
2 parents d60c4b2 + 4de1e34 commit ccddebb
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 fieldBound = self._fieldBounds[dim];
if(fieldBound) {
self._bounds[dim] = [fieldBound.min, fieldBound.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 ccddebb

Please sign in to comment.