-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-charts): vega lite schema support #35546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
AtishayMsft
wants to merge
45
commits into
microsoft:master
Choose a base branch
from
AtishayMsft:usr/atisjai/vegaLiteFluent
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 575ee59
Add support for vega lite for fluent charts
atisjai 567feea
Improvements and bug fixes
atisjai 2d7a086
Fix formatting
atisjai 1c61cdf
Fix formatting
atisjai 3386c5c
Fix lint errors
atisjai d095f0a
Fix lint errors
atisjai ed21fa2
Fix tests
atisjai cdd710e
Merge branch 'master' into usr/atisjai/vegaLiteFluent
atisjai eb9b320
Fix formatting
atisjai c8e285f
Merge branch 'master' into usr/atisjai/vegaLiteFluent
atisjai 6bae230
Fix color fix bars issue
atisjai e3dd838
Fix test lint
atisjai 1b91e49
Fix issue
atisjai 3fb4e69
Fix issues
atisjai 9eb6319
Fix tests
atisjai 24eacdf
Fix bugs
atisjai e03162f
Merge branch 'master' into usr/atisjai/vegaLiteFluent
atisjai 1dbdd1c
Fix formatting issues
atisjai db2e585
Update snapshots
atisjai 23cce90
Merge branch 'master' into usr/atisjai/vegaLiteFluent
atisjai d6050b0
Update snapshots
atisjai 2501a04
Update snapshots
atisjai c64fecf
Fix type check errors
atisjai 9f82062
Fix formatting errors
atisjai 15bee29
Fix non-deterministic IDs in VegaDeclarativeChart tests
atisjai 5c882a1
Fix non-deterministic IDs in VegaDeclarativeChart tests
atisjai 63a96f3
Merge branch 'usr/atisjai/vegaLiteFluent' of https://github.com/Atish…
atisjai fa663c2
Fix tests
atisjai 00e2779
Fix issues
atisjai acc0033
Fix type check issues
atisjai 8a61a3f
Fix lint errors
atisjai 595efe6
Update storybook to load contrib repo schemas
atisjai e5ff246
Fix issue
atisjai 4c72c6f
Fix issues
atisjai c2abb79
Fix issues
atisjai 37c3428
Fix formatting
atisjai fabbd23
Fix test snapshots
atisjai 05c97a8
Merge remote-tracking branch 'origin/master' into usr/atisjai/vegaLit…
atisjai 59271f0
Fix test snapshots
atisjai e644a44
Update snapshots and restricted TZ to UTC
atisjai 4df7f14
Fix imports
atisjai d9ffe65
Add change file
atisjai 89d2070
Remove unnecessary files
atisjai 5f01e0f
Cleanup
atisjai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-charts-41b1a74d-095a-448d-80ec-c3156292b6a2.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
...react-charts/library/docs/examples/declarative/vegalite/color-schemes/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
45 changes: 45 additions & 0 deletions
45
...eact-charts/library/docs/examples/declarative/vegalite/color-schemes/category10-line.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": [ | ||
| { "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 | ||
| } | ||
46 changes: 46 additions & 0 deletions
46
...arts/library/docs/examples/declarative/vegalite/color-schemes/category20-stacked-bar.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
31 changes: 31 additions & 0 deletions
31
...t-charts/library/docs/examples/declarative/vegalite/color-schemes/custom-range-donut.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
43 changes: 43 additions & 0 deletions
43
...harts/library/docs/examples/declarative/vegalite/color-schemes/tableau10-grouped-bar.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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