Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/fixtures/mock_ui_state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
define(function (require) {
var _ = require('lodash');
var keys = {};
return {
get: function (path, def) {
return keys[path] == null ? def : keys[path];
},
set: function (path, val) {
keys[path] = val;
return val;
},
on: _.noop,
off: _.noop
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@
Show Tooltip
</label>
</div>
<div class="vis-option-item">
<label>
<input type="checkbox" ng-model="vis.params.addLegend">
Show Legend
</label>
</div>
</div>
3 changes: 2 additions & 1 deletion src/plugins/table_vis/public/__tests__/_table_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ describe('Integration', function () {

$rootScope.vis = vis;
$rootScope.esResponse = esResponse;
$el = $('<visualize vis="vis" es-resp="esResponse">');
$rootScope.uiState = require('fixtures/mock_ui_state');
$el = $('<visualize vis="vis" es-resp="esResponse" ui-state="uiState">');
$compile($el)($rootScope);
$rootScope.$apply();

Expand Down
27 changes: 14 additions & 13 deletions src/ui/public/filter_bar/filter_bar_click_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@ define(function (require) {
var _ = require('lodash');
var dedupFilters = require('./lib/dedupFilters');
var uniqFilters = require('./lib/uniqFilters');

// given an object or array of objects, return the value of the passed param
// if the param is missing, return undefined
function findByParam(values, param) {
if (_.isArray(values)) { // point series chart
var index = _.findIndex(values, param);
if (index === -1) return;
return values[index][param];
}
return values[param]; // pie chart
}
var findByParam = require('ui/utils/find_by_param');

return function (Notifier) {
return function ($state) {
return function (event) {
return function (event, simulate) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added simulate so you can check whether or not a filter would be created by this function. Allows us to check if we should display the filter buttons without reimplementing all of the logic in this file somewhere else.

var notify = new Notifier({
location: 'Filter bar'
});
Expand Down Expand Up @@ -58,9 +48,20 @@ define(function (require) {

if (!filters.length) return;

if (event.negate) {
_.each(filters, function (filter) {
filter.meta = filter.meta || {};
filter.meta.negate = true;
});
}

filters = dedupFilters($state.filters, uniqFilters(filters));
// We need to add a bunch of filter deduping here.
$state.$newFilters = filters;
if (!simulate) {
$state.$newFilters = filters;
}

return filters;
}
};
};
Expand Down
13 changes: 13 additions & 0 deletions src/ui/public/utils/find_by_param.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
define(function (require) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled this out of src/ui/public/filter_bar/filter_bar_click_handler.js into a utils/ function so it could be reused.

var _ = require('lodash');
// given an object or array of objects, return the value of the passed param
// if the param is missing, return undefined
return function findByParam(values, param) {
if (_.isArray(values)) { // point series chart
var index = _.findIndex(values, param);
if (index === -1) return;
return values[index][param];
}
return values[param]; // pie chart
};
});
1 change: 0 additions & 1 deletion src/ui/public/vislib/__tests__/lib/layout/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ dateHistogramArray.forEach(function (data, i) {
expect($(vis.el).find('.vis-wrapper').length).to.be(1);
expect($(vis.el).find('.y-axis-col-wrapper').length).to.be(1);
expect($(vis.el).find('.vis-col-wrapper').length).to.be(1);
expect($(vis.el).find('.legend-col-wrapper').length).to.be(1);
expect($(vis.el).find('.y-axis-col').length).to.be(1);
expect($(vis.el).find('.y-axis-title').length).to.be(1);
expect($(vis.el).find('.y-axis-div-wrapper').length).to.be(1);
Expand Down
129 changes: 0 additions & 129 deletions src/ui/public/vislib/__tests__/lib/legend.js

This file was deleted.

15 changes: 2 additions & 13 deletions src/ui/public/vislib/lib/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,8 @@ define(function (require) {
*/
Dispatch.prototype.highlightLegend = function (element) {
var label = this.getAttribute('data-label');

if (!label) return;

d3.select(element)
.select('.legend-ul')
.selectAll('li.color')
.filter(function (d, i) {
return String(d.label) !== label;
})
.classed('blur_shape', true);
$('[data-label]', element.parentNode).not('[data-label="' + label + '"]').css('opacity', 0.5);
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the legend isn't part of the Vis object now, rather the visualize directive, we need to get at the parent to make this work. Css selectors and Jquery make this a bit more concise

/**
Expand All @@ -245,10 +237,7 @@ define(function (require) {
* @method unHighlightLegend
*/
Dispatch.prototype.unHighlightLegend = function (element) {
d3.select(element)
.select('.legend-ul')
.selectAll('li.color')
.classed('blur_shape', false);
$('[data-label]', element.parentNode).css('opacity', 1);
};

/**
Expand Down
12 changes: 0 additions & 12 deletions src/ui/public/vislib/lib/handler/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ define(function (require) {

var Data = Private(require('ui/vislib/lib/data'));
var Layout = Private(require('ui/vislib/lib/layout/layout'));
var Legend = Private(require('ui/vislib/lib/legend'));

/**
* Handles building all the components of the visualization
Expand Down Expand Up @@ -39,15 +38,10 @@ define(function (require) {
this.axisTitle = opts.axisTitle;
this.alerts = opts.alerts;

if (this._attr.addLegend) {
this.legend = opts.legend;
}

this.layout = new Layout(vis.el, vis.data, vis._attr.type, opts);
this.binder = new Binder();
this.renderArray = _.filter([
this.layout,
this.legend,
this.axisTitle,
this.chartTitle,
this.alerts,
Expand Down Expand Up @@ -96,12 +90,6 @@ define(function (require) {

this._validateData();
this.renderArray.forEach(function (property) {
if (property instanceof Legend) {
self.vis.activeEvents().forEach(function (event) {
self.enable(event, property);
});
}

if (typeof property.render === 'function') {
property.render();
}
Expand Down
2 changes: 0 additions & 2 deletions src/ui/public/vislib/lib/handler/types/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ define(function (require) {
return function PieHandler(Private) {
var Handler = Private(require('ui/vislib/lib/handler/handler'));
var Data = Private(require('ui/vislib/lib/data'));
var Legend = Private(require('ui/vislib/lib/legend'));
var ChartTitle = Private(require('ui/vislib/lib/chart_title'));

/*
Expand All @@ -11,7 +10,6 @@ define(function (require) {

return function (vis) {
return new Handler(vis, {
legend: new Legend(vis),
chartTitle: new ChartTitle(vis.el)
});
};
Expand Down
2 changes: 0 additions & 2 deletions src/ui/public/vislib/lib/handler/types/point_series.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ define(function (require) {
var injectZeros = Private(require('ui/vislib/components/zero_injection/inject_zeros'));
var Handler = Private(require('ui/vislib/lib/handler/handler'));
var Data = Private(require('ui/vislib/lib/data'));
var Legend = Private(require('ui/vislib/lib/legend'));
var XAxis = Private(require('ui/vislib/lib/x_axis'));
var YAxis = Private(require('ui/vislib/lib/y_axis'));
var AxisTitle = Private(require('ui/vislib/lib/axis_title'));
Expand All @@ -29,7 +28,6 @@ define(function (require) {

return new Handler(vis, {
data: data,
legend: new Legend(vis, vis.data),
axisTitle: new AxisTitle(vis.el, data.get('xAxisLabel'), data.get('yAxisLabel')),
chartTitle: new ChartTitle(vis.el),
xAxis: new XAxis({
Expand Down
4 changes: 0 additions & 4 deletions src/ui/public/vislib/lib/layout/types/column_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ define(function (require) {
]
}
]
},
{
type: 'div',
class: 'legend-col-wrapper'
}
]
}
Expand Down
Loading