@buildcanada/charts 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -23
- package/src/grapher/controls/ContentSwitchers.tsx +1 -1
- package/src/grapher/core/GrapherState.tsx +1 -4
- package/src/grapher/entitySelector/EntitySelector.tsx +1 -1
- package/src/grapher/lineCharts/LineChartHelpers.ts +1 -1
- package/src/grapher/slopeCharts/SlopeChartHelpers.ts +1 -1
- package/src/grapher/tabs/Tabs.tsx +1 -1
- package/src/types/domainTypes/ContentGraph.ts +1 -1
- package/src/types/index.ts +1 -1
- package/LICENSE.md +0 -8
- package/README.md +0 -113
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildcanada/charts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A configurable data visualization library for creating interactive charts. Extracted from Our World in Data's Grapher.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -32,16 +32,10 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"engines": {
|
|
36
|
-
"node": ">=22.0"
|
|
37
|
-
},
|
|
38
35
|
"scripts": {
|
|
39
|
-
"build": "storybook build -o storybook-static",
|
|
40
36
|
"typecheck": "tsc --noEmit",
|
|
41
37
|
"test": "vitest run",
|
|
42
|
-
"test:watch": "vitest"
|
|
43
|
-
"storybook": "storybook dev -p 6006",
|
|
44
|
-
"serve-storybook": "serve storybook-static -p 6006"
|
|
38
|
+
"test:watch": "vitest"
|
|
45
39
|
},
|
|
46
40
|
"keywords": [
|
|
47
41
|
"charts",
|
|
@@ -70,6 +64,7 @@
|
|
|
70
64
|
"classnames": "^2.5.1",
|
|
71
65
|
"colorbrewer": "^1.3.0",
|
|
72
66
|
"d3": "^7.9.0",
|
|
67
|
+
"d3-transition": "^3.0.1",
|
|
73
68
|
"dayjs": "^1.11.11",
|
|
74
69
|
"fparser": "^3.1.0",
|
|
75
70
|
"fuzzysort": "^3.1.0",
|
|
@@ -99,9 +94,7 @@
|
|
|
99
94
|
"versor": "^0.2.0"
|
|
100
95
|
},
|
|
101
96
|
"devDependencies": {
|
|
102
|
-
"@storybook/
|
|
103
|
-
"@storybook/react": "^10.1.11",
|
|
104
|
-
"@storybook/react-vite": "^10.1.11",
|
|
97
|
+
"@storybook/react-dom-shim": "^10.1.11",
|
|
105
98
|
"@testing-library/dom": "^10.4.1",
|
|
106
99
|
"@testing-library/jest-dom": "^6.9.1",
|
|
107
100
|
"@testing-library/react": "^16.3.0",
|
|
@@ -113,25 +106,17 @@
|
|
|
113
106
|
"@types/lodash-es": "^4",
|
|
114
107
|
"@types/mousetrap": "^1.6.9",
|
|
115
108
|
"@types/papaparse": "^5.3.16",
|
|
116
|
-
"@types/react": "^19.2.2",
|
|
117
|
-
"@types/react-dom": "^19.2.2",
|
|
118
109
|
"@types/string-pixel-width": "^1.7.2",
|
|
119
110
|
"@types/topojson-client": "^3.1.1",
|
|
120
111
|
"@types/url-parse": "^1.4.8",
|
|
121
|
-
"
|
|
112
|
+
"debug": "^4.4.3",
|
|
122
113
|
"eslint": "^9.37.0",
|
|
123
114
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
124
115
|
"happy-dom": "^20.1.0",
|
|
125
116
|
"jsdom": "^27.4.0",
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"react-dom": "^19.2.0",
|
|
130
|
-
"sass": "^1.77.0",
|
|
131
|
-
"serve": "^14.2.5",
|
|
132
|
-
"storybook": "^10.1.11",
|
|
133
|
-
"typescript": "~5.9.2",
|
|
134
|
-
"vite": "^6.0.0",
|
|
117
|
+
"object-assign": "^4.1.1",
|
|
118
|
+
"side-channel": "^1.1.0",
|
|
119
|
+
"timezone-mock": "^1.3.6",
|
|
135
120
|
"vitest": "^4.0.15"
|
|
136
121
|
}
|
|
137
122
|
}
|
|
@@ -42,7 +42,7 @@ export class ContentSwitchers extends React.Component<{
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
private isOverflowMenuOpen = false
|
|
45
|
-
private overflowButtonRef = React.createRef<
|
|
45
|
+
private overflowButtonRef = React.createRef<HTMLDivElement>()
|
|
46
46
|
|
|
47
47
|
@computed private get manager(): ContentSwitchersManager {
|
|
48
48
|
return this.props.manager
|
|
@@ -1641,10 +1641,7 @@ export class GrapherState {
|
|
|
1641
1641
|
if (!slot.allowMultiple)
|
|
1642
1642
|
validDimensions = _.uniqWith(
|
|
1643
1643
|
validDimensions,
|
|
1644
|
-
(
|
|
1645
|
-
a: OwidChartDimensionInterface,
|
|
1646
|
-
b: OwidChartDimensionInterface
|
|
1647
|
-
) =>
|
|
1644
|
+
(a, b) =>
|
|
1648
1645
|
a.property === slot.property &&
|
|
1649
1646
|
a.property === b.property
|
|
1650
1647
|
)
|
|
@@ -205,7 +205,7 @@ const EXTERNAL_SORT_INDICATOR_DEFINITIONS = [
|
|
|
205
205
|
// then check the label
|
|
206
206
|
const label = getTitleForSortColumnLabel(column)
|
|
207
207
|
// matches "gdp per capita" and content within parentheses
|
|
208
|
-
const potentialMatches =
|
|
208
|
+
const potentialMatches: string[] =
|
|
209
209
|
label.match(/\(.*?\)|(\bgdp per capita\b)/gi) ?? []
|
|
210
210
|
// filter for "gdp per capita" matches that are not within parentheses
|
|
211
211
|
const matches = potentialMatches.filter(
|
|
@@ -177,7 +177,7 @@ export function toRenderLineChartSeries(
|
|
|
177
177
|
// sort by interaction state so that foreground series
|
|
178
178
|
// are drawn on top of background series
|
|
179
179
|
if (isFocusModeActive || isHoverModeActive) {
|
|
180
|
-
series = _.sortBy(series, byHoverThenFocusState)
|
|
180
|
+
series = _.sortBy<RenderLineChartSeries>(series, byHoverThenFocusState)
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
return series
|
|
@@ -66,7 +66,7 @@ export function toRenderSlopeChartSeries(
|
|
|
66
66
|
// Sort by interaction state so that foreground series
|
|
67
67
|
// are drawn on top of background series
|
|
68
68
|
if (isHoverModeActive || isFocusModeActive) {
|
|
69
|
-
return _.sortBy(series, byHoverThenFocusState)
|
|
69
|
+
return _.sortBy<RenderSlopeChartSeries>(series, byHoverThenFocusState)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
return series
|
package/src/types/index.ts
CHANGED
package/LICENSE.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
Copyright (c) 2024 Our World in Data
|
|
3
|
-
|
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
-
|
|
6
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
-
|
|
8
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
# @buildcanada/charts
|
|
2
|
-
|
|
3
|
-
Part of the [Build Canada Design System](https://github.com/BuildCanada/bcds) monorepo.
|
|
4
|
-
|
|
5
|
-
A configurable data visualization library for creating interactive charts. Extracted from [Our World in Data's](https://ourworldindata.org) Grapher.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @buildcanada/charts
|
|
11
|
-
# or
|
|
12
|
-
bun add @buildcanada/charts
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Peer Dependencies
|
|
16
|
-
|
|
17
|
-
This library requires the following peer dependencies:
|
|
18
|
-
|
|
19
|
-
```json
|
|
20
|
-
{
|
|
21
|
-
"react": "^19.0.0",
|
|
22
|
-
"react-dom": "^19.0.0",
|
|
23
|
-
"mobx": "^6.13.0",
|
|
24
|
-
"mobx-react": "^7.6.0"
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Quick Start
|
|
29
|
-
|
|
30
|
-
```tsx
|
|
31
|
-
import {
|
|
32
|
-
ChartsProvider,
|
|
33
|
-
Grapher,
|
|
34
|
-
GrapherState,
|
|
35
|
-
GRAPHER_CHART_TYPES,
|
|
36
|
-
DimensionProperty,
|
|
37
|
-
createOwidTestDataset,
|
|
38
|
-
legacyToOwidTableAndDimensionsWithMandatorySlug,
|
|
39
|
-
} from "@buildcanada/charts"
|
|
40
|
-
import "@buildcanada/charts/styles.css"
|
|
41
|
-
|
|
42
|
-
// Define your data
|
|
43
|
-
const myData = [
|
|
44
|
-
{ year: 2020, entity: { id: 1, name: "Canada" }, value: 100 },
|
|
45
|
-
{ year: 2021, entity: { id: 1, name: "Canada" }, value: 120 },
|
|
46
|
-
]
|
|
47
|
-
|
|
48
|
-
const metadata = { id: 1, display: { name: "My Metric" } }
|
|
49
|
-
const dimensions = [{ variableId: 1, property: DimensionProperty.y }]
|
|
50
|
-
|
|
51
|
-
const dataset = createOwidTestDataset([{ data: myData, metadata }])
|
|
52
|
-
const table = legacyToOwidTableAndDimensionsWithMandatorySlug(dataset, dimensions, {})
|
|
53
|
-
|
|
54
|
-
const grapherState = new GrapherState({
|
|
55
|
-
title: "My Chart",
|
|
56
|
-
chartTypes: [GRAPHER_CHART_TYPES.LineChart],
|
|
57
|
-
dimensions,
|
|
58
|
-
})
|
|
59
|
-
grapherState.inputTable = table
|
|
60
|
-
|
|
61
|
-
function App() {
|
|
62
|
-
return (
|
|
63
|
-
<ChartsProvider>
|
|
64
|
-
<div style={{ width: "800px", height: "600px" }}>
|
|
65
|
-
<Grapher grapherState={grapherState} />
|
|
66
|
-
</div>
|
|
67
|
-
</ChartsProvider>
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Documentation
|
|
73
|
-
|
|
74
|
-
- **[Data Loading Guide](docs/DATA_LOADING_GUIDE.md)** - Complete guide on loading CSV/JSON data
|
|
75
|
-
- **[Publishing Guide](docs/PUBLISHING.md)** - How to publish to npm
|
|
76
|
-
|
|
77
|
-
## Development
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
bun install # Install dependencies
|
|
81
|
-
bun run storybook # Run Storybook on port 6006
|
|
82
|
-
bun run build # Build Storybook for production
|
|
83
|
-
bun test # Run tests
|
|
84
|
-
bun run typecheck # TypeScript check
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Components
|
|
88
|
-
|
|
89
|
-
### Grapher
|
|
90
|
-
|
|
91
|
-
The main charting component supporting multiple visualization types:
|
|
92
|
-
- Line charts
|
|
93
|
-
- Bar charts (discrete and stacked)
|
|
94
|
-
- Scatter plots
|
|
95
|
-
- World and regional maps
|
|
96
|
-
- Stacked area charts
|
|
97
|
-
- Slope charts
|
|
98
|
-
- Marimekko charts
|
|
99
|
-
|
|
100
|
-
### Explorer
|
|
101
|
-
|
|
102
|
-
A data explorer that wraps Grapher and adds additional controls for exploring complex datasets.
|
|
103
|
-
|
|
104
|
-
## Architecture
|
|
105
|
-
|
|
106
|
-
- Built with **React 19** and **MobX 6** for state management
|
|
107
|
-
- Uses TC-39 stage 3 decorators
|
|
108
|
-
- TypeScript throughout
|
|
109
|
-
- SCSS for styling with BEM conventions
|
|
110
|
-
|
|
111
|
-
## License
|
|
112
|
-
|
|
113
|
-
MIT
|