Reenable VEGA_DEBUG for Vega visualization (#20456) (#20536)

* Reenable vega debug

* Restore to simple VEGA_DEBUG implementation
This commit is contained in:
Tim Roes 2018-07-07 10:08:38 +02:00 committed by GitHub
parent e87f67eb3f
commit 167b29b2b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View file

@ -21,6 +21,7 @@ import $ from 'jquery';
import moment from 'moment';
import dateMath from '@kbn/datemath';
import * as vega from 'vega-lib';
import * as vegaLite from 'vega-lite';
import { Utils } from '../data_model/utils';
import { VISUALIZATION_COLORS } from '@elastic/eui';
import { TooltipHandler } from './vega_tooltip';
@ -329,6 +330,33 @@ export class VegaBaseView {
return { from, to, mode };
}
/**
* Set global debug variable to simplify vega debugging in console. Show info message first time
*/
setDebugValues(view, spec, vlspec) {
if (window) {
if (window.VEGA_DEBUG === undefined && console) {
console.log('%cWelcome to Kibana Vega Plugin!', 'font-size: 16px; font-weight: bold;');
console.log('You can access the Vega view with VEGA_DEBUG. ' +
'Learn more at https://vega.github.io/vega/docs/api/debugging/.');
}
const debugObj = {};
window.VEGA_DEBUG = debugObj;
window.VEGA_DEBUG.VEGA_VERSION = vega.version;
window.VEGA_DEBUG.VEGA_LITE_VERSION = vegaLite.version;
window.VEGA_DEBUG.view = view;
window.VEGA_DEBUG.vega_spec = spec;
window.VEGA_DEBUG.vegalite_spec = vlspec;
// On dispose, clean up, but don't use undefined to prevent repeated debug statements
this._addDestroyHandler(() => {
if (debugObj === window.VEGA_DEBUG) {
window.VEGA_DEBUG = null;
}
});
}
}
destroy() {
// properly handle multiple destroy() calls by converting this._destroyHandlers
// into the _ongoingDestroy promise, while handlers are being disposed

View file

@ -107,6 +107,7 @@ export class VegaMapView extends VegaBaseView {
});
const vegaView = vegaMapLayer.getVegaView();
this.setDebugValues(vegaView, this._parser.spec, this._parser.vlspec);
await this.setView(vegaView);
}

View file

@ -26,6 +26,7 @@ export class VegaView extends VegaBaseView {
if (!this._$container) return;
const view = new vega.View(vega.parse(this._parser.spec), this._vegaViewConfig);
this.setDebugValues(view, this._parser.spec, this._parser.vlspec);
view.warn = this.onWarn.bind(this);
view.error = this.onError.bind(this);