Skip to content

Commit 7e88df2

Browse files
Add waterfall chart and remove schema validation
1 parent 149f1d0 commit 7e88df2

File tree

16 files changed

+3343
-2713
lines changed

16 files changed

+3343
-2713
lines changed

package-lock.json

Lines changed: 2098 additions & 1471 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@undp/data-viz",
3-
"version": "2.1.9",
3+
"version": "2.2.1",
44
"main": "./dist/index.cjs",
55
"module": "./dist/index.js",
66
"browser": "./dist/index.umd.js",
@@ -32,6 +32,11 @@
3232
"import": "./dist/ButterflyChart.js",
3333
"require": "./dist/ButterflyChart.cjs"
3434
},
35+
"./WaterfallChart": {
36+
"types": "./dist/WaterfallChart.d.ts",
37+
"import": "./dist/WaterfallChart.js",
38+
"require": "./dist/WaterfallChart.cjs"
39+
},
3540
"./CirclePackingGraph": {
3641
"types": "./dist/CirclePackingGraph.d.ts",
3742
"import": "./dist/CirclePackingGraph.js",
@@ -382,16 +387,6 @@
382387
"import": "./dist/transformData.js",
383388
"require": "./dist/transformData.cjs"
384389
},
385-
"./validateSchema": {
386-
"types": "./dist/validateSchema.d.ts",
387-
"import": "./dist/validateSchema.js",
388-
"require": "./dist/validateSchema.cjs"
389-
},
390-
"./getSchema": {
391-
"types": "./dist/getSchema.d.ts",
392-
"import": "./dist/getSchema.js",
393-
"require": "./dist/getSchema.cjs"
394-
},
395390
"./Types": {
396391
"types": "./dist/Types.d.ts",
397392
"import": "./dist/Types.js",
@@ -471,7 +466,6 @@
471466
"@dnd-kit/core": "^6.3.1",
472467
"@dnd-kit/modifiers": "^9.0.0",
473468
"@undp/design-system-react": "^1.5.5",
474-
"ajv": "^8.17.1",
475469
"dom-to-svg": "^0.12.2",
476470
"file-saver": "^2.0.5",
477471
"handlebars": "^4.7.8",
@@ -538,15 +532,14 @@
538532
},
539533
"handlebars": {
540534
"optional": true
541-
},
542-
"ajv": {
543-
"optional": true
544535
}
545536
},
546537
"optionalDependencies": {
547538
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
548539
},
549540
"devDependencies": {
541+
"@dnd-kit/core": "^6.3.1",
542+
"@dnd-kit/modifiers": "^9.0.0",
550543
"@mdx-js/loader": "^3.1.1",
551544
"@mdx-js/rollup": "^3.1.1",
552545
"@nabla/vite-plugin-eslint": "^2.0.6",
@@ -584,8 +577,10 @@
584577
"@types/three": "^0.180.0",
585578
"@typescript-eslint/eslint-plugin": "^8.42.0",
586579
"@typescript-eslint/parser": "^8.42.0",
580+
"@undp/design-system-react": "^1.5.5",
587581
"@vitejs/plugin-react": "^5.0.2",
588582
"autoprefixer": "^10.4.21",
583+
"dom-to-svg": "^0.12.2",
589584
"eslint": "^9.34.0",
590585
"eslint-config-love": "^122.0.0",
591586
"eslint-config-prettier": "^10.1.8",
@@ -597,13 +592,26 @@
597592
"eslint-plugin-react": "^7.37.5",
598593
"eslint-plugin-react-hooks": "^7.0.0",
599594
"eslint-plugin-storybook": "^9.1.4",
595+
"file-saver": "^2.0.5",
596+
"handlebars": "^4.7.8",
597+
"maplibre-gl": "^5.16.0",
598+
"marked": "^17.0.1",
599+
"math-expression-evaluator": "^2.0.7",
600+
"pmtiles": "^4.3.2",
600601
"postcss": "^8.5.6",
601602
"prettier": "^3.6.2",
603+
"react": "^19.2.3",
602604
"react-docgen-typescript": "^2.4.0",
605+
"react-dom": "^19.2.3",
606+
"react-globe.gl": "^2.37.0",
603607
"rimraf": "^6.0.1",
604608
"rollup-plugin-visualizer": "^6.0.3",
605609
"storybook": "^9.1.4",
610+
"tailwind-animate": "^0.2.10",
611+
"tailwind-merge": "^3.4.0",
606612
"tailwindcss": "^4.1.12",
613+
"tailwindcss-animate": "^1.0.7",
614+
"three": "^0.182.0",
607615
"typescript": "^5.9.2",
608616
"vite": "^7.1.4",
609617
"vite-plugin-dts": "^4.5.4"

readme.md

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### Getting Started
44

5-
[UNDP data viz library](https://dataviz.design.undp.org) is dedicated to providing a good development experience for data visualization specialists. Before starting, it is recommended to learn React first, and correctly install and configure Node.js v18 or above.
5+
[UNDP data viz library](https://dataviz.design.undp.org) is dedicated to providing a good development experience for data visualization specialists. Before starting, it is recommended to learn React first, and correctly install and configure Node.js v18 or above.
66

77
We also assumes that you have intermediate knowledge about HTML, CSS, and JavaScript/TypeScript, and React.
88

@@ -13,52 +13,59 @@ Detailed documentation can be found [here](https://dataviz.design.undp.org)
1313
NPM Package can be found [here](https://www.npmjs.com/package/@undp/data-viz)
1414

1515
### Installation
16+
1617
__Using npm__
18+
1719
```
1820
npm i @undp/data-viz
1921
```
2022

21-
2223
__Using yarn__
24+
2325
```
2426
yarn add @undp/data-viz
2527
```
2628

2729
### Import
30+
2831
It is recommended to import what you need and the use it. For example, import the `HorizontalBarGraph` like this:
32+
2933
```
3034
import { HorizontalBarGraph } from '@undp/data-viz'
3135
```
3236

37+
It is also recommended to import the css because some setting expect the CSS to be imported to look good. You can import the css file like this:
3338

34-
It is also recommended to import the css because some setting expect the CSS to be imported to look good. You can import the css file like this:
3539
```
3640
import '@undp/data-viz/style.css';
3741
```
3842

3943
### TypeScript
44+
4045
UNDP visualization library provides a built-in ts definition, you don't need to install any type definitions.
4146

4247
### Dependencies
48+
4349
The dependencies that are pre-installed wit the library:
50+
4451
* Various D3 libraries - For visualizations
45-
* d3-array
46-
* d3-delaunay
47-
* d3-force
48-
* d3-format
49-
* d3-geo
50-
* d3-hierarchy
51-
* d3-scale
52-
* d3-selection
53-
* d3-shape
54-
* d3-zoom
52+
* d3-array
53+
* d3-delaunay
54+
* d3-force
55+
* d3-format
56+
* d3-geo
57+
* d3-hierarchy
58+
* d3-scale
59+
* d3-selection
60+
* d3-shape
61+
* d3-zoom
5562
* Various Lodash libraries - For array and data manipulation
56-
* lodash.flattendeep
57-
* lodash.intersection
58-
* lodash.orderby
59-
* lodash.sortby
60-
* lodash.sum
61-
* lodash.uniqby
63+
* lodash.flattendeep
64+
* lodash.intersection
65+
* lodash.orderby
66+
* lodash.sortby
67+
* lodash.sum
68+
* lodash.uniqby
6269
* motion - For creating animations in the animated graphs
6370
* papaparse - For loading and parsing csv from links
6471
* simple-statistics - For statistical functions
@@ -67,12 +74,14 @@ The dependencies that are pre-installed wit the library:
6774
* modern-screenshot - For downloading div as images
6875
* react-csv - For generating a csv file
6976

70-
__Required peer dependencies__
77+
__Required peer dependencies__
78+
7179
* React (of course!) (Peer dependency)
7280
* React-dom (of course!) (Peer dependency)
7381
* @undp/design-system-react - For UI elements (Peer dependency)
7482

75-
__Optional peer dependencies__
83+
__Optional peer dependencies__
84+
7685
* maplibre-gl - For Maplibre maps (Peer optional dependency: only needed when using GeoHub maps)
7786
* pmtiles - For adding pmtiles to Maplibre maps (Peer optional dependency: only needed when using GeoHub maps)
7887
* dnd-kit - For creating comparison maps (Peer optional dependency: only needed when using GeoHub compare maps)
@@ -84,6 +93,7 @@ __Optional peer dependencies__
8493
### How to add a new chart or graph
8594

8695
Adding a new chart or graph to the library requires multiple steps:
96+
8797
* Add the code for the graph to `./src/Components/Elements/Graphs/` folder
8898
* Once the code is done add the id of the graph to either `GraphTypeForGriddedGraph` or `GeoHubGraphType` in `./src/Types.tsx` depending if you want it to be available in `GriddedGraphDashboard` or not
8999
* Add the missing settings to `GraphSettingsDataType` in `./src/Types.tsx`
@@ -95,13 +105,14 @@ Adding a new chart or graph to the library requires multiple steps:
95105

96106
Adding schema
97107
__Schemas are in different repo: [undp-viz-library-schema](https://github.com/UNDP-Data/undp-viz-library-schemas)
108+
98109
* Add the data schema for the graph and graph settings schema to the `dataSchema` folder.
99110
* Also add the missing properties to the `SettingSchema` in `settingSchema` folder
100111

101112
Adding documentation and stories in storybook:
113+
102114
* Add a new story in `./src/stories/Graph+Map+Chart` folder
103115
* Add a graph name and id to `GraphNames` in `./src/stories/assets/constants.ts`
104116
* Add a config file for the graph in `./src/stories/assets/config` folder
105117
* Add the graph in `./src/stories/assets/graphSettingsSelect.ts`
106118
* Add the graph in `./src/stories/assets/graphDataConfigSelect.ts`
107-

src/Components/Dashboard/GraphEl.tsx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { BeeSwarmChart } from '../Graphs/BeeSwarmChart';
3232
import { RadarChart } from '../Graphs/RadarChart';
3333
import { BulletChart } from '../Graphs/BulletChart';
3434
import { HybridMap } from '../Graphs/Maps/HybridMap';
35+
import { WaterfallChart } from '../Graphs/WaterfallChart';
3536

3637
import { getValues } from '@/Utils/getValues';
3738
import {
@@ -127,6 +128,7 @@ function GraphEl(props: Props) {
127128
dataCards: DataCards,
128129
radarChart: RadarChart,
129130
hybridMap: HybridMap,
131+
waterfallChart: WaterfallChart,
130132
};
131133
const getGraphProps = (graphType: GraphType) => {
132134
switch (graphType) {
@@ -199,6 +201,69 @@ function GraphEl(props: Props) {
199201
animate: settings?.animate,
200202
naLabel: settings?.naLabel,
201203
};
204+
case 'waterfallChart':
205+
return {
206+
customLayers: settings?.customLayers,
207+
precision: settings?.precision,
208+
theme: settings?.theme,
209+
dimmedOpacity: settings?.dimmedOpacity,
210+
data: graphData,
211+
colors: settings?.colors as string | string[] | undefined,
212+
graphTitle: settings?.graphTitle,
213+
graphDescription: settings?.graphDescription,
214+
footNote: settings?.footNote,
215+
height: settings?.height,
216+
width: settings?.width,
217+
suffix: settings?.suffix,
218+
prefix: settings?.prefix,
219+
sources: settings?.sources,
220+
barPadding: settings?.barPadding,
221+
showValues: settings?.showValues,
222+
showTicks: settings?.showTicks,
223+
leftMargin: settings?.leftMargin,
224+
rightMargin: settings?.rightMargin,
225+
truncateBy: settings?.truncateBy,
226+
colorDomain: settings?.colorDomain,
227+
colorLegendTitle:
228+
Object.keys(settings || {}).indexOf('colorLegendTitle') !== -1
229+
? settings?.colorLegendTitle
230+
: getValues('color', graphDataConfiguration || [], readableHeader || []),
231+
backgroundColor: settings?.backgroundColor,
232+
padding: settings?.padding,
233+
topMargin: settings?.topMargin,
234+
bottomMargin: settings?.bottomMargin,
235+
relativeHeight: settings?.relativeHeight,
236+
showLabels: settings?.showLabels,
237+
showColorScale: settings?.showColorScale,
238+
maxValue: settings?.maxValue,
239+
minValue: settings?.minValue,
240+
labelOrder: settings?.labelOrder,
241+
tooltip: settings?.tooltip,
242+
refValues: settings?.refValues,
243+
graphID: settings?.graphID,
244+
highlightedDataPoints: settings?.highlightedDataPoints,
245+
graphDownload: settings?.graphDownload,
246+
dataDownload: settings?.dataDownload,
247+
language: settings?.language,
248+
minHeight: settings?.minHeight,
249+
showNAColor: settings?.showNAColor,
250+
maxBarThickness: settings?.maxBarThickness,
251+
minBarThickness: settings?.minBarThickness,
252+
maxNumberOfBars: settings?.maxNumberOfBars,
253+
ariaLabel: settings?.ariaLabel,
254+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
255+
onSeriesMouseClick: (el: any) => {
256+
updateFilters?.(el.label);
257+
},
258+
detailsOnClick: settings?.detailsOnClick,
259+
barAxisTitle: settings?.barAxisTitle,
260+
noOfTicks: settings?.noOfTicks,
261+
styles: settings?.styles,
262+
classNames: settings?.classNames,
263+
filterNA: settings?.filterNA,
264+
animate: settings?.animate,
265+
naLabel: settings?.naLabel,
266+
};
202267
case 'groupedBarChart':
203268
return {
204269
timeline: settings?.timeline,

src/Components/Graphs/SankeyChart/Graph.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ export function Graph(props: Props) {
123123
.nodePadding(nodePadding)
124124
.size([graphWidth, graphHeight])
125125
.nodeAlign(sankeyCenter)
126-
.nodeSort(() => null)
127-
.linkSort(() => null)
126+
.nodeSort(null)
127+
.linkSort(null)
128128
: sankey()
129129
.nodeWidth(nodeWidth)
130130
.nodePadding(nodePadding)

0 commit comments

Comments
 (0)