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

Backport of area chart opacity fix - 4.4 #6468

Merged
merged 2 commits into from
Mar 8, 2016
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
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 @@ define(function (require) {
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 @@ define(function (require) {
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 @@ define(function (require) {
* 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
21 changes: 20 additions & 1 deletion src/ui/public/vislib/visualizations/area_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,26 @@ define(function (require) {
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 @@ -26,12 +26,18 @@ define(function (require) {
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