Skip to content
This repository has been archived by the owner on Dec 21, 2018. It is now read-only.

Commit

Permalink
Update tooltips, support custom handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
jheer committed Apr 7, 2018
1 parent de335ce commit 94823ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/CanvasHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import point from './util/point';
import {domFind} from './util/dom';
import {inherits} from 'vega-util';

export default function CanvasHandler(loader) {
Handler.call(this, loader);
export default function CanvasHandler(loader, tooltip) {
Handler.call(this, loader, tooltip);
this._down = null;
this._touch = null;
this._first = true;
Expand Down Expand Up @@ -143,8 +143,8 @@ prototype.fire = function(type, evt, touch) {
// if hyperlinked, handle link first
if (type === 'click' && a && a.href) {
this.handleHref(evt, a, a.href);
} else if ((type === 'mouseover' || type === 'mouseout') && a && a.tooltip) {
this.handleTooltip(evt, a, type === 'mouseover' ? a.tooltip : null);
} else if ((type === 'mouseover' || type === 'mouseout')) {
this.handleTooltip(evt, a, type === 'mouseover');
}

// invoke all registered handlers
Expand Down
14 changes: 11 additions & 3 deletions src/Handler.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import {domCreate} from './util/dom';
import {loader} from 'vega-loader';

export default function Handler(customLoader) {
export default function Handler(customLoader, customTooltip) {
this._active = null;
this._handlers = {};
this._loader = customLoader || loader();
this._tooltip = customTooltip || defaultTooltip;
}

function defaultTooltip(handler, event, item, value) {
handler.element().setAttribute('title', value || '');
}

var prototype = Handler.prototype;
Expand Down Expand Up @@ -73,6 +78,9 @@ prototype.handleHref = function(event, item, href) {
.catch(function() { /* do nothing */ });
};

prototype.handleTooltip = function(event, item, tooltipText) {
this._el.setAttribute('title', tooltipText || '');
prototype.handleTooltip = function(event, item, show) {
if (item && item.tooltip != null) {
this._tooltip.call(this._obj, this, event, item,
show ? item.tooltip : null);
}
};
8 changes: 3 additions & 5 deletions src/SVGHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import Handler from './Handler';
import {domFind} from './util/dom';
import {inherits} from 'vega-util';

export default function SVGHandler(loader) {
Handler.call(this, loader);
export default function SVGHandler(loader, tooltip) {
Handler.call(this, loader, tooltip);
var h = this;
h._hrefHandler = listener(h, function(evt, item) {
if (item && item.href) h.handleHref(evt, item, item.href);
});
h._tooltipHandler = listener(h, function(evt, item) {
if (item && item.tooltip) {
h.handleTooltip(evt, item, evt.type === 'mouseover' ? item.tooltip : null);
}
h.handleTooltip(evt, item, evt.type === 'mouseover');
});
}

Expand Down

0 comments on commit 94823ec

Please sign in to comment.