Switchable Dimensions
*This plugin is officially supported by Sisense. You can find the latest version of this plugin on the Sisense Add-Ons page.
Introduction
This article will explain how to create a switchable dimensions or measures in a widget, using custom JavaScript. The switchable dimension can either be in categories, values, rows, columns or any other dimension that exists in a specific widget.
Business Case
This plugin allows you to provide several views of data for a given expression.
Example
Right click context menu items:
Setting up
Step 1 - Download and extract the enclosed folder in the plugins folder
C:\Program Files\Sisense\PrismWeb\plugins\SwitchDimension, if the "plugins" folder is not there, please create it.
Step 2 - Create or update the widget in which you wish to have a switchable dimension
Define only one dimension (for example - “Country”) from the dimensions group you want to “switch” between (for example - Country, Brand & Product_Category).
Click "Apply" to save changes.
Step 3 - Go to the widget’s script and paste the following code with the proper values. Make sure you have at least two dimensions to switch.
prism.registerSwitchDimension({
widget: widget,
maxItemsBeforeSubMenuIsCreated: 5, //optional
dimensions: [
{
panel: '<PANEL_NAME>',
affectAllWidgets: true, //optional (true|false)
dims: [
{
"index": 0,
"dim": "[<TABLE_NAME>.<FIELD_NAME>]",
"datatype": "<DATATYPE>",
"title": "", //optional
"widgetTitleTemplate": "" //optional
},
{
"index": 0,
"dim": "[<TABLE_NAME>.<FIELD_NAME>]",
"datatype": "<DATATYPE>",
"title": "", //optional
"widgetTitleTemplate": "" //optional
}
]
}
]
});
Where:
-
maxItemsBeforeSubMenuIsCreated - when total count of dimensions exceeds this value, the list of dimensions in the context menu will be placed under sub menu. Default value is 5.
- panel - the panel name according to the switchable field’s location in the widget (the panels are located on the left side when editing a widget).
Possible panel names are: "categories", "rows", "values", "break by" etc.
-
affectAllWidgets - boolean value (true|false). If value is true switching dimension will be applied for every widget from a dashboard which has the same panel as the one from the configuration. Default value is false.
-
dim - The dimension to be switched to. This property is case sensitive.
- datatype - dimension data type. It's important to set correct datatype. Allowed datatypes: "datetime", "text", "numeric".
- title - caption in context menu.
- widgetTitleTemplate - a string template to allow dynamic widget title. When defined, a widget title will be dynamically changed according to the given template. The template must contain {{dim}} variable which will be automatically replaced with the dimension title. Default value is the dimension title.
Step 4 - Save the script.
Example config
The widget script sample below will allow to switch between Country, Brand & Category for 'categories' panel and Age Range, Gender for 'break by' panel. Switching between dimension for 'break by' panel will affect all widgets from dashboard which have 'break by' panel.
prism.registerSwitchDimension({
widget: widget,
dimensions: [
{
panel: 'categories',
dims: [
{
"index":0,
"dim":"[country.Country]",
"datatype": "text",
"title":"Country"
},
{
"index":0,
"dim":"[brand.Brand]",
"datatype": "text",
"title":"Brand"
},
{
"index":0,
"dim":"[category.Category]",
"datatype": "text",
"title":"Category"
}
]
},
{
panel: 'break by',
affectAllWidgets: true,
dims: [
{
"index":0,
"dim":"[Commerce.Age Range]",
"datatype": "text",
"title":"Age range"
},
{
"index": 0,
"dim": "[Commerce.Gender]",
"datatype": "text",
"title": "Gender"
}
]
}
]
});
The plugin has backwards compatibility for the old config version.
02/02/2016 - Plugin updated. Added fix for broken breadcrumbs display when switching dimensions combined with drilling. Added support for "datatype" configuration property. Make sure that your configuration script has "datatype" property set.
05/03/2016 - Plugin updated. Added fix for duplicated "Switch to" options on widget right click menu.
Jan 3 2018 - updated context menu UI, ability to update multiple widgets on dimension switch, dynamic widget title + bugfixes
-
I'm having some difficulty getting this plugin to run at all. I suspect it has to do with one of the following:
--Can you sort on a saved formula? I'm looking to switch between a calculated Gross Margin (SUM([Extended Price]-[Extended Cost])) and the Total Extended Price (SUM([Extended Price]). I can type "gross" into the data browser and the formula appears, but it's not in a table in the Elasticube.
--What additional formatting is required to use table and column names that contain spaces? I know it's bad practice, I don't have a choice though.
I downloaded one of the example dashboards from the comments, and the switch works there, so I know the plugin does work.
My code as it stands: (variables renamed)
prism.registerSwitchDimension({
widget: widget,
dimensions: [
{
"index": 0,
"panel": "values",
"dim": "[[Table with spaces].Extended Price]",
"title": "Total Extended Price"
"widgetTitle": "Top Products by Extended Price"
},
{
"index": 0,
"panel": "values",
"dim": "[Gross Margin]",
"title": "Gross Margin"
"widgetTitle": "Top Products by Gross Margin"
}
]
});
I'm new to Sisense, Plugins, and JAQL, so any assistance is appreciated -
Hi Glenn,
If a table contains spaces in its name the format of the dimension remains the same: "[Table With Spaces.Column]"
Unfortunately the plugin doesn't support formulas instead it supports only aggregation functions and the format for values should be defined like this:
{
panel: 'values',
dims: [
{
'index': 0,
'dim': '[Commerce.Cost]',
'datatype': 'numeric',
'agg': 'sum',
'title': 'Total Cost'
},
{
'index': 0,
'dim': '[Commerce.Revenue]',
'datatype': 'numeric',
'agg': 'sum',
'title': 'Total Revenue'
}
]
} -
This plugin stopped working for me and I do't know why.
prism.registerSwitchDimension({
widget: widget,
dimensions: [
{
panel: 'rows',
dims: [
{
"index": 0,
"dim":"[Product_dim.Category]",
"datatype": "text",
"title": "", //optional
"widgetTitleTemplate": "" //optional
}
,{
"index": 0,
"dim":"[Product_dim.Manufacturer]",
"datatype": "text",
"title": "", //optional
"widgetTitleTemplate": "" //optional
}
]
}
]
});
Does anybody understand what I am doing wrong?
Also I don't get where I should use "" panel: 'rows', """. Is it in each dim or just outside like I did above?
I am using Sisense version 6.7.1.15016 -
Hi Oleg. The SwitchDimension plugin stopped working for v7.1.0.10324, have you experienced the same issue? It was working perfectly on v7.0.2.11001
Our code typically looks like this:
prism.registerSwitchDimension({
widget: widget,
maxItemsBeforeSubMenuIsCreated: 4,
dimensions: [
{
panel: 'point',
affectAllWidgets: true,
dims: [
{
"index":0,
"dim":"[dim_estructura.subcategoria]",
"datatype": "text",
"title":"Subcategoría",
"widgetTitleTemplate":"Matriz Venta Neta s/IVA vs Precio c/IVA"},
{
"index":0,
"dim":"[fact_comercial_dia.marca]",
"datatype": "text",
"title":"Marca",
"widgetTitleTemplate":"Matriz Venta Neta s/IVA vs Precio c/IVA"
}
]
}
]
}); -
UPDATE: if you are experiencing the same problem when moving to v7.1.0.x, here is the procedure that fixed it, thanks to Oleksii who helped us in the process:
This issue is affected by function isNeededToCreateSubMenu(). To fix this issue, please, apply next steps:
- Open file switchDimension.js which is located at the path C:\Program Files\Sisense\PrismWeb\plugins\SwitchDimension;
- Find next function:
function isNeededToCreateSubMenu(dimensionsSettings, allowedLength) {
var dimCount = 0;
for (var key in dimensionsSettings) {
dimCount += dimensionsSettings[key].dims.length;
}
return dimCount >= allowedLength;
}- Add additional verification to this function:
function isNeededToCreateSubMenu(dimensionsSettings, allowedLength) {
var dimCount = 0;
for (var key in dimensionsSettings) {
if (dimensionsSettings[key].dims) {
dimCount += dimensionsSettings[key].dims.length;
};
}
return dimCount >= allowedLength;
}Make sure that these changes were applied. The best approach to apply these changes, please, disable and enable this plugin.
-
This isn't working for me. I have all the code right and it gives me the option to switch the dimensions. When I click to change the category, the X axis (which is a date) become really funky and displays some random dates in the first few columns and then random series for the rest. Anyone have any idea why this is happening?
Before I click:
After click:
-
I have a different Drill Hierarchy for each dimension that is switched, but when I apply them, they are only saved on one dimension, not each one. When I go back and review them the Hierarchy is no longer checked in the editor. Is this a bug in v7.2 or is there something else going on? See attached screen shot.
-
Hi,
I have a table that has a dot in it's name and it is breaking the plugin - Is there a way to wrap that dot?
The name of the table is: Db_Warehouse.Reports_Recommendation_All_Clients
The name of the column is: OverallRecommendationTitleNew
See syntax below:
{
panel: 'break by',
affectAllWidgets: true,
dims: [
{
"index":0,
"dim":"[Db_Warehouse.Reports_Recommendation_All_Clients.OverallRecommendationTitleNew]",
"datatype": "text",
"title":"Overall Recommendation Level"
//"widgetTitle":"Distribution of Recommendation Level by Job Profile"
},
{
"index": 0,
"dim":"[Db_Warehouse.Reports_Recommendation_All_Clients.RecTitle]",
"datatype": "text",
"title":"Recommendation Level"
//"widgetTitle":"Distribution of Recommendation Level by Job Profile"
}
]
}Thanks in advance!
-
While this says it is supported by Sisense, it is not listed on https://documentation.sisense.com/latest/sisense-mobile.htm as being supported on the app. From our vantage point, if it's not supported on the app, it's not supported.
Thanks.
-
I'm able to get things working but only using the 'values' panel. When specifying 'categories' or 'break by' the option doesn't show up when right clicking the chart. Any ideas on what I could be doing wrong?
{
panel: 'categories',
affectAllWidgets: false, //optional (true|false)
dims: [
{
"index":0,
"dim":"[users.created_at]",
"datatype":"datetime",
"title":"Created At",
"widgetTitle": "Users Over Created At"
},
{
"index":0,
"dim":"[users.updated_at]",
"datatype":"datetime",
"title":"Updated At",
"widgetTitle": "Users Over Updated At"
}
]
}
Please sign in to leave a comment.
Comments
52 comments