Skip to content

Commit c539d61

Browse files
committed
feat: Automatic scaleTypes, elementTypes and stacking
1 parent a97ee83 commit c539d61

22 files changed

+1963
-2002
lines changed

docs/src/pages/docs/api.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ The individual datums in a series' `data` array can be anything you want! Just r
6363
React Charts uses axes to configure a fair amount of the chart. Axes handle many things like:
6464

6565
- Accessing chart values from your series' `Datum`s
66-
- Positioning your axis on the grid
67-
- Configuring the scale type for your axis
68-
- Configuring the element type for series that are tied to your axis
66+
- Optionally positioning your axis on the grid
67+
- Optionsally configuring the scale type for your axis
68+
- Optionsally configuring the element type for series that are tied to your axis
6969

7070
To date, we have the following scale types available:
7171

@@ -97,9 +97,6 @@ function MyChart() {
9797

9898
const primaryAxis = React.useMemo(
9999
(): AxisOptions<MyDatum> => ({
100-
isPrimary: true,
101-
scaleType: 'time',
102-
position: 'bottom',
103100
getValue: datum => datum.date,
104101
}),
105102
[]
@@ -108,8 +105,6 @@ function MyChart() {
108105
const secondaryAxes = React.useMemo(
109106
(): AxisOptions<MyDatum>[] => [
110107
{
111-
scaleType: 'linear',
112-
position: 'left',
113108
getValue: datum => datum.stars,
114109
},
115110
],
@@ -130,7 +125,7 @@ function MyChart() {
130125

131126
## Secondary Axis Element Types
132127

133-
Secondary axes can be configured to render their respective series using 3 different element types using the `AxisOptions<TDatum>['scaleType']` property:
128+
Secondary axes for the most part are automatic, but can be optionally configured to render their respective series using 3 different element types using the `AxisOptions<TDatum>['scaleType']` property:
134129

135130
- `line`
136131
- 1 Line per series (optional, eg. for Bubble/Scatter charts)
@@ -148,9 +143,7 @@ Example
148143
const secondaryAxes = React.useMemo(
149144
(): AxisOptions<MyDatum>[] => [
150145
{
151-
// scaleType: 'linear',
152-
// position: 'left',
153-
// getValue: datum => datum.stars,
146+
getValue: datum => datum.stars,
154147
elementType: 'bar',
155148
},
156149
],

docs/src/pages/docs/getting-started.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,14 @@ const data: Series[] = [
4343
```
4444

4545
- `primaryAxis: AxisOptions<TDatum>`
46-
- `isPrimary: true`
47-
- Scale Type
48-
- Position
4946
- Primary Value Accessor
5047
- `secondaryAxes: AxisOptions<TDatum>[]`
51-
- `isPrimary: boolean`
52-
- Scale Type
53-
- Position
5448
- Primary Value Accessor
5549

5650
```tsx
5751
function App() {
5852
const primaryAxis = React.useMemo(
5953
(): AxisOptions<DailyStars> => ({
60-
isPrimary: true,
61-
scaleType: 'time',
62-
position: 'bottom',
6354
getValue: datum => datum.date,
6455
}),
6556
[]
@@ -68,8 +59,6 @@ function App() {
6859
const secondaryAxes = React.useMemo(
6960
(): AxisOptions<DailyStars>[] => [
7061
{
71-
scaleType: 'linear',
72-
position: 'left',
7362
getValue: datum => datum.stars,
7463
},
7564
],

docs/src/pages/docs/overview.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Outside of providing custom styling and interfacing with some D3-supported optio
1010
You will, however, need general knowledge of:
1111

1212
- Your data. If you don't know the data you want to visualize, you're not going to get far at all!
13+
14+
It's optional for basic charting, but if you really want to be productive, you'll want understand:
15+
1316
- High-level Scale Architypes, the differences in what they do, and why you would use one over the other. Again, you do not need to know how to build your own scales or use `d3-scale`, but knowing the concepts and ideas behind scale types like `time`, `linear/continuous`, and `ordinal/band` will go a long way. [Learn more at Observerble](https://observablehq.com/@d3/learn-d3-scales).
1417

1518
I think that's it TBH! But this list might grow/shrink in the future. If you think something should be added to this list or changed in anyway, hit the **Edit this page on Github** link at the bottom!

examples/simple/src/components/Area.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export default function Bar() {
1313
AxisOptions<typeof data[number]["data"][number]>
1414
>(
1515
() => ({
16-
isPrimary: true,
17-
scaleType: "time",
18-
position: "bottom",
1916
getValue: (datum) => datum.primary as Date,
2017
}),
2118
[]
@@ -26,11 +23,10 @@ export default function Bar() {
2623
>(
2724
() => [
2825
{
29-
scaleType: "linear",
30-
position: "left",
3126
getValue: (datum) => datum.secondary,
32-
elementType: "area",
3327
stacked: true,
28+
// OR
29+
// elementType: "area",
3430
},
3531
],
3632
[]

examples/simple/src/components/Band.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export default function Band() {
1414
AxisOptions<typeof data[number]["data"][number]>
1515
>(
1616
() => ({
17-
isPrimary: true,
18-
scaleType: "band",
1917
position: "left",
2018
getValue: (datum) => datum.primary,
2119
}),
@@ -27,12 +25,9 @@ export default function Band() {
2725
>(
2826
() => [
2927
{
30-
scaleType: "linear",
3128
position: "top",
3229
show: false,
3330
getValue: (datum) => datum.secondary,
34-
elementType: "bar",
35-
stacked: true,
3631
stackOffset: stackOffsetWiggle,
3732
},
3833
],

examples/simple/src/components/Bar.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export default function Bar() {
1313
AxisOptions<typeof data[number]["data"][number]>
1414
>(
1515
() => ({
16-
isPrimary: true,
17-
scaleType: "band",
18-
position: "bottom",
1916
getValue: (datum) => datum.primary,
2017
}),
2118
[]
@@ -26,11 +23,7 @@ export default function Bar() {
2623
>(
2724
() => [
2825
{
29-
scaleType: "linear",
30-
position: "left",
3126
getValue: (datum) => datum.secondary,
32-
elementType: "bar",
33-
stacked: true,
3427
},
3528
],
3629
[]

examples/simple/src/components/BarHorizontal.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ export default function Bar() {
1313
AxisOptions<typeof data[number]["data"][number]>
1414
>(
1515
() => ({
16-
isPrimary: true,
17-
scaleType: "band",
1816
position: "left",
1917
getValue: (datum) => datum.primary,
2018
}),
@@ -26,11 +24,8 @@ export default function Bar() {
2624
>(
2725
() => [
2826
{
29-
scaleType: "linear",
3027
position: "bottom",
3128
getValue: (datum) => datum.secondary,
32-
elementType: "bar",
33-
stacked: true,
3429
},
3530
],
3631
[]

examples/simple/src/components/Bubble.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ export default function Bubble() {
1414
AxisOptions<typeof data[number]["data"][number]>
1515
>(
1616
() => ({
17-
isPrimary: true,
18-
scaleType: "time",
19-
position: "bottom",
2017
getValue: (datum) => datum.primary as unknown as Date,
2118
}),
2219
[]
@@ -27,10 +24,7 @@ export default function Bubble() {
2724
>(
2825
() => [
2926
{
30-
scaleType: "linear",
31-
position: "left",
3227
getValue: (datum) => datum.secondary,
33-
elementType: "line",
3428
},
3529
],
3630
[]

examples/simple/src/components/CustomStyles.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ function MyChart({
5151
AxisOptions<typeof data[number]["data"][number]>
5252
>(
5353
() => ({
54-
isPrimary: true,
55-
scaleType: "band",
56-
position: "bottom",
5754
getValue: (datum) => datum.primary,
5855
}),
5956
[]
@@ -64,11 +61,8 @@ function MyChart({
6461
>(
6562
() => [
6663
{
67-
scaleType: "linear",
68-
position: "left",
6964
getValue: (datum) => datum.secondary,
7065
elementType,
71-
stacked: true,
7266
},
7367
],
7468
[elementType]

examples/simple/src/components/DarkMode.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export default function DarkMode() {
1313
AxisOptions<typeof data[number]["data"][number]>
1414
>(
1515
() => ({
16-
isPrimary: true,
17-
scaleType: "time",
18-
position: "bottom",
1916
getValue: (datum) => datum.primary as unknown as Date,
2017
}),
2118
[]
@@ -26,10 +23,7 @@ export default function DarkMode() {
2623
>(
2724
() => [
2825
{
29-
scaleType: "linear",
30-
position: "left",
3126
getValue: (datum) => datum.secondary,
32-
elementType: "line",
3327
},
3428
],
3529
[]

0 commit comments

Comments
 (0)