Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes opacity issue in area charts (overlaping) and harmonize the behavior with other charts #6346

Merged
merged 8 commits into from
Mar 8, 2016
23 changes: 16 additions & 7 deletions src/ui/public/vislib/lib/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,17 @@ export default function DispatchClass(Private) {
var isClickable = this.listenerCount('click') > 0;
var addEvent = this.addEvent;
var $el = this.handler.el;
if(!this.handler.highlight) {
this.handler.highlight = self.highlight;
}

function hover(d, i) {
// Add pointer if item is clickable
if (isClickable) {
self.addMousePointer.call(this, arguments);
}

self.highlightLegend.call(this, $el);
self.handler.highlight.call(this, $el);
self.emit('hover', self.eventResponse(d, i));
}

Expand All @@ -129,9 +132,12 @@ export default function DispatchClass(Private) {
var self = this;
var addEvent = this.addEvent;
var $el = this.handler.el;
if(!this.handler.unHighlight) {
this.handler.unHighlight = self.unHighlight;
}

function mouseout() {
self.unHighlightLegend.call(this, $el);
self.handler.unHighlight.call(this, $el);
}

return addEvent('mouseout', mouseout);
Expand Down Expand Up @@ -225,21 +231,24 @@ export default function DispatchClass(Private) {
* Mouseover Behavior
*
* @param element {D3.Selection}
* @method highlightLegend
* @method highlight
*/
Dispatch.prototype.highlightLegend = function (element) {
Dispatch.prototype.highlight = function (element) {
var label = this.getAttribute('data-label');
if (!label) return;
$('[data-label]', element.parentNode).not(function (els, el) { return $(el).data('label') !== label;}).css('opacity', 0.5);
//Opacity 1 is needed to avoid the css application
$('[data-label]', element.parentNode).css('opacity', 1).not(
function (els, el) { return `${$(el).data('label')}` === label;}
).css('opacity', 0.5);
};

/**
* Mouseout Behavior
*
* @param element {D3.Selection}
* @method unHighlightLegend
* @method unHighlight
*/
Dispatch.prototype.unHighlightLegend = function (element) {
Dispatch.prototype.unHighlight = function (element) {
$('[data-label]', element.parentNode).css('opacity', 1);
};

Expand Down
20 changes: 19 additions & 1 deletion src/ui/public/vislib/visualizations/area_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,25 @@ export default function AreaChartFactory(Private) {
if (this.isOverlapping) {

// Default opacity should return to 0.6 on mouseout
handler._attr.defaultOpacity = 0.6;
var defaultOpacity = 0.6;
handler._attr.defaultOpacity = defaultOpacity;
handler.highlight = function (element) {
var label = this.getAttribute('data-label');
if (!label) return;

var highlightOpacity = 0.8;
var highlightElements = $('[data-label]', element.parentNode).filter(
function (els, el) { return `${$(el).data('label')}` === label;
});
$('[data-label]', element.parentNode).not(highlightElements).css('opacity', defaultOpacity / 2); // half of the default opacity
highlightElements.css('opacity', highlightOpacity);
};
handler.unHighlight = function (element) {
$('[data-label]', element).css('opacity', defaultOpacity);

//The legend should keep max opacity
$('[data-label]', $(element).siblings()).css('opacity', 1);
};
}

this.checkIfEnoughData();
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/visualize/visualize_legend.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<li
ng-repeat="legendData in labels track by legendData.label"
ng-mouseenter="highlightSeries(legendData.label)"
ng-mouseleave="unhighlightSeries()"
ng-mouseenter="highlight($event)"
ng-mouseleave="unhighlight($event)"
data-label="{{legendData.label}}"
class="legend-value color">

Expand Down Expand Up @@ -38,4 +38,4 @@

</li>
</ul>
</div>
</div>
14 changes: 10 additions & 4 deletions src/ui/public/visualize/visualize_legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ uiModules.get('kibana')
refresh();
});

$scope.highlightSeries = function (label) {
$('[data-label]', $elem.siblings()).not(function (els, el) { return $(el).data('label') !== label;}).css('opacity', 0.5);
$scope.highlight = function (event) {
var el = event.currentTarget;
var handler = $scope.renderbot.vislibVis.handler;
if(!handler) return;
handler.highlight.call(el, handler.el);
};

$scope.unhighlightSeries = function () {
$('[data-label]', $elem.siblings()).css('opacity', 1);
$scope.unhighlight = function (event) {
var el = event.currentTarget;
var handler = $scope.renderbot.vislibVis.handler;
if(!handler) return;
handler.unHighlight.call(el, handler.el);
};

$scope.setColor = function (label, color) {
Expand Down