Row 1 | +
+ |
+
Row 2 | +
+ |
+
Row 3 | +
+ |
+
Row 4 | +
+ |
+
Row 5 | +
+ |
+
Row 6 | +
+ |
+
Row 7 | +
+ |
+
Row 8 | +
+ |
+
Custom Callout Content
+{JSON.stringify(props, null, 2)}+
Custom Callout Content
+{JSON.stringify(props, null, 2)}+
Bar Custom Data
+Custom Callout Content
+{JSON.stringify(props, null, 2)}+
{JSON.stringify(props, null, 2)}+
+ { + "x": 20, + "values": [ + { + "legend": "metaData1", + "y": 50, + "color": "red", + "index": -1 + } + ] +} ++
+ { + "x": 20, + "values": [ + { + "legend": "metaData1", + "y": 50, + "color": "red", + "index": -1 + } + ] +} ++
Custom Callout Content
+Custom Callout Content
+Custom Callout Content
+{JSON.stringify(props, null, 2)}+
{ + (props?: P, defaultRender?: (props?: P) => JSX.Element | null): JSX.Element | null; +} + +export const formatDate = (date: Date, useUTC?: string | boolean) => { + const timeFormat = useUTC ? d3UtcFormat : d3TimeFormat; + return timeFormat('%-e %b %Y, %H:%M')(date) + (useUTC ? ' GMT' : ''); +}; diff --git a/packages/charts/react-charts-preview/library/src/utilities/vbc-utils.ts b/packages/charts/react-charts-preview/library/src/utilities/vbc-utils.ts new file mode 100644 index 0000000000000..3cd66e42a7973 --- /dev/null +++ b/packages/charts/react-charts-preview/library/src/utilities/vbc-utils.ts @@ -0,0 +1,33 @@ +export const getClosestPairDiffAndRange = (data: number[] | Date[]): [number, number] | undefined => { + if (data.length < 2) { + return; + } + data = data.sort((a, b) => + a instanceof Date ? (a as Date).getTime() - (b as Date).getTime() : (a as number) - (b as number), + ); + let minDiff = Number.MAX_VALUE; + for (let i = 1; i < data.length; i++) { + const diff = + data[i] instanceof Date + ? (data[i] as Date).getTime() - (data[i - 1] as Date).getTime() + : (data[i] as number) - (data[i - 1] as number); + minDiff = Math.min(minDiff, diff); + } + const range = + data[0] instanceof Date + ? (data[data.length - 1] as Date).getTime() - (data[0] as Date).getTime() + : (data[data.length - 1] as number) - (data[0] as number); + return [minDiff, range]; +}; + +export const calculateAppropriateBarWidth = (data: number[] | Date[], totalWidth: number) => { + const result = getClosestPairDiffAndRange(data); + if (!result || result[1] === 0) { + return 16; + } + const [closestPairDiff, range] = result; + // Refer to https://microsoft.github.io/fluentui-charting-contrib/docs/rfcs/fix-overlapping-bars-on-continuous-axes + // for the derivation of the following formula. + const barWidth = Math.round((totalWidth * closestPairDiff) / (2 * range + closestPairDiff)); + return barWidth; +}; diff --git a/packages/charts/react-charts-preview/library/tsconfig.json b/packages/charts/react-charts-preview/library/tsconfig.json new file mode 100644 index 0000000000000..c44b74a21ccee --- /dev/null +++ b/packages/charts/react-charts-preview/library/tsconfig.json @@ -0,0 +1,28 @@ +{ + "extends": "../../../../tsconfig.base.json", + "compilerOptions": { + "target": "ES2019", + "noEmit": true, + "isolatedModules": true, + "importHelpers": true, + "jsx": "react", + "noUnusedLocals": true, + "preserveConstEnums": true, + "strictPropertyInitialization": false, + "strictBindCallApply": false, + "strictFunctionTypes": false, + "strictNullChecks": true, + "noImplicitReturns": false, + "noEmitOnError": false + }, + "include": [], + "files": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/packages/charts/react-charts-preview/library/tsconfig.lib.json b/packages/charts/react-charts-preview/library/tsconfig.lib.json new file mode 100644 index 0000000000000..53066fdd11fff --- /dev/null +++ b/packages/charts/react-charts-preview/library/tsconfig.lib.json @@ -0,0 +1,22 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "lib": ["ES2019", "dom"], + "declaration": true, + "declarationDir": "../../../../dist/out-tsc/types", + "outDir": "../../../../dist/out-tsc", + "inlineSources": true, + "types": ["static-assets", "environment"] + }, + "exclude": [ + "./src/testing/**", + "**/*.spec.ts", + "**/*.spec.tsx", + "**/*.test.ts", + "**/*.test.tsx", + "**/*.stories.ts", + "**/*.stories.tsx" + ], + "include": ["./src/**/*.ts", "./src/**/*.tsx"] +} diff --git a/packages/charts/react-charts-preview/library/tsconfig.spec.json b/packages/charts/react-charts-preview/library/tsconfig.spec.json new file mode 100644 index 0000000000000..911456fe4b4d9 --- /dev/null +++ b/packages/charts/react-charts-preview/library/tsconfig.spec.json @@ -0,0 +1,17 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "outDir": "dist", + "types": ["jest", "node"] + }, + "include": [ + "**/*.spec.ts", + "**/*.spec.tsx", + "**/*.test.ts", + "**/*.test.tsx", + "**/*.d.ts", + "./src/testing/**/*.ts", + "./src/testing/**/*.tsx" + ] +} diff --git a/packages/charts/react-charts-preview/stories/.eslintrc.json b/packages/charts/react-charts-preview/stories/.eslintrc.json new file mode 100644 index 0000000000000..a41120835dcc9 --- /dev/null +++ b/packages/charts/react-charts-preview/stories/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "extends": ["plugin:@fluentui/eslint-plugin/react"], + "root": true, + "rules": { + "import/no-extraneous-dependencies": [ + "error", + { + "packageDir": [".", "../../../../"] + } + ] + } +} diff --git a/packages/charts/react-charts-preview/stories/.gitkeep b/packages/charts/react-charts-preview/stories/.gitkeep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/packages/charts/react-charts-preview/stories/.storybook/main.js b/packages/charts/react-charts-preview/stories/.storybook/main.js new file mode 100644 index 0000000000000..b380cd896aea1 --- /dev/null +++ b/packages/charts/react-charts-preview/stories/.storybook/main.js @@ -0,0 +1,14 @@ +const rootMain = require('../../../../../.storybook/main'); + +module.exports = /** @type {Omit