Skip to content

Commit

Permalink
feat(website): add data visualization foundation page (#2236)
Browse files Browse the repository at this point in the history
* feat: add data viz foundations page

* feat: finish page, add library page

* chore: update yarnlock

* fix: broken link

* fix: pr feedback

* fix: add changelog

* chore: add changeset

* fix: add core to changelog

* fix: patch preview images

* chore: update copy

* chore: update data-viz package

* chore: fix conflicts

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
shleewhite and kodiakhq[bot] committed Mar 1, 2022
1 parent 2100371 commit 33c4368
Show file tree
Hide file tree
Showing 13 changed files with 417 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .changeset/wild-chicken-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@twilio-paste/data-visualization-library': patch
'@twilio-paste/core': patch
---

[Data Visualization] add changelog
3 changes: 3 additions & 0 deletions packages/paste-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@twilio-paste/combobox": "^9.0.2",
"@twilio-paste/combobox-primitive": "^0.3.2",
"@twilio-paste/customization": "^3.0.1",
"@twilio-paste/data-visualization-library": "^0.1.0",
"@twilio-paste/date-picker": "^1.0.1",
"@twilio-paste/design-tokens": "^7.1.0",
"@twilio-paste/disclosure": "^6.0.1",
Expand Down Expand Up @@ -108,6 +109,8 @@
"gatsby-transformer-json": "^2.2.26",
"gatsby-transformer-remark": "^2.6.53",
"gatsby-transformer-sharp": "^2.3.14",
"highcharts": "^9.3.3",
"highcharts-react-official": "^3.1.0",
"lodash": "^4.17.19",
"lottie-web": "^5.7.4",
"pretty-format": "^24.9.0",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const inversePairingTokens: TokenPair[] = [
{textToken: 'colorTextIconInverse', backgroundToken: 'colorBackgroundBodyInverse'},
];

const StyledSwatchGrid = styled.div<{numberColumns: number}>`
export const StyledSwatchGrid = styled.div<{numberColumns: number}>`
display: grid;
column-gap: ${themeGet('space.space70')};
row-gap: ${themeGet('space.space100')};
Expand Down Expand Up @@ -221,7 +221,7 @@ export const InversePairingSwatches: React.FC = () => {
);
};

const ImgCaption: React.FC = ({children}) => (
export const ImgCaption: React.FC = ({children}) => (
<Box as="p" marginTop="space40" marginBottom="space110">
<Text as="span" color="colorTextWeak" fontSize="fontSize20" lineHeight="lineHeight20">
<Text as="span" fontWeight="fontWeightBold" color="colorTextWeak" fontSize="fontSize20" lineHeight="lineHeight20">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import * as React from 'react';
import {Box} from '@twilio-paste/box';
import {ThemeContext, styled, themeGet} from '@twilio-paste/styling-library';
import type {ThemeShape} from '@twilio-paste/theme';
import {ColorSwatchText} from '../components/color-swatch/ColorSwatch';
import {StyledSwatchGrid, ImgCaption} from './ColorsFoundationExamples';

interface TokenData {
name: string;
value: string;
}

// Need to use styled div because the data-viz names aren't valid backgroundColors on Box
const StyledSwatch = styled.div<{backgroundColor: string}>`
position: relative;
border-radius: ${themeGet('radii.borderRadius20')};
background-color: ${(props) => props.backgroundColor};
height: ${themeGet('space.space110')};
`;

export const DataVizColorSwatches: React.FC = () => {
const context = React.useContext(ThemeContext) as ThemeShape;

// Adapted from the usePasteHighchartsTheme hook
const dataVizTokenValues: TokenData[] = React.useMemo(() => {
const collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
const tokenNames = Object.keys(context.dataVisualization) as Array<keyof ThemeShape['dataVisualization']>;

const sortedTokenNames = tokenNames.sort((a, b) => collator.compare(a, b));

return sortedTokenNames.map((name) => ({name, value: context.dataVisualization[name]}));
}, [context]);

return (
<Box as="ul" margin="space0" padding="space0" marginBottom="space70">
<StyledSwatchGrid numberColumns={5}>
{dataVizTokenValues.map(({name, value}) => (
<Box as="li" listStyleType="none">
<StyledSwatch backgroundColor={value} />
<ColorSwatchText>{name}</ColorSwatchText>
</Box>
))}
</StyledSwatchGrid>
</Box>
);
};

export const PieChartCaption: React.FC = () => (
<ImgCaption>
A white divider line is used between each section of the pie charts to create contrast and help distinguish the
difference between the categories.
</ImgCaption>
);

export const LineChartCaption: React.FC = () => (
<ImgCaption>
Different shapes are used at each point in the line charts to create additional visual distinction between each
category.
</ImgCaption>
);

export const LineChartOptions = {
title: {text: 'Solar Employment Growth by Sector, 2010-2016'},
subtitle: {text: 'Source: thesolarfoundation.com'},
series: [
{
name: 'Installation',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
},
{
name: 'Manufacturing',
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434],
},
{
name: 'Sales & Distribution',
data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387],
},
{
name: 'Project Development',
data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227],
},
{
name: 'Other',
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111],
},
],
};

