StatCardElement Documentation
Purpose
The StatCardElement is a user interface component designed for displaying statistical data in a visually appealing manner on the Vantage analytics platform. It is particularly useful for showing key performance indicators (KPIs), trends, and comparisons that can be adjusted dynamically based on user input or workflow configurations. The component enhances the readability of data insights, integrating with various workflows to provide real-time feedback and metrics.
Settings
The StatCardElement comes equipped with several configurable settings that dictate its behavior and appearance. Below is a comprehensive explanation of each setting:
1. config.icon
- Input type: String
- Description: This setting defines which icon will be displayed in the top right corner of the card. It uses a predefined set of icons mapped within
iconMap. Changing this value alters the icon that represents the card's data. - Default value:
Activity(if not specified)
2. config.showIcon
- Input type: Boolean
- Description: This setting determines whether the icon will be displayed or not. Setting this to
truewill render the specified icon in the card, while setting it tofalsewill hide it completely. - Default value:
true
3. config.trendValue
- Input type: String
- Description: This setting sets the display value for the trend indicator below the main value, showing how the current value compares to previous metrics. Modifying this value impacts the trend information without involving any comparisons.
- Default value:
'—'
4. config.comparisonWorkflowId
- Input type: String
- Description: When set, this ID directs the component to use another workflow for comparison purposes. This enables comparison mode, where the current value can be compared against a historical or alternative metric. Absence of this ID puts the component in legacy/manual mode.
- Default value:
null
5. config.comparisonLabel
- Input type: String
- Description: This label is displayed alongside the trend comparison value. It can be configured to provide context about what the comparison indicates (e.g., "vs. last month"). This affects how the comparisons are perceived by users.
- Default value:
''(empty string)
6. config.trendPositive
- Input type: Boolean
- Description: This setting drives the default visualization of the trend arrow. If set to
true, a positive trend indicator (up arrow) will be displayed; iffalse, a negative trend indicator (down arrow) will appear. This is significant for manually configured trending scenarios. - Default value:
true
7. config.positiveColor
- Input type: String (Hexadecimal)
- Description: Specifies the color used for the trend when it is positive. This affects the coloring of trend text as well as the trend indicator arrow. Changing this alters the visual cue for positive trends.
- Default value:
'#16a34a'(green-600)
8. config.negativeColor
- Input type: String (Hexadecimal)
- Description: Specifies the color used for the trend when it is negative. Similar to
positiveColor, this influences the trend's visual appearance when indicating a drop. - Default value:
'#dc2626'(red-600)
9. config.style
- Input type: Object
- Description: This setting accepts a JavaScript style object that can customize the component’s overall presentation. Changing it allows users to apply bespoke stylistic changes to better match their dashboard requirements.
- Default value:
{}(no custom styles)
How It Works
The StatCardElement fetches its configuration from the element prop which contains settings to modify its display and functionality. The workflows prop is used to find a relevant workflow based on a specified workflowId, which can be significant for pulling in additional data such as workflow titles and comparison metrics.
On initialization, the component executes the following logic:
- It identifies if an icon should be shown based on
config.showIcon. - It generates a main statistical value (
valueDisplay) that it mocks for demonstration purposes. - If
comparisonWorkflowIdis specified, it computes the comparison value and calculates the percentage difference, determining the appropriate trend direction and color. - If not in comparison mode, it defaults to the manual settings provided by the user for trend display.
- Finally, it renders the component, displaying all of the configured data prominently.
Use Cases & Examples
Use Cases
-
KPI Dashboard for Sales Performance: A company may utilize the
StatCardElementin a sales dashboard to configure cards that show monthly sales performance against targets, visually indicating progress and trend with corresponding arrows and colors. -
Website Analytics Reporting: An analytics team might deploy the component to visualize web traffic stats, such as user engagement growth, by comparing current daily active users against the previous day, utilizing trend indicators to provide quick insights.
-
Financial Report Monitoring: Financial teams could leverage the component for displaying quarterly revenue growth trends, allowing comparison of the current quarter's revenue against the previous quarter.
Example Configuration
To illustrate a specific use case, consider a marketing dashboard that needs to visualize monthly customer acquisition.
Configuration Data
const statCardConfig = {
element: {
label: "Monthly Customer Acquisition",
workflowId: "workflow123",
config: {
icon: "users",
showIcon: true,
trendValue: "+25%",
comparisonWorkflowId: "workflow124",
comparisonLabel: "versus last month",
trendPositive: true,
positiveColor: "#16a34a",
negativeColor: "#dc2626",
style: { backgroundColor: "#f0f4ff" }
}
},
workflows: [
{ id: "workflow123", title: "Current Month Statistics" },
{ id: "workflow124", title: "Previous Month Statistics" }
]
}In this example:
- The card is labeled as "Monthly Customer Acquisition."
- It shows a user icon on the top, indicating the metric is related to users.
- The displayed trend value shows a positive growth of 25%.
- It compares the current month against the previous month, clearly labeled.
- Colors are set to green for positive trends, ensuring that users can grasp performance at a glance.
- Custom styling is applied to match branding requirements.
This extensive configuration makes the StatCardElement a versatile tool for displaying critical business metrics effectively.