Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a09edc1
Limit d3 color to the utility needed
atisjai Nov 26, 2025
575ee59
Add support for vega lite for fluent charts
atisjai Nov 30, 2025
567feea
Improvements and bug fixes
atisjai Dec 6, 2025
2d7a086
Fix formatting
atisjai Dec 6, 2025
1c61cdf
Fix formatting
atisjai Dec 7, 2025
3386c5c
Fix lint errors
atisjai Dec 7, 2025
d095f0a
Fix lint errors
atisjai Dec 7, 2025
ed21fa2
Fix tests
atisjai Dec 18, 2025
cdd710e
Merge branch 'master' into usr/atisjai/vegaLiteFluent
atisjai Dec 18, 2025
eb9b320
Fix formatting
atisjai Dec 19, 2025
c8e285f
Merge branch 'master' into usr/atisjai/vegaLiteFluent
atisjai Jan 7, 2026
6bae230
Fix color fix bars issue
atisjai Jan 7, 2026
e3dd838
Fix test lint
atisjai Jan 7, 2026
1b91e49
Fix issue
atisjai Jan 7, 2026
3fb4e69
Fix issues
atisjai Jan 10, 2026
9eb6319
Fix tests
atisjai Jan 10, 2026
24eacdf
Fix bugs
atisjai Jan 16, 2026
e03162f
Merge branch 'master' into usr/atisjai/vegaLiteFluent
atisjai Jan 16, 2026
1dbdd1c
Fix formatting issues
atisjai Jan 17, 2026
db2e585
Update snapshots
atisjai Jan 17, 2026
23cce90
Merge branch 'master' into usr/atisjai/vegaLiteFluent
atisjai Jan 18, 2026
d6050b0
Update snapshots
atisjai Jan 18, 2026
2501a04
Update snapshots
atisjai Jan 18, 2026
c64fecf
Fix type check errors
atisjai Jan 18, 2026
9f82062
Fix formatting errors
atisjai Jan 18, 2026
15bee29
Fix non-deterministic IDs in VegaDeclarativeChart tests
atisjai Jan 18, 2026
5c882a1
Fix non-deterministic IDs in VegaDeclarativeChart tests
atisjai Jan 18, 2026
63a96f3
Merge branch 'usr/atisjai/vegaLiteFluent' of https://github.com/Atish…
atisjai Jan 18, 2026
fa663c2
Fix tests
atisjai Jan 18, 2026
00e2779
Fix issues
atisjai Jan 18, 2026
acc0033
Fix type check issues
atisjai Jan 19, 2026
8a61a3f
Fix lint errors
atisjai Jan 19, 2026
595efe6
Update storybook to load contrib repo schemas
atisjai Jan 19, 2026
e5ff246
Fix issue
atisjai Jan 19, 2026
4c72c6f
Fix issues
atisjai Jan 19, 2026
c2abb79
Fix issues
atisjai Jan 19, 2026
37c3428
Fix formatting
atisjai Jan 28, 2026
fabbd23
Fix test snapshots
atisjai Jan 29, 2026
05c97a8
Merge remote-tracking branch 'origin/master' into usr/atisjai/vegaLit…
atisjai Jan 29, 2026
59271f0
Fix test snapshots
atisjai Jan 29, 2026
e644a44
Update snapshots and restricted TZ to UTC
atisjai Jan 30, 2026
4df7f14
Fix imports
atisjai Jan 30, 2026
d9ffe65
Add change file
atisjai Jan 30, 2026
89d2070
Remove unnecessary files
atisjai Jan 30, 2026
5f01e0f
Cleanup
atisjai Feb 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "(feat): Add support for vega based schema",
"packageName": "@fluentui/react-charts",
"email": "[email protected]",
"dependentChangeType": "patch"
}
6 changes: 6 additions & 0 deletions packages/charts/react-charts/library/config/tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* eslint-disable @typescript-eslint/no-empty-function */
/** Jest test setup file. */
require('@testing-library/jest-dom');
const { resetIdsForTests } = require('@fluentui/react-utilities');

// Reset ID counter before each test for deterministic snapshots
beforeEach(() => {
resetIdsForTests();
});

