Skip to content

Commit 9028067

Browse files
feat: expose customPalette prop for color customization (#30)
* feat: expose customPalette prop for color customization - Add customPalette prop to InferenceResult component - Update predictionsToAnnotations to accept optional custom palette - Export default palette for users to reference 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: specify yarn as package manager and update CLAUDE.md - Add packageManager field to enforce yarn@1.22.19 usage - Update CLAUDE.md to use yarn commands instead of npm - Document yarn installation commands and workspace management 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: add .claude to gitignore 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8115a38 commit 9028067

5 files changed

Lines changed: 95 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules/
22
.DS_Store
33
**/yarn-error.log
4-
docs
4+
docs
5+
6+
.claude

CLAUDE.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Package Manager
6+
7+
**IMPORTANT: This project uses Yarn (v1.22.19) as its package manager. Always use `yarn` commands instead of `npm` for dependency management and script execution.**
8+
9+
## Development Commands
10+
11+
### Build
12+
```bash
13+
# Build all packages in the monorepo
14+
yarn build
15+
16+
# Type check all packages
17+
yarn tsc
18+
```
19+
20+
### Testing
21+
```bash
22+
# Run tests in core package
23+
cd packages/core && yarn test
24+
25+
# Run tests in react package
26+
cd packages/react && yarn test
27+
28+
# Run tests with coverage in react package
29+
cd packages/react && yarn coverage
30+
```
31+
32+
### Linting
33+
```bash
34+
# Lint all files from root
35+
yarn lint
36+
```
37+
38+
### Documentation
39+
```bash
40+
# Generate documentation with TypeDoc
41+
yarn docs
42+
```
43+
44+
### Installing Dependencies
45+
```bash
46+
# Install all dependencies
47+
yarn install
48+
49+
# Add a new dependency to a specific package
50+
cd packages/core && yarn add <package-name>
51+
cd packages/react && yarn add <package-name>
52+
```
53+
54+
## Architecture
55+
56+
This is a Lerna monorepo containing two main packages:
57+
58+
1. **landingai** (`packages/core/`) - Core JavaScript library for LandingLens API integration
59+
- Provides API client for inference endpoints
60+
- Contains utility functions for annotations, colors, and math operations
61+
- Exports TypeScript types for predictions and API responses
62+
63+
2. **landingai-react** (`packages/react/`) - React components library
64+
- Provides React components for image collection and inference visualization
65+
- Uses React Context API for API configuration (`InferenceContext`)
66+
- Main components: `PhotoCollector`, `InferenceResult`, and annotation visualizers
67+
68+
### Key Dependencies
69+
- Build tools: esbuild for bundling, TypeScript for type checking
70+
- Testing: Jest for core package, Vitest for React package
71+
- Monorepo management: Lerna with Yarn workspaces
72+
- React versions supported: 16.8.0+ and 17.0.0
73+
74+
### Code Conventions
75+
- ESLint configuration requires semicolons and single quotes
76+
- TypeScript strict mode is enabled
77+
- Component CSS uses CSS modules (`.module.css` files)
78+
- All public APIs are exported through package index files

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"author": "Lan Tian <tian.lan@landing.ai>",
88
"license": "MIT",
99
"private": true,
10+
"packageManager": "yarn@1.22.19",
1011
"scripts": {
1112
"build": "npx lerna run build",
1213
"tsc": "npx lerna run tsc",

packages/core/lib/utils/annotationUtils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { Annotation, InferenceResult, ObjectDetectionPrediction, SegmentationPrediction } from '../types';
2-
import { hexToRgb, palette } from './colorUtils';
2+
import { hexToRgb, palette as defaultPalette } from './colorUtils';
33

44
/**
55
* Convert server format predictions into a list of {@link Annotation} for easy rendering
6+
* @param inferenceResult - The inference result from the API
7+
* @param customPalette - Optional custom color palette to use instead of the default
68
*/
7-
export function predictionsToAnnotations(inferenceResult?: InferenceResult | null) {
9+
export function predictionsToAnnotations(inferenceResult?: InferenceResult | null, customPalette?: string[]) {
810
if (!inferenceResult) {
911
return [];
1012
}
13+
const palette = customPalette || defaultPalette;
1114
const { backbonepredictions, predictions } = inferenceResult;
1215
const predictionsMap = predictions.bitmaps ?? backbonepredictions?.bitmaps ?? backbonepredictions;
1316
return Object.entries(predictionsMap || []).map(([id, prediction]) => ({

packages/react/lib/components/InferenceResult.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export interface InferenceResultProps {
1515
* Show labels for predicted annotations. Default is false.
1616
*/
1717
showLabels?: boolean;
18+
/**
19+
* Custom color palette for annotations. If not provided, uses the default palette.
20+
* Should be an array of hex color strings (e.g. ['#FF0000', '#00FF00', '#0000FF']).
21+
*/
22+
customPalette?: string[];
1823
/**
1924
* Called when there is predict error.
2025
*/
@@ -29,16 +34,16 @@ export interface InferenceResultProps {
2934
* Also provides summaries of the results.
3035
*/
3136
export const InferenceResult: React.FC<InferenceResultProps> = (props) => {
32-
const { image, showLabels = false, onPredictError } = props;
37+
const { image, showLabels = false, customPalette, onPredictError } = props;
3338
const apiInfo = useInferenceContext();
3439

3540
const imageRef = useRef<HTMLImageElement>(null);
3641

3742
// inference results
3843
const [inferenceResult, setInferenceResult] = useState<InferenceResultType>();
3944
const annotations = useMemo(() => {
40-
return predictionsToAnnotations(inferenceResult);
41-
}, [inferenceResult]);
45+
return predictionsToAnnotations(inferenceResult, customPalette);
46+
}, [inferenceResult, customPalette]);
4247
const className = useMemo(() => {
4348
return inferenceResult?.predictions?.labelName ?? '';
4449
}, [inferenceResult]);

0 commit comments

Comments
 (0)