export const LineChartExample = `
const LineChartExample = () => {
const themedLineChartOptions = usePasteHighchartsTheme(LineChartOptions);
return <HighchartsReact highcharts={Highcharts} options={themedLineChartOptions} />;
};
render(<LineChartExample />);
`.trim();
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {Text} from '@twilio-paste/text';
import {Heading} from '@twilio-paste/heading';
import {useTheme} from '@twilio-paste/theme';
import {PackageStatusLegend} from '../package-status-legend';
import {STORYBOOK_DOMAIN} from '../../../constants';
import type {SidebarCategoryRoutes} from '../../../constants';
import {STORYBOOK_DOMAIN, SidebarCategoryRoutes} from '../../../constants';
import GithubIcon from '../../icons/GithubIcon';
import StorybookIcon from '../../icons/StorybookIcon';
import {getOpengraphServiceUrl, getNameFromPackageName, getCategoryNameFromRoute} from '../../../utils/RouteUtils';
Expand Down Expand Up @@ -64,15 +63,21 @@ const ComponentHeader: React.FC<ComponentHeaderProps> = ({
display: 'inline-block',
};

const categoryName = getCategoryNameFromRoute(categoryRoute);
const isFoundations = categoryRoute === SidebarCategoryRoutes.FOUNDATIONS;
const shouldHavePreview = [SidebarCategoryRoutes.COMPONENTS, SidebarCategoryRoutes.PRIMITIVES].includes(
categoryRoute
);

return (
<Box>
{ogImagePath && (
{ogImagePath && shouldHavePreview && (
<Helmet>
<meta property="og:image" content={getOpengraphServiceUrl(ogImagePath)} />
</Helmet>
)}
<Box marginBottom="space50">
<Anchor href={categoryRoute}>{getCategoryNameFromRoute(categoryRoute)}</Anchor>
{isFoundations ? <>{categoryName}</> : <Anchor href={categoryRoute}>{categoryName}</Anchor>}
</Box>
<Box display="flex" alignItems="center" flexWrap="wrap" marginBottom="space70" rowGap="space70" maxWidth="size70">
<Box marginRight="space50">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ const SidebarNavigation: React.FC = () => {
</SidebarAnchor>
<SidebarSeparator />
<NavigationDisclosure buttonText="Foundations" categoryRoute={SidebarCategoryRoutes.FOUNDATIONS} level={0}>
<SidebarAnchor level={1} to={`${SidebarCategoryRoutes.FOUNDATIONS}/colors`}>
Colors
</SidebarAnchor>
<NavigationDisclosure
buttonText="Content"
categoryRoute={SidebarCategoryRoutes.CONTENT}
Expand All @@ -169,8 +172,8 @@ const SidebarNavigation: React.FC = () => {
Product style guide
</SidebarAnchor>
</NavigationDisclosure>
<SidebarAnchor level={1} to={`${SidebarCategoryRoutes.FOUNDATIONS}/colors`}>
Colors
<SidebarAnchor level={1} to={`${SidebarCategoryRoutes.FOUNDATIONS}/data-visualization`}>
Data visualization
</SidebarAnchor>
<SidebarAnchor
level={1}
Expand Down Expand Up @@ -329,6 +332,9 @@ const SidebarNavigation: React.FC = () => {
<SidebarAnchor level={2} to={`${SidebarCategoryRoutes.LIBRARIES}/codemods`}>
Codemods
</SidebarAnchor>
<SidebarAnchor level={2} to={`${SidebarCategoryRoutes.LIBRARIES}/data-visualization`}>
Data visualization
</SidebarAnchor>
</NavigationDisclosure>
</NavigationDisclosure>
<NavigationDisclosure
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
title: Data visualization library
description: A library that helps theme data visualizations with Paste tokens.
slug: /core/libraries/data-visualizatioln/
---

import {graphql} from 'gatsby';
import PackageJSON from '@twilio-paste/data-visualization-library/package.json';
import Changelog from '@twilio-paste/data-visualization-library/CHANGELOG.md';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import {usePasteHighchartsTheme} from '@twilio-paste/data-visualization-library';

import {SidebarCategoryRoutes} from '../../../../constants';

export const pageQuery = graphql`
{
mdx(fields: {slug: {eq: "/core/libraries/data-visualization/"}}) {
fileAbsolutePath
frontmatter {
slug
title
}
headings {
depth
value
}
}
}
`;

<ComponentHeader
name="Data visualization library"
categoryRoute={SidebarCategoryRoutes.LIBRARIES}
githubUrl="https://github.com/twilio-labs/paste/tree/main/packages/paste-libraries/data-visualization"
storybookUrl="/?path=/story/libraries-data-visualization"
packageName={PackageJSON.name}
version={PackageJSON.version}
description={PackageJSON.description}
/>

---

<contentwrapper>
<PageAside data={props.data.mdx} />
<content>

## Usage Guide

This package is meant to be used with another data visualization library to style visualizations.

### Installation

```bash
yarn add @twilio-paste/data-visualization-library - or - yarn add @twilio-paste/core/data-visualization-library
```

### usePasteHighchartsTheme

This is a React Hook to take a Highcharts config and add Paste colors and fonts.

```jsx
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import {usePasteHighchartsTheme} from '@twilio-paste/data-visualization-library';

const LineChartOptions = {
title: {text: 'Solar Employment Growth by Sector, 2010-2016'},
subtitle: {text: 'Source: thesolarfoundation.com'},
series: [
{
name: 'Installation',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
},
{
name: 'Manufacturing',
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434],
},
{
name: 'Sales & Distribution',
data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387],
},
{
name: 'Project Development',
data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227],
},
{
name: 'Other',
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111],
},
],
};

const LineChartExample = () => {
const themedLineChartOptions = usePasteHighchartsTheme(LineChartOptions);
return <HighchartsReact highcharts={Highcharts} options={themedLineChartOptions} />;
};
```

The hook adds [the following styles](https://github.com/twilio-labs/paste/blob/4aefbe75d7c34ebdab209be14073426c1632d8a9/packages/paste-libraries/data-visualization/src/usePasteHighchartsTheme.tsx#L42):

- `colors`: the colors Highcharts cycles through for the chart's series
- `chart`: the background color
- `title`, `subtitle`, `legend`, `credits`, `label`, and `tooltip`: the font, text colors, and background color
- `xAxis`, `yAxis`: the font, text colors, and the line and tick colors.

To learn more about the configurations available, check out [the Highcharts API documentation](https://api.highcharts.com/highcharts/).

<ChangelogRevealer>
<Changelog />
</ChangelogRevealer>

</content>

</contentwrapper>
21 changes: 5 additions & 16 deletions packages/paste-website/src/pages/foundations/colors/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ slug: /foundations/colors/
import {graphql} from 'gatsby';
import Img from 'gatsby-image';

import {Box} from '@twilio-paste/box';
import {Heading} from '@twilio-paste/heading';
import {Button} from '@twilio-paste/button';
import {Anchor} from '@twilio-paste/anchor';
import {Stack} from '@twilio-paste/stack';
import {Text} from '@twilio-paste/text';
import {DeleteIcon} from '@twilio-paste/icons/esm/DeleteIcon';

import {Callout, CalloutTitle, CalloutText} from '../../../components/callout';
Expand Down Expand Up @@ -83,19 +80,11 @@ export const pageQuery = graphql`

<content>

<Box marginBottom="space50">Foundations</Box>
<Box display="flex" alignItems="center" flexWrap="wrap" marginBottom="space70" rowGap="space70" maxWidth="size70">
<Box marginRight="space50">
<Heading as="h1" variant="heading10" marginBottom="space0">
{props.pageContext.frontmatter.title}
</Heading>
</Box>
</Box>
<Box maxWidth="size70">
<Text as="p" fontSize="fontSize40">
{props.pageContext.frontmatter.description}
</Text>
</Box>
<ComponentHeader
name={props.pageContext.frontmatter.title}
description={props.pageContext.frontmatter.description}
categoryRoute={SidebarCategoryRoutes.FOUNDATIONS}
/>

</content>

Expand Down
Loading

0 comments on commit 33c4368

Please sign in to comment.