@chipmobilesdk/rn-chart 0.1.1 → 0.2.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/CHANGELOG.md +126 -74
- package/README.md +337 -314
- package/package.json +46 -49
- package/skills/sdk-rn-chart/SKILL.md +1 -2
- package/src/a11y/summary.ts +170 -177
- package/src/contract/datasource.ts +126 -134
- package/src/contract/errors.ts +129 -133
- package/src/contract/format.ts +162 -168
- package/src/contract/interaction.ts +70 -71
- package/src/contract/marker.ts +75 -75
- package/src/contract/props.ts +57 -60
- package/src/contract/state.ts +88 -94
- package/src/contract/theme.ts +169 -139
- package/src/contract/value.ts +121 -125
- package/src/geometry/bar.ts +271 -256
- package/src/geometry/distribution.ts +197 -200
- package/src/geometry/heatmap.ts +189 -195
- package/src/geometry/hitTest.ts +117 -120
- package/src/geometry/layout.ts +162 -121
- package/src/geometry/markers.ts +55 -0
- package/src/geometry/path.ts +193 -199
- package/src/geometry/progress.ts +223 -204
- package/src/geometry/scale.ts +140 -146
- package/src/geometry/ticks.ts +145 -153
- package/src/geometry/timeSeries.ts +168 -158
- package/src/geometry/types.ts +94 -88
- package/src/index.ts +158 -176
- package/src/react/ChartBoundary.tsx +96 -96
- package/src/react/ChartFrame.tsx +583 -620
- package/src/react/ChartLegend.tsx +211 -177
- package/src/react/ChartThemeProvider.tsx +44 -48
- package/src/react/charts.tsx +154 -161
- package/src/react/useChartLayout.ts +124 -124
- package/src/react/useChartSelection.ts +152 -170
- package/src/render/Axis.tsx +120 -122
- package/src/render/Marks.tsx +173 -205
- package/src/validation/budgets.ts +103 -110
- package/src/validation/validateDatasource.ts +174 -174
package/src/contract/value.ts
CHANGED
|
@@ -1,125 +1,121 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Value semantics for @chipmobilesdk/rn-chart.
|
|
3
|
-
*
|
|
4
|
-
* The foundation of the whole contract. Four value classes, carried as a
|
|
5
|
-
* discriminated union with **no numeric field on the three non-value cases**.
|
|
6
|
-
*
|
|
7
|
-
* That shape is deliberate: with a nullable `number`, `value ?? 0` would
|
|
8
|
-
* compile, and turning a gap into a zero is the single most damaging thing a
|
|
9
|
-
* charting library can do to someone's data. Here there is simply no number to
|
|
10
|
-
* read unless the value is known.
|
|
11
|
-
*
|
|
12
|
-
* See specs/007-rn-chart-package/data-model.md §1 (FR-011, FR-012).
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/** A real observation, including a genuine `0`. */
|
|
16
|
-
export interface KnownValue {
|
|
17
|
-
readonly kind: 'known';
|
|
18
|
-
readonly value: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** We do not know this value. Never rendered as zero, never interpolated. */
|
|
22
|
-
export interface UnknownValue {
|
|
23
|
-
readonly kind: 'unknown';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** This value does not apply here. Excluded from totals and proportions. */
|
|
27
|
-
export interface NotApplicableValue {
|
|
28
|
-
readonly kind: 'notApplicable';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Hidden from this viewer: permission, or not enough data to disclose. */
|
|
32
|
-
export interface WithheldValue {
|
|
33
|
-
readonly kind: 'withheld';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type ValueState =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
export function
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
export
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
readonly
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
countedPoints: counted,
|
|
123
|
-
excludedPoints: excluded,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Value semantics for @chipmobilesdk/rn-chart.
|
|
3
|
+
*
|
|
4
|
+
* The foundation of the whole contract. Four value classes, carried as a
|
|
5
|
+
* discriminated union with **no numeric field on the three non-value cases**.
|
|
6
|
+
*
|
|
7
|
+
* That shape is deliberate: with a nullable `number`, `value ?? 0` would
|
|
8
|
+
* compile, and turning a gap into a zero is the single most damaging thing a
|
|
9
|
+
* charting library can do to someone's data. Here there is simply no number to
|
|
10
|
+
* read unless the value is known.
|
|
11
|
+
*
|
|
12
|
+
* See specs/007-rn-chart-package/data-model.md §1 (FR-011, FR-012).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** A real observation, including a genuine `0`. */
|
|
16
|
+
export interface KnownValue {
|
|
17
|
+
readonly kind: 'known';
|
|
18
|
+
readonly value: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** We do not know this value. Never rendered as zero, never interpolated. */
|
|
22
|
+
export interface UnknownValue {
|
|
23
|
+
readonly kind: 'unknown';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** This value does not apply here. Excluded from totals and proportions. */
|
|
27
|
+
export interface NotApplicableValue {
|
|
28
|
+
readonly kind: 'notApplicable';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Hidden from this viewer: permission, or not enough data to disclose. */
|
|
32
|
+
export interface WithheldValue {
|
|
33
|
+
readonly kind: 'withheld';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type ValueState = KnownValue | UnknownValue | NotApplicableValue | WithheldValue;
|
|
37
|
+
|
|
38
|
+
export type ValueKind = ValueState['kind'];
|
|
39
|
+
|
|
40
|
+
const UNKNOWN: UnknownValue = { kind: 'unknown' };
|
|
41
|
+
const NOT_APPLICABLE: NotApplicableValue = { kind: 'notApplicable' };
|
|
42
|
+
const WITHHELD: WithheldValue = { kind: 'withheld' };
|
|
43
|
+
|
|
44
|
+
export function known(value: number): KnownValue {
|
|
45
|
+
return { kind: 'known', value };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Note: shadows the `unknown` *type* keyword in value position only. TypeScript
|
|
50
|
+
* keeps type and value namespaces separate, so `x: unknown` still means the
|
|
51
|
+
* type even in modules that import this helper.
|
|
52
|
+
*/
|
|
53
|
+
export function unknown(): UnknownValue {
|
|
54
|
+
return UNKNOWN;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function notApplicable(): NotApplicableValue {
|
|
58
|
+
return NOT_APPLICABLE;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function withheld(): WithheldValue {
|
|
62
|
+
return WITHHELD;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function isKnown(v: ValueState): v is KnownValue {
|
|
66
|
+
return v.kind === 'known';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* True when the value must never reach a rendering, a label, a summary, or an
|
|
71
|
+
* interaction callback (FR-033, FR-053). Withheld values carry no number at
|
|
72
|
+
* all, so this is about intent rather than data hiding.
|
|
73
|
+
*/
|
|
74
|
+
export function isWithheld(v: ValueState): v is WithheldValue {
|
|
75
|
+
return v.kind === 'withheld';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* True when the point takes part in totals, proportions, and axis domains.
|
|
80
|
+
* `notApplicable` and `withheld` are excluded; excluding either makes a total
|
|
81
|
+
* incomplete (FR-013).
|
|
82
|
+
*/
|
|
83
|
+
export function participatesInTotals(v: ValueState): boolean {
|
|
84
|
+
return v.kind === 'known';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface TotalResult {
|
|
88
|
+
readonly total: number;
|
|
89
|
+
/** True when any point was excluded, so the total is not the whole picture. */
|
|
90
|
+
readonly incomplete: boolean;
|
|
91
|
+
readonly countedPoints: number;
|
|
92
|
+
readonly excludedPoints: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Sums known values and reports whether anything was left out (FR-013).
|
|
97
|
+
*
|
|
98
|
+
* `unknown` also excludes and marks the total incomplete: we cannot claim a sum
|
|
99
|
+
* is complete when part of the data is missing.
|
|
100
|
+
*/
|
|
101
|
+
export function sumKnown(values: readonly ValueState[]): TotalResult {
|
|
102
|
+
let total = 0;
|
|
103
|
+
let counted = 0;
|
|
104
|
+
let excluded = 0;
|
|
105
|
+
|
|
106
|
+
for (const v of values) {
|
|
107
|
+
if (v.kind === 'known') {
|
|
108
|
+
total += v.value;
|
|
109
|
+
counted += 1;
|
|
110
|
+
} else {
|
|
111
|
+
excluded += 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
total,
|
|
117
|
+
incomplete: excluded > 0,
|
|
118
|
+
countedPoints: counted,
|
|
119
|
+
excludedPoints: excluded,
|
|
120
|
+
};
|
|
121
|
+
}
|