Skip to content

Commit 6cb1533

Browse files
AtishayMsftatisjai
andauthored
update plotly test app (#105)
* Create v9 theme wrapper * Use v9 dropdown control * Add portal compat provider * Address comments --------- Co-authored-by: Atishay Jain (from Dev Box) <[email protected]>
1 parent 7f9bf9c commit 6cb1533

File tree

10 files changed

+2061
-16623
lines changed

10 files changed

+2061
-16623
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"appService.defaultWebAppToDeploy": "undefined/subscriptions/394a341b-4f31-4bea-8f00-9577217a04d2/resourceGroups/loopback/providers/Microsoft.Web/sites/fluentchartstest",
3+
"appService.deploySubpath": "build"
4+
}

apps/plotly_examples/package-lock.json

-16,275
This file was deleted.

apps/plotly_examples/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"private": true,
55
"dependencies": {
66
"@fluentui/react-charting": "^5.23.32",
7+
"@fluentui/react-portal-compat": "9.0.176",
8+
"@fluentui/react-components": "^9.21.0",
9+
"@types/d3-color": "^3.1.1",
10+
"d3-color": "^3.1.0",
711
"react": "^17.0.2",
812
"react-dom": "^17.0.2",
913
"react-scripts": "^5.0.1",

apps/plotly_examples/src/App.tsx

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
import React from 'react';
2-
import { DeclarativeChartBasicExample } from './components/DeclarativeChart';
2+
import {
3+
FluentProvider,
4+
webLightTheme,
5+
webDarkTheme,
6+
Dropdown,
7+
Option,
8+
SelectionEvents,
9+
OptionOnSelectData,
10+
Subtitle2
11+
} from '@fluentui/react-components';
12+
import { PortalCompatProvider } from '@fluentui/react-portal-compat';
13+
import { ChartWrapper } from './components/ChartWrapper';
314

415
const App: React.FC = () => {
16+
const [value, setValue] = React.useState("Light");
17+
18+
const onOptionSelect = (event: SelectionEvents, data: OptionOnSelectData): void => {
19+
setValue(data.optionText ?? "Light");
20+
};
21+
522
return (
623
<div>
7-
<h1>Data Visualization</h1>
8-
<DeclarativeChartBasicExample />
24+
<FluentProvider theme={ value === "Light"? webLightTheme: webDarkTheme} targetDocument={document}>
25+
<PortalCompatProvider>
26+
<Subtitle2> Theme:</Subtitle2>&nbsp;&nbsp;
27+
<Dropdown
28+
value={value}
29+
onOptionSelect={onOptionSelect}
30+
>
31+
<Option>Light</Option>
32+
<Option>Dark</Option>
33+
</Dropdown>
34+
<ChartWrapper />
35+
</PortalCompatProvider>
36+
</FluentProvider>
937
</div>
1038
);
1139
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ThemeProvider, createTheme } from '@fluentui/react'
2+
import React from 'react';
3+
import { Subtitle1 } from "@fluentui/react-components";
4+
import { paletteSlots, semanticSlots } from "../theming/v8TokenMapping";
5+
import { DeclarativeChartBasicExample } from './DeclarativeChart';
6+
7+
export function ChartWrapper() {
8+
const v8Theme = createTheme({ palette: paletteSlots, semanticColors: semanticSlots }); //ToDo - Make the slot values dynamic
9+
return (
10+
<ThemeProvider theme={v8Theme}>
11+
<Subtitle1 align="center" style={{marginLeft:'30%'}}>Declarative chart using plotly schema</Subtitle1>
12+
<DeclarativeChartBasicExample />
13+
</ThemeProvider>
14+
);
15+
}
16+

apps/plotly_examples/src/components/DeclarativeChart.tsx

+22-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import * as React from 'react';
2-
import { Dropdown, IDropdownOption } from '@fluentui/react/lib/Dropdown';
32
import { TextField, ITextFieldStyles } from '@fluentui/react/lib/TextField';
3+
import {
4+
Dropdown,
5+
Option,
6+
SelectionEvents,
7+
OptionOnSelectData,
8+
Subtitle2
9+
} from '@fluentui/react-components';
410
import { DeclarativeChart, DeclarativeChartProps, IDeclarativeChart, Schema } from '@fluentui/react-charting';
511

612
interface IErrorBoundaryProps {
@@ -46,11 +52,6 @@ const schemasData = requireContext.keys().map((fileName: string) => ({
4652
schema: requireContext(fileName),
4753
}));
4854

49-
const options: IDropdownOption[] = schemasData.map((data) => ({
50-
key: (data.schema as { id: string }).id,
51-
text: data.fileName,
52-
}));
53-
5455
const dropdownStyles = { dropdown: { width: 200 } };
5556

5657
const textFieldStyles: Partial<ITextFieldStyles> = { root: { maxWidth: 300 } };
@@ -64,7 +65,7 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
6465
const selectedSchema = schemasData[0]?.schema || {};
6566
const { selectedLegends } = selectedSchema as any;
6667
this.state = {
67-
selectedChoice: (schemasData[0].schema as { id: string }).id || 'unknown', // Set the first file as the default choice if available
68+
selectedChoice: (schemasData[0].fileName) || 'unknown', // Set the first file as the default choice if available
6869
selectedSchema: selectedSchema,
6970
schemasData: schemasData,
7071
selectedLegends: JSON.stringify(selectedLegends),
@@ -80,9 +81,9 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
8081
});
8182
}
8283

83-
private _onChange = (ev: any, option?: IDropdownOption): void => {
84-
const selectedChoice = option?.key as string;
85-
const selectedSchema = this.state.schemasData.find((data) => (data.schema as { id: string }).id === selectedChoice)?.schema;
84+
private _onChange = (event: SelectionEvents, data: OptionOnSelectData): void => {
85+
const selectedChoice = data.optionText!;
86+
const selectedSchema = this.state.schemasData.find((s) => (s.schema as { id: string }).id === data.optionValue!)?.schema;
8687
const { selectedLegends } = selectedSchema as any;
8788
this.setState({ selectedChoice, selectedSchema, selectedLegends: JSON.stringify(selectedLegends) });
8889
};
@@ -130,13 +131,15 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
130131
return (
131132
<>
132133
<div style={{ display: 'flex' }}>
133-
<Dropdown
134-
label="Select a schema"
135-
options={options}
136-
onChange={this._onChange}
137-
selectedKey={this.state.selectedChoice}
138-
styles={dropdownStyles}
139-
/>
134+
<label> Select a schema:</label>&nbsp;&nbsp;&nbsp;
135+
<Dropdown
136+
value={this.state.selectedChoice}
137+
onOptionSelect={this._onChange}
138+
>
139+
{schemasData.map((data) => (
140+
<Option value={(data.schema as { id: string }).id}>{data.fileName}</Option>
141+
))}
142+
</Dropdown>
140143
&nbsp;&nbsp;&nbsp;
141144
</div>
142145
<br />
@@ -147,12 +150,12 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
147150
});
148151
}}
149152
>
150-
Download
153+
Download as Image
151154
</button>
152155
<div data-testid="chart-container" >
153156
<br />
154157
<br />
155-
<h2>{this.state.selectedChoice}. {selectedSchema.layout.title}</h2>
158+
<Subtitle2>{selectedSchema.layout.title}</Subtitle2>
156159
<br />
157160
<br />
158161
<ErrorBoundary>

0 commit comments

Comments
 (0)