diff --git a/examples/summary.js b/examples/summary.js index 7db42d897..7b61488cf 100644 --- a/examples/summary.js +++ b/examples/summary.js @@ -36,6 +36,8 @@ var survey = new Survey.SurveyModel(json); // SurveyAnalytics.SelectBasePlotly.displayModeBar = false; +// SurveyAnalytics.VisualizerBase.suppressVisualizerStubRendering = true; + SurveyAnalytics.PlotlySetup.onImageSaving.add(function (selectBaseVisualizer, options) { options.filename = "Exported " + selectBaseVisualizer.question.name; }); diff --git a/src/visualizationManager.ts b/src/visualizationManager.ts index f4e1d477c..8066138ff 100644 --- a/src/visualizationManager.ts +++ b/src/visualizationManager.ts @@ -80,6 +80,9 @@ export class VisualizationManager { ): VisualizerConstructor[] { let vDescrs = VisualizationManager.vizualizers[questionType]; if (!vDescrs) { + if(VisualizerBase.suppressVisualizerStubRendering) { + return []; + } return [VisualizerBase]; } vDescrs = [].concat(vDescrs); diff --git a/src/visualizationPanel.ts b/src/visualizationPanel.ts index 27b505d3e..0691873da 100644 --- a/src/visualizationPanel.ts +++ b/src/visualizationPanel.ts @@ -286,6 +286,13 @@ export class VisualizationPanel extends VisualizerBase { ) { super(null, data, options, "panel"); + const f = (SurveyCore).hasLicense; + this.haveCommercialLicense = (!!f && f(4)) || + VisualizationPanel.haveCommercialLicense || + (typeof options.haveCommercialLicense !== "undefined" + ? options.haveCommercialLicense + : false); + this._layoutEngine = options.layoutEngine || new MuuriLayoutEngine( @@ -304,14 +311,9 @@ export class VisualizationPanel extends VisualizerBase { if (_elements === undefined) { this._elements = this.buildElements(questions); } - const f = (SurveyCore).hasLicense; - this.haveCommercialLicense = (!!f && f(4)) || - VisualizationPanel.haveCommercialLicense || - (typeof options.haveCommercialLicense !== "undefined" - ? options.haveCommercialLicense - : false); this.buildVisualizers(questions); + if (!this.haveCommercialLicense) { this.registerToolbarItem("commercialLicense", () => { return createCommercialLicenseLink(); @@ -553,6 +555,9 @@ export class VisualizationPanel extends VisualizerBase { private buildVisualizers(questions: Array) { questions.forEach((question) => { const visualizer = this.createVisualizer(question); + if(!visualizer) { + return; + } if (this.allowHideQuestions) { visualizer.registerToolbarItem("removeQuestion", () => { @@ -890,6 +895,9 @@ export class VisualizationPanel extends VisualizerBase { container: HTMLElement ) { const visualizer = this.getVisualizer(element.name); + if(!visualizer) { + return; + } const questionElement = DocumentHelper.createElement("div"); questionElement.dataset.question = element.name; diff --git a/src/visualizerBase.ts b/src/visualizerBase.ts index 42b3a119d..d93f07cca 100644 --- a/src/visualizerBase.ts +++ b/src/visualizerBase.ts @@ -34,6 +34,8 @@ var styles = require("./visualizerBase.scss"); * [View Demo](https://surveyjs.io/dashboard/examples/how-to-plot-survey-data-in-custom-bar-chart/ (linkStyle)) */ export class VisualizerBase implements IDataInfo { + public static suppressVisualizerStubRendering: boolean = false; + private _showToolbar = true; private _footerVisualizer: VisualizerBase = undefined; private _dataProvider: DataProvider = undefined; @@ -198,7 +200,9 @@ export class VisualizerBase implements IDataInfo { question.title = this.processText(this.question.title); this._footerVisualizer = this.createVisualizer(question); - this._footerVisualizer.onUpdate = () => this.invokeOnUpdate(); + if(!!this._footerVisualizer) { + this._footerVisualizer.onUpdate = () => this.invokeOnUpdate(); + } } return this._footerVisualizer; } diff --git a/tests/visualizationManager.test.ts b/tests/visualizationManager.test.ts index 29d6bd8df..50724841a 100644 --- a/tests/visualizationManager.test.ts +++ b/tests/visualizationManager.test.ts @@ -1,6 +1,7 @@ import { VisualizationManager } from "../src/visualizationManager"; import { Text } from "../src/text"; import { WordCloud } from "../src/wordcloud/wordcloud"; +import { VisualizerBase } from "../src/visualizerBase"; test("register and get", () => { expect(VisualizationManager.vizualizers).toMatchObject({}); @@ -117,4 +118,18 @@ test("visualizers set order", () => { VisualizationManager.unregisterVisualizer("test", undefined as any); testVizualizers = VisualizationManager.getVisualizersByType("test"); expect(testVizualizers.length).toBe(0); -}); \ No newline at end of file +}); + +test("stub default visualizer and suppressVisulizerStubRendering setting", () => { + let testVizualizers = VisualizationManager.getVisualizersByType("signaturepad"); + expect(testVizualizers.length).toBe(1); + expect(testVizualizers[0].name).toBe("VisualizerBase"); + + try { + VisualizerBase.suppressVisualizerStubRendering = true; + testVizualizers = VisualizationManager.getVisualizersByType("signaturepad"); + expect(testVizualizers.length).toBe(0); + } finally { + VisualizerBase.suppressVisualizerStubRendering = false; + } +});