Skip to content

feat(data-viz): add simple chart type support #4318

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

Open
wants to merge 26 commits into
base: docs-data-viz-base-chart
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dfcc8fc
feat(data-visualization): add initial supported charts
krisantrobus Apr 22, 2025
ffc2426
feat(data-visualization): axis titles
krisantrobus Apr 22, 2025
984f0b2
feat(data-visualization): include area chart
krisantrobus Apr 22, 2025
d3e2144
feat(data-visualization): additional example
krisantrobus Apr 23, 2025
718e80c
feat(data-visualization): tests
krisantrobus Apr 23, 2025
4ef5467
feat(data-visualization): refactor
krisantrobus Apr 23, 2025
4c6b80d
chore(data-visualization): lci checks
krisantrobus Apr 23, 2025
d5169fc
feat(data-visualization): changesets
krisantrobus Apr 23, 2025
c25b041
feat(data-visualization): animation boolean
krisantrobus Apr 24, 2025
26c20bc
feat(data-visualization): wip
krisantrobus Apr 25, 2025
ef8ccc2
feat(data-visualization): jsdoc and type cleanup
krisantrobus Apr 25, 2025
e67f1e3
feat(data-visualization): cedits and column styles
krisantrobus Apr 25, 2025
5a6b23a
feat(data-visualization): watermark on examples
krisantrobus Apr 25, 2025
aa47290
feat(data-visualization): update chart types content
krisantrobus Apr 28, 2025
6c1bce6
feat(data-visualization): adding typedocs
krisantrobus Apr 29, 2025
1609a2b
feat(data-visualization): chart option docs
krisantrobus Apr 29, 2025
f878f40
feat(data-visualization): cleanup chart options
krisantrobus Apr 29, 2025
cd18f45
Merge branch 'docs-data-viz-base-chart' of github.com:twilio-labs/pas…
krisantrobus Apr 29, 2025
e2b4870
Merge branch 'docs-data-viz-base-chart' of github.com:twilio-labs/pas…
krisantrobus Apr 29, 2025
835ff2e
feat(data-visualization): pr cleanup
krisantrobus Apr 29, 2025
65066c5
chore(typos): fix various typos
krisantrobus Apr 29, 2025
369105b
chore(typos): revert fix
krisantrobus Apr 29, 2025
a0b2ef3
Merge branches 'chart-types-line-column-support' and 'docs-data-viz-b…
krisantrobus Apr 29, 2025
e6d8b1f
Merge branch 'docs-data-viz-base-chart' of github.com:twilio-labs/pas…
krisantrobus Apr 30, 2025
ba1e786
chore(data-viz): update urls
krisantrobus Apr 30, 2025
b4dfd0f
Merge branch 'docs-data-viz-base-chart' of github.com:twilio-labs/pas…
krisantrobus May 1, 2025
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
6 changes: 6 additions & 0 deletions .changeset/serious-avocados-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/core": minor
"@twilio-paste/data-visualization-library": minor
---

[Data visualization library] added helper functions and types to provide support for creating highcharts options for supported chart types
6 changes: 6 additions & 0 deletions .changeset/twenty-rocks-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/chart-provider": minor
"@twilio-paste/core": minor
---

[Chart Provider] added the ability to use options for supported chart types
2 changes: 2 additions & 0 deletions packages/paste-core/components/chart-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@twilio-paste/box": "^11.0.0",
"@twilio-paste/color-contrast-utils": "^5.0.0",
"@twilio-paste/customization": "^9.0.0",
"@twilio-paste/data-visualization-library": "^6.0.1",
"@twilio-paste/design-tokens": "^10.3.0",
"@twilio-paste/style-props": "^10.0.0",
"@twilio-paste/styling-library": "^4.0.0",
Expand All @@ -45,6 +46,7 @@
"@twilio-paste/box": "^11.0.1",
"@twilio-paste/color-contrast-utils": "^5.0.0",
"@twilio-paste/customization": "^9.0.1",
"@twilio-paste/data-visualization-library": "^6.0.1",
"@twilio-paste/design-tokens": "^10.13.0",
"@twilio-paste/style-props": "^10.0.1",
"@twilio-paste/styling-library": "^4.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Box, safelySpreadBoxProps } from "@twilio-paste/box";
import type { BoxProps } from "@twilio-paste/box";
import { transformToHighchartsOptions } from "@twilio-paste/data-visualization-library";
import type { ChartTypeOptions } from "@twilio-paste/data-visualization-library";
import type { HTMLPasteProps } from "@twilio-paste/types";
import * as Highcharts from "highcharts";
import * as React from "react";
Expand All @@ -25,16 +27,47 @@ interface HighchartsOptions extends BaseChartProviderProps {
* @memberof ChartProviderProps
*/
highchartsOptions: Highcharts.Options;
pasteOptions?: never;
options?: never;
}