// https://github.com/jsdom/jsdom/issues/3368
global.ResizeObserver = class ResizeObserver {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# Vega-Lite Color Scheme Examples

This directory contains examples demonstrating Vega-Lite color scheme support in the VegaLiteSchemaAdapter.

## Supported Color Schemes

The adapter maps standard Vega-Lite color schemes to Fluent UI DataViz colors:

### Fully Supported Schemes

| Vega-Lite Scheme | Description | Fluent Mapping |
| ---------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **category10** | D3 Category10 (10 colors) | Maps to Fluent qualitative colors (lightBlue, warning, lightGreen, error, orchid, pumpkin, hotPink, disabled, gold, teal) |
| **category20** | D3 Category20 (20 colors) | Maps to Fluent qualitative color pairs with light/dark shades |
| **tableau10** | Tableau 10 (10 colors) | Maps to Fluent colors matching Tableau's palette |
| **tableau20** | Tableau 20 (20 colors) | Maps to Fluent colors with light/dark pairs |

### Partially Supported (Fallback to Default)

The following schemes are recognized but currently fall back to the default Fluent palette with a warning:

- `accent`, `dark2`, `paired`, `pastel1`, `pastel2`, `set1`, `set2`, `set3`

### Custom Color Ranges

You can also specify custom colors using the `range` property, which takes priority over named schemes.

## Examples

### 1. Category10 Line Chart

**File**: `category10-line.json`

Multi-series line chart using the category10 scheme:

```json
{
"encoding": {
"color": {
"field": "category",
"type": "nominal",
"scale": { "scheme": "category10" }
}
}
}
```

### 2. Tableau10 Grouped Bar Chart

**File**: `tableau10-grouped-bar.json`

Grouped bar chart using the tableau10 scheme:

```json
{
"encoding": {
"color": {
"field": "product",
"type": "nominal",
"scale": { "scheme": "tableau10" }
}
}
}
```

### 3. Custom Color Range Donut Chart

**File**: `custom-range-donut.json`

Donut chart with custom color array:

```json
{
"encoding": {
"color": {
"field": "category",
"type": "nominal",
"scale": {
"range": ["#637cef", "#e3008c", "#2aa0a4", "#9373c0", "#13a10e"]
}
}
}
}
```

### 4. Category20 Stacked Bar Chart

**File**: `category20-stacked-bar.json`

Stacked bar chart using the category20 scheme for more colors:

```json
{
"encoding": {
"color": {
"field": "segment",
"type": "nominal",
"scale": { "scheme": "category20" }
}
}
}
```

## Color Priority

The adapter applies colors in the following priority order:

1. **Static color value** (`encoding.color.value`) - Highest priority
2. **Mark color** (`mark.color`)
3. **Custom range** (`encoding.color.scale.range`)
4. **Named scheme** (`encoding.color.scale.scheme`)
5. **Default Fluent palette** - Fallback

## Implementation Details

### VegaLiteColorAdapter

The color mapping is implemented in `VegaLiteColorAdapter.ts`:

```typescript
import { getVegaColor } from './VegaLiteColorAdapter';

// Get color for a series
const color = getVegaColor(
seriesIndex, // Series/color index
colorScheme, // e.g., 'category10'
colorRange, // Custom color array
isDarkTheme, // Light/dark theme support
);
```

### Scheme Mappings

Each Vega scheme is mapped to Fluent DataViz tokens that adapt to light/dark themes:

**Category10 Example**:

- Vega blue (#1f77b4) → Fluent `color26` (lightBlue.shade10)
- Vega orange (#ff7f0e) → Fluent `warning` (semantic warning color)
- Vega green (#2ca02c) → Fluent `color5` (lightGreen.primary)

**Tableau10 Example**:

- Tableau blue (#4e79a7) → Fluent `color1` (cornflower.tint10)
- Tableau orange (#f28e2c) → Fluent `color7` (pumpkin.primary)
- Tableau red (#e15759) → Fluent `error` (semantic error color)

## Testing

Unit tests for color scheme support are in `VegaLiteSchemaAdapterUT.test.tsx`:

```bash
npm test -- VegaLiteSchemaAdapterUT
```

**Test Coverage**:

- ✅ category10 scheme mapping
- ✅ tableau10 scheme mapping
- ✅ category20 scheme mapping
- ✅ Custom color ranges
- ✅ Priority order (range over scheme)
- ✅ Fallback to default palette

## Related Files

- **VegaLiteColorAdapter.ts** - Color scheme mapping logic
- **VegaLiteSchemaAdapter.ts** - Integration into chart transformers
- **colors.ts** - Fluent DataViz palette definitions
- **VegaLiteTypes.ts** - Type definitions for scale.scheme and scale.range

## Usage in Charts

All chart types support color schemes:

- ✅ LineChart
- ✅ VerticalBarChart
- ✅ VerticalStackedBarChart
- ✅ GroupedVerticalBarChart
- ✅ DonutChart
- ✅ AreaChart (inherits from LineChart)

## Dark Theme Support

Color mappings automatically adapt to dark theme:

```typescript
// Light theme: Uses first color in token array
// Dark theme: Uses second color in token array (if available)

const color = getVegaColor(0, 'category10', undefined, true); // isDarkTheme = true
```

Example:

- `color11` → Light: #3c51b4 (cornflower.shade20) | Dark: #93a4f4 (cornflower.tint30)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Multi-series line chart with category10 color scheme",
"mark": "line",
"data": {
"values": [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these json files being used. Remove if not

{ "month": "Jan", "sales": 28, "category": "Electronics" },
{ "month": "Feb", "sales": 55, "category": "Electronics" },
{ "month": "Mar", "sales": 43, "category": "Electronics" },
{ "month": "Apr", "sales": 91, "category": "Electronics" },
{ "month": "May", "sales": 81, "category": "Electronics" },
{ "month": "Jan", "sales": 35, "category": "Clothing" },
{ "month": "Feb", "sales": 60, "category": "Clothing" },
{ "month": "Mar", "sales": 50, "category": "Clothing" },
{ "month": "Apr", "sales": 75, "category": "Clothing" },
{ "month": "May", "sales": 70, "category": "Clothing" },
{ "month": "Jan", "sales": 20, "category": "Food" },
{ "month": "Feb", "sales": 45, "category": "Food" },
{ "month": "Mar", "sales": 38, "category": "Food" },
{ "month": "Apr", "sales": 62, "category": "Food" },
{ "month": "May", "sales": 58, "category": "Food" }
]
},
"encoding": {
"x": {
"field": "month",
"type": "ordinal",
"axis": { "title": "Month" }
},
"y": {
"field": "sales",
"type": "quantitative",
"axis": { "title": "Sales" }
},
"color": {
"field": "category",
"type": "nominal",
"scale": { "scheme": "category10" },
"legend": { "title": "Category" }
}
},
"title": "Sales by Category (Category10 Scheme)",
"width": 600,
"height": 400
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Stacked bar chart with category20 color scheme",
"mark": "bar",
"data": {
"values": [
{ "quarter": "Q1", "value": 10, "segment": "Segment 1" },
{ "quarter": "Q1", "value": 15, "segment": "Segment 2" },
{ "quarter": "Q1", "value": 8, "segment": "Segment 3" },
{ "quarter": "Q1", "value": 12, "segment": "Segment 4" },
{ "quarter": "Q2", "value": 12, "segment": "Segment 1" },
{ "quarter": "Q2", "value": 18, "segment": "Segment 2" },
{ "quarter": "Q2", "value": 10, "segment": "Segment 3" },
{ "quarter": "Q2", "value": 14, "segment": "Segment 4" },
{ "quarter": "Q3", "value": 14, "segment": "Segment 1" },
{ "quarter": "Q3", "value": 20, "segment": "Segment 2" },
{ "quarter": "Q3", "value": 12, "segment": "Segment 3" },
{ "quarter": "Q3", "value": 16, "segment": "Segment 4" },
{ "quarter": "Q4", "value": 16, "segment": "Segment 1" },
{ "quarter": "Q4", "value": 22, "segment": "Segment 2" },
{ "quarter": "Q4", "value": 14, "segment": "Segment 3" },
{ "quarter": "Q4", "value": 18, "segment": "Segment 4" }
]
},
"encoding": {
"x": {
"field": "quarter",
"type": "nominal",
"axis": { "title": "Quarter" }
},
"y": {
"field": "value",
"type": "quantitative",
"axis": { "title": "Value" }
},
"color": {
"field": "segment",
"type": "nominal",
"scale": { "scheme": "category20" },
"legend": { "title": "Segment" }
}
},
"title": "Quarterly Values by Segment (Category20 Scheme)",
"width": 600,
"height": 400
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Donut chart with custom color range",
"mark": { "type": "arc", "innerRadius": 50 },
"data": {
"values": [
{ "category": "A", "value": 28 },
{ "category": "B", "value": 55 },
{ "category": "C", "value": 43 },
{ "category": "D", "value": 91 },
{ "category": "E", "value": 81 }
]
},
"encoding": {
"theta": {
"field": "value",
"type": "quantitative"
},
"color": {
"field": "category",
"type": "nominal",
"scale": {
"range": ["#637cef", "#e3008c", "#2aa0a4", "#9373c0", "#13a10e"]
},
"legend": { "title": "Category" }
}
},
"title": "Distribution by Category (Custom Colors)",
"width": 400,
"height": 400
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Grouped bar chart with tableau10 color scheme",
"mark": "bar",
"data": {
"values": [
{ "category": "Q1", "value": 28, "product": "Product A" },
{ "category": "Q1", "value": 35, "product": "Product B" },
{ "category": "Q1", "value": 42, "product": "Product C" },
{ "category": "Q2", "value": 55, "product": "Product A" },
{ "category": "Q2", "value": 60, "product": "Product B" },
{ "category": "Q2", "value": 48, "product": "Product C" },
{ "category": "Q3", "value": 43, "product": "Product A" },
{ "category": "Q3", "value": 50, "product": "Product B" },
{ "category": "Q3", "value": 65, "product": "Product C" },
{ "category": "Q4", "value": 91, "product": "Product A" },
{ "category": "Q4", "value": 75, "product": "Product B" },
{ "category": "Q4", "value": 82, "product": "Product C" }
]
},
"encoding": {
"x": {
"field": "category",
"type": "nominal",
"axis": { "title": "Quarter" }
},
"y": {
"field": "value",
"type": "quantitative",
"axis": { "title": "Revenue ($K)" }
},
"color": {
"field": "product",
"type": "nominal",
"scale": { "scheme": "tableau10" },
"legend": { "title": "Product" }
},
"xOffset": { "field": "product" }
},
"title": "Quarterly Revenue by Product (Tableau10 Scheme)",
"width": 600,
"height": 400
}
Loading
Loading