Skip to content

Commit

Permalink
Merge pull request #7 from RevealBi/options-improvments
Browse files Browse the repository at this point in the history
Improved options API
  • Loading branch information
brianlagunas authored Jan 29, 2025
2 parents 2430189 + 03178a1 commit 2b909c4
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ export const RevealViewDefaults: RevealViewOptions = Object.freeze({
startWithNewVisualization: false,

header: {
showHeader: true,
canAddVisualization: true,
menu: {
showMenu: true,
exportToExcel: true,
exportToImage: true,
exportToPdf: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface RevealViewOptions {
* Gets or sets if the DashboardViewer should start with a new visualization.
*/
startWithNewVisualization?: boolean;
header?: HeaderOptions;
header?: HeaderOptions | boolean;
filters?: FilterOptions;
dataSourceDialog?: DataSourceDialogOptions;
visualizations?: VisualizationOptions;
Expand Down Expand Up @@ -130,15 +130,8 @@ export interface HeaderOptions {
* Gets or sets if the user can add a new visualization.
*/
canAddVisualization?: boolean;
/**
* Gets or sets if the header is shown.
*/
showHeader?: boolean;
menu?: {
/**
* Gets or sets if the menu is shown.
*/
showMenu?: boolean;

menu?: boolean | {
/**
* Gets or sets if the menu item "Export to Image" is shown.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,21 @@ export class RvRevealView extends LitElement {
this._revealView.startWithNewVisualization = this._mergedOptions.startWithNewVisualization;

//header
this._revealView.showHeader = this._mergedOptions.header!.showHeader;
this._revealView.canAddVisualization = this._mergedOptions.header!.canAddVisualization;
this._revealView.showMenu = this._mergedOptions.header!.menu!.showMenu;
this._revealView.showExportToExcel = this._mergedOptions.header!.menu!.exportToExcel;
this._revealView.showExportImage = this._mergedOptions.header!.menu!.exportToImage;
this._revealView.showExportToPDF = this._mergedOptions.header!.menu!.exportToPdf;
this._revealView.showExportToPowerPoint = this._mergedOptions.header!.menu!.exportToPowerPoint;
this._revealView.showRefresh = this._mergedOptions.header!.menu!.refresh;
if (typeof this._mergedOptions.header === 'boolean') {
this._revealView.showHeader = this._mergedOptions.header;
} else if (this._mergedOptions.header) {
this._revealView.canAddVisualization = this._mergedOptions.header.canAddVisualization;

if (typeof this._mergedOptions.header.menu === 'boolean') {
this._revealView.showMenu = this._mergedOptions.header.menu;
} else if (this._mergedOptions.header.menu) {
this._revealView.showExportToExcel = this._mergedOptions.header.menu.exportToExcel;
this._revealView.showExportImage = this._mergedOptions.header.menu.exportToImage;
this._revealView.showExportToPDF = this._mergedOptions.header.menu.exportToPdf;
this._revealView.showExportToPowerPoint = this._mergedOptions.header.menu.exportToPowerPoint;
this._revealView.showRefresh = this._mergedOptions.header.menu.refresh;
}
}

//filters
this._revealView.showFilters = this._mergedOptions.filters!.showFilters;
Expand Down Expand Up @@ -321,8 +328,10 @@ export class RvRevealView extends LitElement {
};

if (viz === null) {
const items = this._mergedOptions.header!.menu!.items!;
createMenuItems(items, item => item.click());
if (typeof this._mergedOptions.header !== 'boolean' && this._mergedOptions.header && typeof this._mergedOptions.header.menu !== 'boolean' && this._mergedOptions.header.menu && this._mergedOptions.header.menu.items) {
const items = this._mergedOptions.header.menu.items;
createMenuItems(items, item => item.click());
}
} else {
const vizItems = this._mergedOptions.visualizations!.menu!.items!;
createMenuItems(vizItems, vizItem => vizItem.click(viz));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const VisualizationViewerDefaults: VisualizationViewerOptions = Object.fr
duplicate: true,
exportToExcel: true,
exportToImage: true,
showMenu: false,
refresh: true,
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ export interface VisualizationViewerOptions {
hoverTooltips?: boolean;
changeChartType?: boolean;
statisticalFunctions?: boolean;
menu?: {
menu?: boolean | {
items?: MenuItem[];
copy?: boolean;
duplicate?: boolean;
exportToExcel?: boolean;
exportToImage?: boolean;
showMenu?: boolean;
refresh?: boolean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ export class RvVisualizationViewer extends LitElement {
return;
}
else {
const vizItems = this._mergedOptions.menu!.items!;
vizItems.forEach(vizItem => {
e.menuItems.push(new $.ig.RVMenuItem(vizItem.title, vizItem.icon, () => vizItem.click(viz)));
})
if (typeof this._mergedOptions.menu !== 'boolean' && this._mergedOptions.menu && this._mergedOptions.menu.items) {
const vizItems = this._mergedOptions.menu.items;
vizItems.forEach(vizItem => {
e.menuItems.push(new $.ig.RVMenuItem(vizItem.title, vizItem.icon, () => vizItem.click(viz)));
})
}
}
}
}
Expand Down Expand Up @@ -101,20 +103,22 @@ export class RvVisualizationViewer extends LitElement {

this._mergedOptions = merge({}, VisualizationViewerDefaults, options);

this._revealView.showExportToExcel = this._mergedOptions.menu!.exportToExcel;
this._revealView.showExportImage = this._mergedOptions.menu!.exportToImage;
this._revealView.showMenu = this._mergedOptions.menu!.showMenu;
this._revealView.showRefresh = this._mergedOptions.menu!.refresh;
if (typeof this._mergedOptions.menu === 'boolean') {
this._revealView.showMenu = this._mergedOptions.menu;
} else if (this._mergedOptions.menu) {
this._revealView.canCopyVisualization = this._mergedOptions.menu.copy;
this._revealView.canDuplicateVisualization = this._mergedOptions.menu.duplicate;
this._revealView.showExportToExcel = this._mergedOptions.menu.exportToExcel;
this._revealView.showExportImage = this._mergedOptions.menu.exportToImage;
this._revealView.showRefresh = this._mergedOptions.menu.refresh;
}

this._revealView.showFilters = this._mergedOptions.showFilters;

this._revealView.categoryGroupingSeparator = this._mergedOptions.categoryGroupingSeparator;
this._revealView.crosshairsEnabled = this._mergedOptions.crosshairs;
this._revealView.hoverTooltipsEnabled = this._mergedOptions.hoverTooltips;
this._revealView.showChangeVisualization = this._mergedOptions.changeChartType;
this._revealView.showStatisticalFunctions = this._mergedOptions.statisticalFunctions;
this._revealView.canCopyVisualization = this._mergedOptions.menu!.copy;
this._revealView.canDuplicateVisualization = this._mergedOptions.menu!.duplicate;
}

private updateVisualization(visualization?: string | number) {
Expand Down
23 changes: 19 additions & 4 deletions samples/sandbox-react/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
import { useRef, useState } from 'react';
import styles from './app.module.scss';
import { RvRevealView, RvRevealViewRef } from 'reveal-sdk-wrappers-react';
import { RevealViewOptions } from 'reveal-sdk-wrappers';
import { MenuOpeningArgs, RevealViewOptions, SeriesColorRequestedArgs } from 'reveal-sdk-wrappers';

declare const $: any;
$.ig.RevealSdkSettings.setBaseUrl("https://samples.revealbi.io/upmedia-backend/reveal-api/");

export function App() {

const rvRef = useRef<RvRevealViewRef>(null);
const [dashboard, setDashboard] = useState<string>("Campaigns");
const [dashboard, setDashboard] = useState<string>("Marketing");
const options: RevealViewOptions = {
startInEditMode: false,
dataSources: [
{ type: "REST", title: "Sales by Category", subtitle: "Excel2Json", url: "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9" },
],
header: {
menu: {
exportToPowerPoint: false,
items: [
{ title: "Item 1", click: () => console.log(rvRef.current?.getRVDashboard())},
{ title: "Item 2", click: () => alert("Item 2") },
Expand All @@ -25,10 +27,23 @@ export function App() {
}
},
}


const menuOpening = (args: MenuOpeningArgs) => {
if (args.visualization) {
args.menuItems[6].isHidden = true; //hide the delete button
const newDeleteButton = new $.ig.RVMenuItem("Delete", null, () => {
//todo: do you custom code here

//perform the built-in delete operation using a backdoor
(rvRef.current as any)?._revealView._dashboardView.deleteWidgetFromDashboard(args.visualization._widgetModel)
});
args.menuItems.push(newDeleteButton);
}
}

return (
<div style={{height: '100%'}}>
<RvRevealView ref={rvRef} dashboard={dashboard} options={options}></RvRevealView>
<RvRevealView ref={rvRef} dashboard={dashboard} options={options} menuOpening={menuOpening}></RvRevealView>
</div>
);
}
Expand Down

0 comments on commit 2b909c4

Please sign in to comment.