Skip to content

Commit

Permalink
Merge pull request #435 from surveyjs/feature/433-hide-visualizer-stub
Browse files Browse the repository at this point in the history
Implemented #433 - Introduce an option to hide charts of non-visualized questions
  • Loading branch information
andrewtelnov authored May 10, 2024
2 parents 05b7621 + 338fbc2 commit f4d5aec
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
2 changes: 2 additions & 0 deletions examples/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
3 changes: 3 additions & 0 deletions src/visualizationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export class VisualizationManager {
): VisualizerConstructor[] {
let vDescrs = VisualizationManager.vizualizers[questionType];
if (!vDescrs) {
if(VisualizerBase.suppressVisualizerStubRendering) {
return [];
}
return [VisualizerBase];
}
vDescrs = [].concat(vDescrs);
Expand Down
20 changes: 14 additions & 6 deletions src/visualizationPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ export class VisualizationPanel extends VisualizerBase {
) {
super(null, data, options, "panel");

const f = (<any>SurveyCore).hasLicense;
this.haveCommercialLicense = (!!f && f(4)) ||
VisualizationPanel.haveCommercialLicense ||
(typeof options.haveCommercialLicense !== "undefined"
? options.haveCommercialLicense
: false);

this._layoutEngine =
options.layoutEngine ||
new MuuriLayoutEngine(
Expand All @@ -304,14 +311,9 @@ export class VisualizationPanel extends VisualizerBase {
if (_elements === undefined) {
this._elements = this.buildElements(questions);
}
const f = (<any>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();
Expand Down Expand Up @@ -553,6 +555,9 @@ export class VisualizationPanel extends VisualizerBase {
private buildVisualizers(questions: Array<Question>) {
questions.forEach((question) => {
const visualizer = this.createVisualizer(question);
if(!visualizer) {
return;
}

if (this.allowHideQuestions) {
visualizer.registerToolbarItem("removeQuestion", () => {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/visualizerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 16 additions & 1 deletion tests/visualizationManager.test.ts
Original file line number Diff line number Diff line change
@@ -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({});
Expand Down Expand Up @@ -117,4 +118,18 @@ test("visualizers set order", () => {
VisualizationManager.unregisterVisualizer("test", undefined as any);
testVizualizers = VisualizationManager.getVisualizersByType("test");
expect(testVizualizers.length).toBe(0);
});
});

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;
}
});

0 comments on commit f4d5aec

Please sign in to comment.