This file provides guidance to Codex (Codex.ai/code) when working with code in this repository.
@netdata/charts is a frontend SDK and chart utilities library for Netdata, providing React-based chart components and visualization tools. It builds multiple distributions (CommonJS, ES6, and UMD) and serves as a peer dependency alongside @netdata/netdata-ui.
# Development & Build
yarn build # Build both CJS and ES6 distributions
yarn build:cjs # Build CommonJS distribution
yarn build:es6 # Build ES6 distribution
yarn storybook # Start Storybook development server
yarn build-storybook # Build static Storybook
# Testing & Quality
yarn test # Run tests
yarn lint # Run ESLint
# Local Development
yarn to-cloud # Copy built package to cloud-frontend node_modules- No semicolons (consistent across all files)
- Double quotes for strings
- 2-space indentation (no tabs)
- 100 character line width
- ES5 trailing commas
- Arrow functions preferred over function declarations
- Template literals for dynamic strings
- ES6 imports/exports throughout
- All imports at the top of file: Never use require() or dynamic imports within function bodies
- Destructuring heavily used in function parameters
- Props spreading with
{...rest}for prop forwarding - Conditional rendering using
&&and ternary operators - No comments unless absolutely necessary for complex logic
- Hooks-first approach: Prefer custom hooks over class components
- Composition over inheritance: Build components from smaller pieces
- JSX in .js files: No .jsx extension required
- React 19 automatic JSX transform: No React import needed in component files
- Central
makeSDKfunction creates chart instances - Plugin system for extending functionality (hover, pan, select, highlight)
- Attribute-based chart configuration
- Styled Components 6: Primary styling solution with theme integration
- @netdata/netdata-ui: Base component library (Flex, Text, etc.)
- HOC Pattern:
withChartfor wrapping chart components - Provider Pattern: React context for chart data and state management
- Modular chart implementations in
src/chartLibraries/ - Separate chart types: dygraph, d3pie, gauge, bars, table, etc.
- Each chart library implements standard interface
src/
├── chartLibraries/ # Chart type implementations
├── components/ # React UI components
├── sdk/ # Core SDK functionality
└── helpers/ # Utility functions
- CommonJS:
dist/directory for Node.js compatibility - ES6:
dist/es6/directory for modern bundlers - Module resolution:
@/alias for src directory
- Make changes in appropriate source files
- Run
yarn to-cloudto copy built assets to cloud-frontend - Test changes in consuming applications
- Jest with jsdom environment
- Simple unit tests focused on component rendering
- Minimal coverage thresholds (1% for branches/functions)
- DOM testing for rendered elements
- Test files colocated with source:
*.test.js
- React 19 (peer dependency)
- Styled Components 6 for styling
- D3.js ecosystem for visualizations
- Dygraphs for time series charts
- @netdata/netdata-ui for base components
- Use theme-based colors:
"mainChartBorder","borderSecondary", etc. - Extend base components from @netdata/netdata-ui
- Support responsive design with height/width props
- Chart state managed via SDK attributes
- React context for sharing chart data
- Custom hooks for chart-specific logic
- Store ALL persistent state in chart attributes - any state that should survive virtualization scrolling
- UI state examples:
drawer.action,drawer.tab,drawer.showAdvancedStats,groupBy,expandedstates - Data state examples:
comparePeriods,drilldownWeightsData,customPeriods - Loading/error states:
compareLoading,compareError,weightsLoading,weightsError - Access via useAttributeValue for automatic reactivity and event listening
- Create custom useSelector hooks when combining multiple attributes or complex logic
- Avoid React useState for any state that needs to persist across component unmount/remount
- Plugins registered at SDK level
- Extend chart functionality without modifying core
- Examples: hover interactions, pan/zoom, selection
Always check existing patterns and components before implementing new functionality. Reuse is strongly preferred over recreation.
- CRITICAL TESTING RULE: NEVER MOCK ANYTHING! Use real imports and actual components/libraries
- Whenever you are about to mock, or you see a test missing its mock, DO NOT MOCK!!!! Check and import actual file/library first. If we are working with charts use makeTestChart and rest of testUtilities!
- NO JEST MOCKS ALLOWED - Use real components, real providers, real everything
- SUPER IMPORTANT: Always use actual imports - never mock @netdata/netdata-ui, never mock providers, never mock any components