@stablelab/forse-chart
v1.1.5
Published
Forse Chart Lib Core Components
Maintainers
Readme
@stablelab/forse-chart
A CGL component library for internal projects.
Installation
Prerequisites
This library requires the following peer dependencies:
npm install react@^19.1.0 react-dom@^19.1.0
# or
yarn add react@^19.1.0 react-dom@^19.1.0Setup
1. Add Tailwind CSS
Components are styled using Tailwind CSS. You need to install Tailwind CSS v4 in your project.
Follow the Tailwind CSS installation instructions to get started.
2. Configure GitHub Package Registry
Add a .npmrc file to the root of your project:
cat <<EOF > .npmrc
//npm.pkg.github.com/:_authToken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@stablelab:registry=https://npm.pkg.github.com
EOF3. Install the package
npm install @stablelab/forse-chart
# or
yarn add @stablelab/forse-chart4. Import the CSS
@import 'tailwindcss';
@import '@stablelab/forse-chart';5. Add environment variable configurations
vercelEnv- Vercel environment variable (defaults to 'development')apiKey- API key fromNEXT_PUBLIC_API_KEYenvironment variableapiDomain- API domain fromNEXT_PUBLIC_API_URLenvironment variable (defaults to 'http://localhost:4000')
6. (Optional) Setup Mixpanel Analytics
If you want to enable Mixpanel tracking in the library, wrap your app with the MixpanelProvider:
npm install mixpanel-browser
# or
yarn add mixpanel-browserOption 1: Pass mixpanel as prop (recommended)
import mixpanel from 'mixpanel-browser';
import { MixpanelProvider } from '@stablelab/forse-chart';
// Initialize mixpanel in your app first
mixpanel.init('your-mixpanel-token');
function App() {
return (
<MixpanelProvider mixpanel={mixpanel}>
<YourApp />
</MixpanelProvider>
);
}Option 2: Use global mixpanel instance
import mixpanel from 'mixpanel-browser';
import { MixpanelProvider } from '@stablelab/forse-chart';
// Initialize mixpanel globally (available as window.mixpanel)
mixpanel.init('your-mixpanel-token');
function App() {
return (
<MixpanelProvider>
<YourApp />
</MixpanelProvider>
);
}Note:
- Mixpanel is optional. The library will work without it, but tracking events will be logged to console and not sent if Mixpanel is not configured.
- All tracking events are logged to console for debugging purposes.
Usage
Basic Import
import { FoChartLib } from '@stablelab/forse-chart';
function MyComponent() {
return <FoChartLib></FoChartLib>;
}Subpath Exports
The library provides subpath exports for better tree-shaking and organization. You can import from specific paths:
Types
import type {
GenericTimeSeriesGraphApiResponse,
HasDataPeriod,
} from '@stablelab/forse-chart/types';Hooks
import { useExportCGLChart, useWindowSize } from '@stablelab/forse-chart/hooks';API
import {
getGraphDataByCategoryIdAndGraphId,
getKpiData,
getMetaForGraph,
getTabGroups,
} from '@stablelab/forse-chart/api';Constants
import {
bgColor,
borderColor,
kpiCard,
textMain,
textMainColor,
} from '@stablelab/forse-chart/constants';Example with Subpath Exports
import { FoChartLib } from '@stablelab/forse-chart';
import { getGraphDataByCategoryIdAndGraphId } from '@stablelab/forse-chart/api';
import { useWindowSize } from '@stablelab/forse-chart/hooks';
import type { GenericTimeSeriesGraphApiResponse } from '@stablelab/forse-chart/types';
function MyComponent() {
const { width, height } = useWindowSize();
// ... use the imports
return <FoChartLib></FoChartLib>;
}Features
The @stablelab/forse-chart package exports the following. All exports are available from the main package, and many are also available as subpath exports (@stablelab/forse-chart/types, @stablelab/forse-chart/hooks, @stablelab/forse-chart/api, @stablelab/forse-chart/constants) for better tree-shaking:
Legacy Chart Components
FoChartLib- Legacy chart componentFoChartLibForOld- Legacy chart component variantFoChartLibProps- TypeScript type for FoChartLib props
CGL Components
Main Chart Components
CGLChart- Main CGL chart componentCGLChartLib- CGL chart library wrapperCGLChartLibProps- TypeScript type for CGLChartLib propscglDefaultChartColors- Default colors for CGL chartsCGLCommentCard- Comment card componentCGLDonutGauges- Donut, gauges chart componentCGLGroupTable- Group table componentCGLHorizontalGauge- Horizontal gauge componentCGLKpi- KPI componentCGLSvg- SVG componentCGLTable- Table component
Custom Components
FoStatsAccordion- Statistics accordion component
Chart Option Builders
buildBarOptions- Bar chart options builderbuildBubbleOption- Bubble chart options builderbuildEventOption- Event chart options builderbuildGaugeOption- Gauge chart options builderbuildHeatmapOption- Heatmap chart options builderbuildLineOption- Line chart options builderbuildNetworkGraphOption- Network graph options builderbuildPieOptions- Pie chart options builderbuildSankeyOption- Sankey chart options builderbuildHorizontalBarOption- Horizontal bar chart options builderbuildHorizontalGaugeOption- Horizontal gauge options builderbuildGaugeSeries- Multi-gauge series builderbuildRadarSeries- Radar chart series builder
Sub-components
CGLDataAsOf- Data timestamp componentCGLNoteItem- Note item componentSwipeableNotes- Swipeable notes componentCGLTabs- Tabs componentCGLTitle- Title componentCategoryCombobox- Category combobox component
KPI Sub-components
KpiInChartType3- KPI in chart type 3KpiInChartType4- KPI in chart type 4KpiSparkLineType5- KPI sparkline type 5
Tab Group Components
CustomCells- Custom table cells componentGATable- GA table componentTableSearch- Table search componentCGLGroupSelector- Group selector componentTabGroupWrapper- Tab group wrapper component
Color Utilities
createColorHasher- Create color hasher functionclearColorCaches- Clear color caches functiongetHashedColorBy- Get hashed color by key function
Tooltip Builders
buildTooltip- Build tooltip functionbuildTooltipFormatter- Build tooltip formatter functionbuildSankeyTooltip- Build Sankey tooltip functionTooltipItem- TypeScript type for tooltip items
Common UI Components
Card- Card componentFoButton- Button componentFoFilters- Filters componentFilters- TypeScript type for filtersFoInput- Input componentFoLink- Link componentFoTabs- Tabs componentFoTooltip- Tooltip componentLoading- Loading componentModal- Modal componentSearchBox- Search box componentShadowWrapper- Shadow wrapper componentShadowSize- TypeScript type for shadow sizesTablePagination- Table pagination component
Wrapper Components
FoChartCard- Chart card wrapper component
Other Components
LegendList- Legend list componentKpiCard- KPI card componentFoDownloadScreenshot- Download screenshot component
State Components
AuthState- Authentication state componentErrorState- Error state componentLoadingState- Loading state componentMaintenanceState- Maintenance state componentUnderMaintenance- Under maintenance componentNoDataState- No data state component
Types
HasDataPeriod- Interface for data periodAllPostsCountProd- Interface for posts count production dataGenericTimeSeriesGraphApiResponse<T>- Generic time series graph API responseArbEvent- Interface for arbitrary eventsArbEventWithSignificance- Interface for events with significanceGenericEventsResponse<T>- Generic events responseMetricOptions- Type for metric optionsGenericTimeSeriesObject- Interface for generic time series objectsUserGroup- Type for user groupsUserGroupCount- Interface for user group countsUserGroupCountResponse- Interface for user group count responsesUserGroupAggregates- Interface for user group aggregatesUserGroupAggregationResponse- Interface for user group aggregation responsesSectorStat- Type for sector statisticsStipMetadataResponse- Interface for STIP metadata responsesAiQueryId- Type for AI query IDsProjectTransaction- Type for project transactionsProjectData- Type for project dataDonationActivity- Type for donation activityDonationActivitySeries- Type for donation activity seriesDonationActivityResponse- Type for donation activity responsesGiniCoefficient- Type for Gini coefficientJokeraceActivity- Type for Jokerace activityJokeraceProjectData- Type for Jokerace project dataProcessedJokeRaceActivity- Type for processed Jokerace activityContestParticipant- Type for contest participantsTooltipFormatterParamsType- Type for tooltip formatter parametersTooltipFormatterType- Type for tooltip formatter
Hooks
useExportCGLChart- Hook for exporting CGL chartsuseWindowSize- Hook for window sizeuseMixpanel- Hook for Mixpanel tracking (returns tracking functions)
Mixpanel
MixpanelProvider- Provider component to initialize Mixpanel with your tokenuseMixpanel- Hook to access Mixpanel tracking functions
Store
createCGLStore- Create CGL store functionCGLStoreContext- CGL store contextuseCGLStore- Hook to use CGL storeLegendItem- TypeScript type for legend itemsCGLState- TypeScript type for CGL stateCGLStore- TypeScript type for CGL store
API
getMetaForGraph- Get metadata for graphgetGraphDataByCategoryIdAndGraphId- Get graph data by category and graph IDgetTabGroups- Get tab groupsgetKpiData- Get KPI datagetDashboardLabelConfigs- Get dashboard label configurationsgetGraphComments- Get graph comments
