Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .storybook/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const CloudThemeLight = create({
inputTextColor: 'black',
inputBorderRadius: 4,

brandUrl: 'https://github.com/gravity-ui/uikit',
brandUrl: 'https://github.com/gravity-ui/charts',
brandTitle: `<div style="font-size: 18px; color: #027bf3; font-weight: 600; margin-top: -6px; margin-bottom: 2px;">Gravity UI</div>
<div style="font-size: 14px;color: #7d7d7d;font-weight: 400;">Charts</div>`,
});
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @gravity-ui/charts &middot; [![npm package](https://img.shields.io/npm/v/@gravity-ui/charts)](https://www.npmjs.com/package/@gravity-ui/charts) [![CI](https://img.shields.io/github/actions/workflow/status/gravity-ui/charts/.github/workflows/ci.yml?label=CI&logo=github)](https://github.com/gravity-ui/charts/actions/workflows/ci.yml?query=branch:main) [![storybook](https://img.shields.io/badge/Storybook-deployed-ff4685)](https://preview.gravity-ui.com/charts/)
# Gravity Charts &middot; [![npm package](https://img.shields.io/npm/v/@gravity-ui/charts)](https://www.npmjs.com/package/@gravity-ui/charts) [![CI](https://img.shields.io/github/actions/workflow/status/gravity-ui/charts/.github/workflows/ci.yml?label=CI&logo=github)](https://github.com/gravity-ui/charts/actions/workflows/ci.yml?query=branch:main) [![storybook](https://img.shields.io/badge/Storybook-deployed-ff4685)](https://preview.gravity-ui.com/charts/)

> [!WARNING]
> The library may have major changes in minor releases while it is on version `0.*.*`.
Expand Down
4 changes: 2 additions & 2 deletions docs/diplodoc/index.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: Gravity UI Charts
title: Gravity Charts
base: ./
meta:
title: Gravity UI Charts
title: Gravity Charts
noIndex: true
links:
- title: Overview
Expand Down
6 changes: 3 additions & 3 deletions docs/diplodoc/pages/overview.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Overview

## About Gravity UI Charts
## About Gravity Charts

**Gravity UI Charts** is a charting library built with [D3](https://d3js.org/) and [React](https://react.dev/). It's designed as part of the [Gravity UI](https://gravity-ui.com/) ecosystem and provides powerful data visualization capabilities for modern web applications through simple configuration objects.
**Gravity Charts** is a charting library built with [D3](https://d3js.org/) and [React](https://react.dev/). It's designed as part of the [Gravity UI](https://gravity-ui.com/) ecosystem and provides powerful data visualization capabilities for modern web applications through simple configuration objects.

{% note warning %}

While the library is in version `0.*.*`, minor releases may include incompatible changes to the API.

{% endnote %}

## What you can already do with Gravity UI Charts
## What you can already do with Gravity Charts

We have already implemented support for the main chart types:

Expand Down
61 changes: 61 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@gravity-ui/date-utils": "^2.5.4",
"@gravity-ui/i18n": "^1.6.0",
"d3": "^7.9.0",
"d3-sankey": "^0.12.3",
"lodash": "^4.17.21",
"tslib": "^2.6.2"
},
Expand Down Expand Up @@ -93,6 +94,7 @@
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.5.2",
"@types/d3": "^7.4.3",
"@types/d3-sankey": "^0.12.4",
"@types/d3-selection": "^3.0.11",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.12",
Expand Down
30 changes: 30 additions & 0 deletions src/__stories__/Sankey/Sankey.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type {Meta, StoryObj} from '@storybook/react';

import {ChartStory} from '../ChartStory';
import {sankeyPlaygroundData} from '../__data__';

const meta: Meta<typeof ChartStory> = {
title: 'Sankey',
component: ChartStory,
};

export default meta;

type Story = StoryObj<typeof ChartStory>;

export const SankeyPlayground = {
name: 'Playground',
args: {
data: sankeyPlaygroundData,
wrapperProps: {
styles: {
height: 560,
},
},
},
argTypes: {
data: {
control: 'object',
},
},
} satisfies Story;
20 changes: 13 additions & 7 deletions src/__stories__/Showcase.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import {
lineTwoYAxisData,
pieBasicData,
pieDonutData,
sankeyPlaygroundData,
scatterBasicData,
scatterTwoYAxisData,
treemapPlaygroundData,
} from './__data__';

const ShowcaseStory = () => {
Expand Down Expand Up @@ -171,15 +173,19 @@ const ShowcaseStory = () => {
<ChartStory data={scatterTwoYAxisData} />
</Col>
</Row>
{/* <Row space={1}>
<Text variant="header-2">Combined charts</Text>
<Row space={1}>
<Text variant="header-2">Other</Text>
</Row>
<Row space={3} style={{minHeight: 280}}>
<Col s={12}>
<Text variant="subheader-1">Line + Bar-X</Text>
<LineAndBarXCombinedChart />
<Row space={3}>
<Col s={12} m={6} l={6}>
<Text variant="subheader-1">Treemap</Text>
<ChartStory data={treemapPlaygroundData} />
</Col>
</Row> */}
<Col s={12} m={6} l={6}>
<Text variant="subheader-1">Sankey</Text>
<ChartStory data={sankeyPlaygroundData} />
</Col>
</Row>
</Container>
</div>
);
Expand Down
15 changes: 15 additions & 0 deletions src/__stories__/__data__/bar-x/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function prepareData(): ChartData {
type: 'bar-x',
data,
name: 'Games released',
borderRadius: 8,
},
],
},
Expand All @@ -42,6 +43,20 @@ function prepareData(): ChartData {
ticks: {
pixelInterval: 120,
},
plotLines: [
{
value: 100,
width: 2,
color: 'red',
dashStyle: 'Dash',
layerPlacement: 'after',
},
{
value: 200,
width: 1,
layerPlacement: 'before',
},
],
},
],
chart: {
Expand Down
1 change: 1 addition & 0 deletions src/__stories__/__data__/bar-y/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function prepareData(): ChartData {
dataLabels: {
enabled: true,
},
borderRadius: 4,
},
],
},
Expand Down
1 change: 1 addition & 0 deletions src/__stories__/__data__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './pie';
export * from './scatter';
export * from './treemap';
export * from './waterfall';
export * from './sankey';
6 changes: 4 additions & 2 deletions src/__stories__/__data__/pie/user-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ export const pieUserStylesData: ChartData = {
borderRadius: 5,
borderWidth: 3,
center: ['25%', null],
radius: '75%',
dataLabels: {enabled: false},
dataLabels: {enabled: true},
data: [
{
name: 'One 1',
value: 50,
radius: '80%',
},
{
name: 'Two 1',
value: 20,
radius: '90%',
},
{
name: 'Three 1',
value: 90,
radius: '100%',
},
],
},
Expand Down
1 change: 1 addition & 0 deletions src/__stories__/__data__/sankey/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './playground';
46 changes: 46 additions & 0 deletions src/__stories__/__data__/sankey/playground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {groups, sort} from 'd3';

import type {ChartData} from '../../../types';
import nintendoGames from '../nintendoGames';

function prepareData(): ChartData {
const gamesWithScore = nintendoGames.filter((game) => Math.round(game.user_score ?? 0));
const gamesByPlatform = groups(gamesWithScore, (item) => item.platform);
const data = gamesByPlatform.map(([platform, games]) => {
const links = sort(
groups(games, (game) => Math.round(game.user_score ?? 0)).map(([score, items]) => ({
name: String(score),
value: items.length,
})),
(d) => d.name,
);

return {
name: platform,
links,
};
});

const scores = sort(
Array.from(new Set(gamesWithScore.map((game) => Math.round(game.user_score ?? 0)))),
(d) => d,
).map((d) => ({name: String(d), links: []}));

return {
title: {
text: 'Average user score by platform',
},
tooltip: {enabled: true},
series: {
data: [
{
type: 'sankey',
data: [...data, ...scores],
name: 'Series 1',
},
],
},
};
}

export const sankeyPlaygroundData = prepareData();
Loading
Loading