export type ChartProviderProps = HighchartsOptions;
interface ChartOptions extends BaseChartProviderProps {
/**
* Overrides the default element name to apply unique styles with the Customization Provider
* @default null
* @type {BoxProps['element']}
* @memberof ChartProviderProps
*/
highchartsOptions?: never;
options: ChartTypeOptions;
}

export type ChartProviderProps = HighchartsOptions | ChartOptions;

const ChartProvider = React.forwardRef<HTMLDivElement, ChartProviderProps>(
({ element = "CHART_PROVIDER", children, highchartsOptions, ...props }, ref) => {
({ element = "CHART_PROVIDER", children, highchartsOptions, options, ...props }, ref) => {
const [chart, setChart] = React.useState<Highcharts.Chart>();
const [chartRef, setChartRef] = React.useState<HTMLElement>();

if (highchartsOptions && !options) {
return (
<Box {...safelySpreadBoxProps(props)} ref={ref} element={element} position="relative">
<ChartContext.Provider
value={{
chart,
setChart,
chartRef,
setChartRef,
options: highchartsOptions,
}}
>
{children}
</ChartContext.Provider>
</Box>
);
}

const transformedOptions = transformToHighchartsOptions(options);

return (
<Box {...safelySpreadBoxProps(props)} ref={ref} element={element} position="relative">
<ChartContext.Provider
Expand All @@ -43,7 +76,7 @@ const ChartProvider = React.forwardRef<HTMLDivElement, ChartProviderProps>(
setChart,
chartRef,
setChartRef,
options: highchartsOptions,
options: transformedOptions,
}}
>
{children}
Expand Down
18 changes: 9 additions & 9 deletions packages/paste-core/components/chart-provider/type-docs.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{
"ChartProvider": {
"highchartsOptions": {
"type": "Options",
"defaultValue": "null",
"required": true,
"externalProp": false,
"description": "Overrides the default element name to apply unique styles with the Customization Provider"
},
"about": {
"type": "string",
"defaultValue": null,
Expand Down Expand Up @@ -486,6 +479,13 @@
"required": false,
"externalProp": true
},
"highchartsOptions": {
"type": "Options",
"defaultValue": "null",
"required": false,
"externalProp": false,
"description": "Overrides the default element name to apply unique styles with the Customization Provider"
},
"id": {
"type": "string",
"defaultValue": null,
Expand Down Expand Up @@ -1574,8 +1574,8 @@
"required": false,
"externalProp": true
},
"pasteOptions": {
"type": "never",
"options": {
"type": "ChartTypeOptions",
"defaultValue": null,
"required": false,
"externalProp": false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { renderHook } from "@testing-library/react";
import { Theme } from "@twilio-paste/theme";
import React from "react";

import { AreaChartConfig, AreaSeries } from "../../src";
import { handleAreaOptions } from "../../src/transformers/areaChart";

const container: React.FC<{ children: React.ReactNode }> = ({ children }) => (
<Theme.Provider theme="default">{children}</Theme.Provider>
);

const seriesData: AreaSeries[] = [
{
name: "Installation",
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
},
{
name: "Manufacturing",
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434],
},
];

const options: AreaChartConfig = {
series: seriesData,
type: "area",
};

describe("Area Chart Transformer", () => {
it("should transform area chart data correctly", () => {
const { result } = renderHook(() => handleAreaOptions(options), { wrapper: container });

expect(result.current.chart).toEqual(
expect.objectContaining({
type: "area",
}),
);

expect(result.current.plotOptions).toEqual(
expect.objectContaining({
series: {
stickyTracking: false,
},
}),
);

expect(result.current.series).toEqual(
expect.arrayContaining([
{
name: "Installation",
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
type: "area",
},
]),
);
});
});
Loading
Loading