In the Open source BI product Helical Insight BI application, there are a lot of Properties options which can allow us to customize a lot of chart related properties like color, color palette, formatting and much more. The properties applied and used here are hard coded in the report definition.
But in many cases we can have situations in which we would like to dynamically change the properties based on the certain condition.
Example: We have created a chart with some color theme. For every user we would like a different color theme to get applied. In those cases Operations can be used. In this blog we are going to cover how to do the same.
Operations allows to put code at these 4 placeholders:
- Preexecution
- Prefetch
- Postfetch
- Postexecution
These hooks serve as extension points where you can inject custom logic in the form of JavaScript. This flexibility is especially valuable for use cases where the report behavior needs to change dynamically based on the user, environment, or data context.
Understanding Report Properties and Dynamic Variables
Every report in Helical Insight contains various report-level properties, such as chart configurations, color palettes, axis settings, and much more. These properties are stored in the report definition and can be accessed and manipulated during runtime via JavaScript.
To understand what properties are available in a report and what values they currently hold, developers can use the browser’s developer tools console. Executing the command:
console.log(properties);
This logs a complete object that represents all report properties. By inspecting this object, you can view what values are currently applied and which ones can be modified or overridden.
This approach is particularly useful when you want to dynamically change property values based on conditions such as user roles, profiles, or data filters. By leveraging this, developers can build reports that adapt in real-time based on the context in which they are being viewed. It enables the developer to inject logic that can alter visuals, filters, or formatting on-the-fly during report execution.
Use Case Example: Dynamic Color Palette Based on User Profile
Let’s consider a practical example involving the Color Palette property, which defines the color themes used in charts and visualizations.
In Helical Insight, administrators can assign profile attributes to users. These attributes are key-value pairs that describe user-specific metadata, such as location, department, or preferred chart colors.
Suppose you have two users:
- User A has a profile attribute: colorPalette = “Vibrant”
- User B has a profile attribute: colorPalette = “Muted”
When these users log into the application and open the same report, we want the chart colors to reflect their assigned palettes. Here’s how this can be achieved:
- Profile Assignment: At the time of user creation or authentication, assign each user relevant profile attributes.
- Accessing Session Variables: Within the report operations (e.g., Preexecution), you can access the user’s profile using session variables like:
user
. You canconsole.log(user)
to see the details of currently logged in user. - Updating Report Properties Dynamically: Using this value, update the color palette property of the chart dynamically:
var colorPaletteProfile = user.profile.find(p => p.profileName === "colorPalette"); if (colorPaletteProfile && colorPaletteProfile.profileValue) { const newPalette = colorPaletteProfile.profileValue.split(',').map(item => item.trim()); properties.chartTheme.colorPalette = newPalette; }
Explanation:
- The user object is a built-in session object available in the runtime.
- The
.profile
array holds key-value objects for each user-specific profile attribute. - We look for the colorPalette profile.
- If it exists, we parse its value (which is a comma-separated string) into an array.
- Finally, we assign this array to the colorPalette property of the chart.
As a result, the same report dynamically adapts the chart color theme based on who is logged in. User A will see one set of colors, while User B sees a completely different palette — all without changing the report or creating multiple versions of it.
Result: When the report is executed, User A will see charts using the “Vibrant” palette, while User B will see the same charts styled with the “Muted” palette, thus offering a personalized reporting experience.
In the above use case we have considered the assigned profile value to a user. But in the condition code which we wrote in the operations, we can check and update based on anything like user name, roles, organization, profile attribute and profile value.
Benefits of Dynamic Operations
- User Personalization: Tailor visuals, filters, and data formatting to match individual user preferences or roles.
- Improved UX: Provide a more relevant and context-aware interface, improving user engagement.
- Reduced Report Duplication: Instead of creating multiple versions of a report for different user types, use dynamic logic to reuse the same report.
- Advanced Security and Data Handling: Enforce data-level restrictions or access controls dynamically using prefetch or postfetch logic.
Conclusion
Helical Insight’s Operations framework is a robust tool that unlocks tremendous customization and automation capabilities in report generation and user experience. By using session-based variables, report properties, and scripting, developers can implement sophisticated business logic that reacts in real time to who is viewing the report and under what conditions. This leads to a more intelligent, efficient, and scalable reporting solution. This not only enhances the user experience but also ensures scalability and maintainability across large deployments.