@chipmobilesdk/rn-chart 0.2.0 → 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.
Files changed (38) hide show
  1. package/CHANGELOG.md +126 -115
  2. package/README.md +381 -381
  3. package/package.json +46 -49
  4. package/skills/sdk-rn-chart/SKILL.md +68 -69
  5. package/src/a11y/summary.ts +170 -177
  6. package/src/contract/datasource.ts +126 -136
  7. package/src/contract/errors.ts +129 -133
  8. package/src/contract/format.ts +162 -168
  9. package/src/contract/interaction.ts +70 -71
  10. package/src/contract/marker.ts +75 -75
  11. package/src/contract/props.ts +57 -60
  12. package/src/contract/state.ts +88 -94
  13. package/src/contract/theme.ts +169 -177
  14. package/src/contract/value.ts +121 -125
  15. package/src/geometry/bar.ts +271 -273
  16. package/src/geometry/distribution.ts +197 -203
  17. package/src/geometry/heatmap.ts +189 -195
  18. package/src/geometry/hitTest.ts +117 -120
  19. package/src/geometry/layout.ts +162 -173
  20. package/src/geometry/markers.ts +55 -57
  21. package/src/geometry/path.ts +193 -199
  22. package/src/geometry/progress.ts +223 -230
  23. package/src/geometry/scale.ts +140 -146
  24. package/src/geometry/ticks.ts +145 -153
  25. package/src/geometry/timeSeries.ts +168 -168
  26. package/src/geometry/types.ts +94 -94
  27. package/src/index.ts +158 -176
  28. package/src/react/ChartBoundary.tsx +96 -96
  29. package/src/react/ChartFrame.tsx +583 -622
  30. package/src/react/ChartLegend.tsx +211 -215
  31. package/src/react/ChartThemeProvider.tsx +44 -48
  32. package/src/react/charts.tsx +154 -161
  33. package/src/react/useChartLayout.ts +124 -124
  34. package/src/react/useChartSelection.ts +152 -170
  35. package/src/render/Axis.tsx +120 -122
  36. package/src/render/Marks.tsx +173 -205
  37. package/src/validation/budgets.ts +103 -110
  38. package/src/validation/validateDatasource.ts +174 -174
@@ -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
- | KnownValue
38
- | UnknownValue
39
- | NotApplicableValue
40
- | WithheldValue;
41
-
42
- export type ValueKind = ValueState['kind'];
43
-
44
- const UNKNOWN: UnknownValue = { kind: 'unknown' };
45
- const NOT_APPLICABLE: NotApplicableValue = { kind: 'notApplicable' };
46
- const WITHHELD: WithheldValue = { kind: 'withheld' };
47
-
48
- export function known(value: number): KnownValue {
49
- return { kind: 'known', value };
50
- }
51
-
52
- /**
53
- * Note: shadows the `unknown` *type* keyword in value position only. TypeScript
54
- * keeps type and value namespaces separate, so `x: unknown` still means the
55
- * type even in modules that import this helper.
56
- */
57
- export function unknown(): UnknownValue {
58
- return UNKNOWN;
59
- }
60
-
61
- export function notApplicable(): NotApplicableValue {
62
- return NOT_APPLICABLE;
63
- }
64
-
65
- export function withheld(): WithheldValue {
66
- return WITHHELD;
67
- }
68
-
69
- export function isKnown(v: ValueState): v is KnownValue {
70
- return v.kind === 'known';
71
- }
72
-
73
- /**
74
- * True when the value must never reach a rendering, a label, a summary, or an
75
- * interaction callback (FR-033, FR-053). Withheld values carry no number at
76
- * all, so this is about intent rather than data hiding.
77
- */
78
- export function isWithheld(v: ValueState): v is WithheldValue {
79
- return v.kind === 'withheld';
80
- }
81
-
82
- /**
83
- * True when the point takes part in totals, proportions, and axis domains.
84
- * `notApplicable` and `withheld` are excluded; excluding either makes a total
85
- * incomplete (FR-013).
86
- */
87
- export function participatesInTotals(v: ValueState): boolean {
88
- return v.kind === 'known';
89
- }
90
-
91
- export interface TotalResult {
92
- readonly total: number;
93
- /** True when any point was excluded, so the total is not the whole picture. */
94
- readonly incomplete: boolean;
95
- readonly countedPoints: number;
96
- readonly excludedPoints: number;
97
- }
98
-
99
- /**
100
- * Sums known values and reports whether anything was left out (FR-013).
101
- *
102
- * `unknown` also excludes and marks the total incomplete: we cannot claim a sum
103
- * is complete when part of the data is missing.
104
- */
105
- export function sumKnown(values: readonly ValueState[]): TotalResult {
106
- let total = 0;
107
- let counted = 0;
108
- let excluded = 0;
109
-
110
- for (const v of values) {
111
- if (v.kind === 'known') {
112
- total += v.value;
113
- counted += 1;
114
- } else {
115
- excluded += 1;
116
- }
117
- }
118
-
119
- return {
120
- total,
121
- incomplete: excluded > 0,
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
+ }