@bashem/rn-charts 0.0.2

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 (97) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +35 -0
  3. package/lib/module/index.js +14 -0
  4. package/lib/module/index.js.map +1 -0
  5. package/lib/module/package.json +1 -0
  6. package/lib/module/skia/AreaChart/AreaChart.js +122 -0
  7. package/lib/module/skia/AreaChart/AreaChart.js.map +1 -0
  8. package/lib/module/skia/AreaChart/useAreaChart.js +141 -0
  9. package/lib/module/skia/AreaChart/useAreaChart.js.map +1 -0
  10. package/lib/module/skia/BarChart/BarChart.js +127 -0
  11. package/lib/module/skia/BarChart/BarChart.js.map +1 -0
  12. package/lib/module/skia/BarChart/useBarChart.js +172 -0
  13. package/lib/module/skia/BarChart/useBarChart.js.map +1 -0
  14. package/lib/module/skia/Common/VerticalLabel.js +73 -0
  15. package/lib/module/skia/Common/VerticalLabel.js.map +1 -0
  16. package/lib/module/skia/HeatMap/HeatMap.js +76 -0
  17. package/lib/module/skia/HeatMap/HeatMap.js.map +1 -0
  18. package/lib/module/skia/HeatMap/useHeatMap.js +139 -0
  19. package/lib/module/skia/HeatMap/useHeatMap.js.map +1 -0
  20. package/lib/module/skia/PieChart/PieChart.js +96 -0
  21. package/lib/module/skia/PieChart/PieChart.js.map +1 -0
  22. package/lib/module/skia/PieChart/usePieChart.js +103 -0
  23. package/lib/module/skia/PieChart/usePieChart.js.map +1 -0
  24. package/lib/module/skia/Popup.js +58 -0
  25. package/lib/module/skia/Popup.js.map +1 -0
  26. package/lib/module/skia/Progress/LinearProgress.js +69 -0
  27. package/lib/module/skia/Progress/LinearProgress.js.map +1 -0
  28. package/lib/module/skia/Progress/SemiCircleProgress.js +70 -0
  29. package/lib/module/skia/Progress/SemiCircleProgress.js.map +1 -0
  30. package/lib/module/skia/RadarChart/RadarChart.js +98 -0
  31. package/lib/module/skia/RadarChart/RadarChart.js.map +1 -0
  32. package/lib/module/skia/RadarChart/useRadarChart.js +164 -0
  33. package/lib/module/skia/RadarChart/useRadarChart.js.map +1 -0
  34. package/lib/module/skia/common.js +65 -0
  35. package/lib/module/skia/common.js.map +1 -0
  36. package/lib/module/util/colors.js +182 -0
  37. package/lib/module/util/colors.js.map +1 -0
  38. package/lib/module/util/util.js +71 -0
  39. package/lib/module/util/util.js.map +1 -0
  40. package/lib/typescript/index.d.ts +2 -0
  41. package/lib/typescript/index.d.ts.map +1 -0
  42. package/lib/typescript/package.json +1 -0
  43. package/lib/typescript/src/index.d.ts +10 -0
  44. package/lib/typescript/src/index.d.ts.map +1 -0
  45. package/lib/typescript/src/skia/AreaChart/AreaChart.d.ts +25 -0
  46. package/lib/typescript/src/skia/AreaChart/AreaChart.d.ts.map +1 -0
  47. package/lib/typescript/src/skia/AreaChart/useAreaChart.d.ts +47 -0
  48. package/lib/typescript/src/skia/AreaChart/useAreaChart.d.ts.map +1 -0
  49. package/lib/typescript/src/skia/BarChart/BarChart.d.ts +30 -0
  50. package/lib/typescript/src/skia/BarChart/BarChart.d.ts.map +1 -0
  51. package/lib/typescript/src/skia/BarChart/useBarChart.d.ts +41 -0
  52. package/lib/typescript/src/skia/BarChart/useBarChart.d.ts.map +1 -0
  53. package/lib/typescript/src/skia/Common/VerticalLabel.d.ts +17 -0
  54. package/lib/typescript/src/skia/Common/VerticalLabel.d.ts.map +1 -0
  55. package/lib/typescript/src/skia/HeatMap/HeatMap.d.ts +33 -0
  56. package/lib/typescript/src/skia/HeatMap/HeatMap.d.ts.map +1 -0
  57. package/lib/typescript/src/skia/HeatMap/useHeatMap.d.ts +25 -0
  58. package/lib/typescript/src/skia/HeatMap/useHeatMap.d.ts.map +1 -0
  59. package/lib/typescript/src/skia/PieChart/PieChart.d.ts +27 -0
  60. package/lib/typescript/src/skia/PieChart/PieChart.d.ts.map +1 -0
  61. package/lib/typescript/src/skia/PieChart/usePieChart.d.ts +13 -0
  62. package/lib/typescript/src/skia/PieChart/usePieChart.d.ts.map +1 -0
  63. package/lib/typescript/src/skia/Popup.d.ts +26 -0
  64. package/lib/typescript/src/skia/Popup.d.ts.map +1 -0
  65. package/lib/typescript/src/skia/Progress/LinearProgress.d.ts +18 -0
  66. package/lib/typescript/src/skia/Progress/LinearProgress.d.ts.map +1 -0
  67. package/lib/typescript/src/skia/Progress/SemiCircleProgress.d.ts +18 -0
  68. package/lib/typescript/src/skia/Progress/SemiCircleProgress.d.ts.map +1 -0
  69. package/lib/typescript/src/skia/RadarChart/RadarChart.d.ts +27 -0
  70. package/lib/typescript/src/skia/RadarChart/RadarChart.d.ts.map +1 -0
  71. package/lib/typescript/src/skia/RadarChart/useRadarChart.d.ts +41 -0
  72. package/lib/typescript/src/skia/RadarChart/useRadarChart.d.ts.map +1 -0
  73. package/lib/typescript/src/skia/common.d.ts +31 -0
  74. package/lib/typescript/src/skia/common.d.ts.map +1 -0
  75. package/lib/typescript/src/util/colors.d.ts +4 -0
  76. package/lib/typescript/src/util/colors.d.ts.map +1 -0
  77. package/lib/typescript/src/util/util.d.ts +33 -0
  78. package/lib/typescript/src/util/util.d.ts.map +1 -0
  79. package/package.json +172 -0
  80. package/src/index.tsx +12 -0
  81. package/src/skia/AreaChart/AreaChart.tsx +140 -0
  82. package/src/skia/AreaChart/useAreaChart.ts +180 -0
  83. package/src/skia/BarChart/BarChart.tsx +190 -0
  84. package/src/skia/BarChart/useBarChart.ts +210 -0
  85. package/src/skia/Common/VerticalLabel.tsx +91 -0
  86. package/src/skia/HeatMap/HeatMap.tsx +106 -0
  87. package/src/skia/HeatMap/useHeatMap.ts +175 -0
  88. package/src/skia/PieChart/PieChart.tsx +114 -0
  89. package/src/skia/PieChart/usePieChart.ts +156 -0
  90. package/src/skia/Popup.tsx +125 -0
  91. package/src/skia/Progress/LinearProgress.tsx +84 -0
  92. package/src/skia/Progress/SemiCircleProgress.tsx +82 -0
  93. package/src/skia/RadarChart/RadarChart.tsx +159 -0
  94. package/src/skia/RadarChart/useRadarChart.ts +208 -0
  95. package/src/skia/common.ts +82 -0
  96. package/src/util/colors.ts +186 -0
  97. package/src/util/util.ts +89 -0
@@ -0,0 +1,186 @@
1
+ // source: https://github.com/colorjs/color-name/blob/master/index.js
2
+ export const colorNameToRBG: Record<string, [number, number, number]> = {
3
+ aliceblue: [240, 248, 255],
4
+ antiquewhite: [250, 235, 215],
5
+ aqua: [0, 255, 255],
6
+ aquamarine: [127, 255, 212],
7
+ azure: [240, 255, 255],
8
+ beige: [245, 245, 220],
9
+ bisque: [255, 228, 196],
10
+ black: [0, 0, 0],
11
+ blanchedalmond: [255, 235, 205],
12
+ blue: [0, 0, 255],
13
+ blueviolet: [138, 43, 226],
14
+ brown: [165, 42, 42],
15
+ burlywood: [222, 184, 135],
16
+ cadetblue: [95, 158, 160],
17
+ chartreuse: [127, 255, 0],
18
+ chocolate: [210, 105, 30],
19
+ coral: [255, 127, 80],
20
+ cornflowerblue: [100, 149, 237],
21
+ cornsilk: [255, 248, 220],
22
+ crimson: [220, 20, 60],
23
+ cyan: [0, 255, 255],
24
+ darkblue: [0, 0, 139],
25
+ darkcyan: [0, 139, 139],
26
+ darkgoldenrod: [184, 134, 11],
27
+ darkgray: [169, 169, 169],
28
+ darkgreen: [0, 100, 0],
29
+ darkgrey: [169, 169, 169],
30
+ darkkhaki: [189, 183, 107],
31
+ darkmagenta: [139, 0, 139],
32
+ darkolivegreen: [85, 107, 47],
33
+ darkorange: [255, 140, 0],
34
+ darkorchid: [153, 50, 204],
35
+ darkred: [139, 0, 0],
36
+ darksalmon: [233, 150, 122],
37
+ darkseagreen: [143, 188, 143],
38
+ darkslateblue: [72, 61, 139],
39
+ darkslategray: [47, 79, 79],
40
+ darkslategrey: [47, 79, 79],
41
+ darkturquoise: [0, 206, 209],
42
+ darkviolet: [148, 0, 211],
43
+ deeppink: [255, 20, 147],
44
+ deepskyblue: [0, 191, 255],
45
+ dimgray: [105, 105, 105],
46
+ dimgrey: [105, 105, 105],
47
+ dodgerblue: [30, 144, 255],
48
+ firebrick: [178, 34, 34],
49
+ floralwhite: [255, 250, 240],
50
+ forestgreen: [34, 139, 34],
51
+ fuchsia: [255, 0, 255],
52
+ gainsboro: [220, 220, 220],
53
+ ghostwhite: [248, 248, 255],
54
+ gold: [255, 215, 0],
55
+ goldenrod: [218, 165, 32],
56
+ gray: [128, 128, 128],
57
+ green: [0, 128, 0],
58
+ greenyellow: [173, 255, 47],
59
+ grey: [128, 128, 128],
60
+ honeydew: [240, 255, 240],
61
+ hotpink: [255, 105, 180],
62
+ indianred: [205, 92, 92],
63
+ indigo: [75, 0, 130],
64
+ ivory: [255, 255, 240],
65
+ khaki: [240, 230, 140],
66
+ lavender: [230, 230, 250],
67
+ lavenderblush: [255, 240, 245],
68
+ lawngreen: [124, 252, 0],
69
+ lemonchiffon: [255, 250, 205],
70
+ lightblue: [173, 216, 230],
71
+ lightcoral: [240, 128, 128],
72
+ lightcyan: [224, 255, 255],
73
+ lightgoldenrodyellow: [250, 250, 210],
74
+ lightgray: [211, 211, 211],
75
+ lightgreen: [144, 238, 144],
76
+ lightgrey: [211, 211, 211],
77
+ lightpink: [255, 182, 193],
78
+ lightsalmon: [255, 160, 122],
79
+ lightseagreen: [32, 178, 170],
80
+ lightskyblue: [135, 206, 250],
81
+ lightslategray: [119, 136, 153],
82
+ lightslategrey: [119, 136, 153],
83
+ lightsteelblue: [176, 196, 222],
84
+ lightyellow: [255, 255, 224],
85
+ lime: [0, 255, 0],
86
+ limegreen: [50, 205, 50],
87
+ linen: [250, 240, 230],
88
+ magenta: [255, 0, 255],
89
+ maroon: [128, 0, 0],
90
+ mediumaquamarine: [102, 205, 170],
91
+ mediumblue: [0, 0, 205],
92
+ mediumorchid: [186, 85, 211],
93
+ mediumpurple: [147, 112, 219],
94
+ mediumseagreen: [60, 179, 113],
95
+ mediumslateblue: [123, 104, 238],
96
+ mediumspringgreen: [0, 250, 154],
97
+ mediumturquoise: [72, 209, 204],
98
+ mediumvioletred: [199, 21, 133],
99
+ midnightblue: [25, 25, 112],
100
+ mintcream: [245, 255, 250],
101
+ mistyrose: [255, 228, 225],
102
+ moccasin: [255, 228, 181],
103
+ navajowhite: [255, 222, 173],
104
+ navy: [0, 0, 128],
105
+ oldlace: [253, 245, 230],
106
+ olive: [128, 128, 0],
107
+ olivedrab: [107, 142, 35],
108
+ orange: [255, 165, 0],
109
+ orangered: [255, 69, 0],
110
+ orchid: [218, 112, 214],
111
+ palegoldenrod: [238, 232, 170],
112
+ palegreen: [152, 251, 152],
113
+ paleturquoise: [175, 238, 238],
114
+ palevioletred: [219, 112, 147],
115
+ papayawhip: [255, 239, 213],
116
+ peachpuff: [255, 218, 185],
117
+ peru: [205, 133, 63],
118
+ pink: [255, 192, 203],
119
+ plum: [221, 160, 221],
120
+ powderblue: [176, 224, 230],
121
+ purple: [128, 0, 128],
122
+ rebeccapurple: [102, 51, 153],
123
+ red: [255, 0, 0],
124
+ rosybrown: [188, 143, 143],
125
+ royalblue: [65, 105, 225],
126
+ saddlebrown: [139, 69, 19],
127
+ salmon: [250, 128, 114],
128
+ sandybrown: [244, 164, 96],
129
+ seagreen: [46, 139, 87],
130
+ seashell: [255, 245, 238],
131
+ sienna: [160, 82, 45],
132
+ silver: [192, 192, 192],
133
+ skyblue: [135, 206, 235],
134
+ slateblue: [106, 90, 205],
135
+ slategray: [112, 128, 144],
136
+ slategrey: [112, 128, 144],
137
+ snow: [255, 250, 250],
138
+ springgreen: [0, 255, 127],
139
+ steelblue: [70, 130, 180],
140
+ tan: [210, 180, 140],
141
+ teal: [0, 128, 128],
142
+ thistle: [216, 191, 216],
143
+ tomato: [255, 99, 71],
144
+ turquoise: [64, 224, 208],
145
+ violet: [238, 130, 238],
146
+ wheat: [245, 222, 179],
147
+ white: [255, 255, 255],
148
+ whitesmoke: [245, 245, 245],
149
+ yellow: [255, 255, 0],
150
+ yellowgreen: [154, 205, 50]
151
+ };
152
+
153
+ export function hexToRgb(hex: string): [number, number, number] {
154
+ // Remove leading "#"
155
+ hex = hex.replace(/^#/, "");
156
+
157
+ // Expand shorthand form (#03F -> #0033FF)
158
+ if (hex.length === 3) {
159
+ hex = hex.split("").map(c => c + c).join("");
160
+ }
161
+
162
+ if (hex.length !== 6) {
163
+ throw new Error(`Invalid hex color: ${hex}`);
164
+ }
165
+
166
+ const num = parseInt(hex, 16);
167
+ const r = (num >> 16) & 0xff;
168
+ const g = (num >> 8) & 0xff;
169
+ const b = num & 0xff;
170
+
171
+ return [r, g, b];
172
+ }
173
+
174
+ export function lighten(color: string, amount: number): string {
175
+ let colorRgb: [number, number, number];
176
+ if (color.startsWith('#')) {
177
+ colorRgb = hexToRgb(color);
178
+ } else {
179
+ colorRgb = colorNameToRBG[color.toLowerCase()] as [number, number, number];
180
+ if (!colorRgb)
181
+ throw new Error(`Unsupported color format: ${color}`);
182
+ }
183
+
184
+ const [r, g, b] = colorRgb.map(c => Math.min(255, Math.floor(c + (255 - c) * amount))) as [number, number, number];
185
+ return `rgb(${r}, ${g}, ${b})`;
186
+ }
@@ -0,0 +1,89 @@
1
+ import { type ReactNode } from "react";
2
+
3
+ export function arrayFrom(maxValue: number, interval: number): number[] {
4
+ return Array.from({ length: Math.floor(maxValue / interval) + 1 }, (_, i) => i * interval);
5
+ }
6
+
7
+ export const stringToArray = (s: string, separator: string): string[] => {
8
+ return s.trim().split(separator);
9
+ };
10
+
11
+ export const increment = (char: string, by: number) => {
12
+ return String.fromCharCode(char.charCodeAt(0) + by);
13
+ };
14
+
15
+ export const getRandomInteger = (min: number, max: number) => {
16
+ return Math.floor(Math.random() * (max - min)) + min;
17
+ };
18
+
19
+ export const parseQuery = (queryString: string) => {
20
+ queryString = queryString.trim();
21
+ var query: Record<string, string> = {};
22
+ var pairs = (
23
+ queryString[0] === "?" ? queryString.substr(1) : queryString
24
+ ).split("&");
25
+ for (var i = 0; i < pairs.length; i++) {
26
+ var pair = pairs[i]!.split("=");
27
+ query[decodeURIComponent(pair[0]!)] = decodeURIComponent(pair[1] || "");
28
+ }
29
+ return query;
30
+ };
31
+
32
+ export const processNumber = (
33
+ num: number,
34
+ min: number,
35
+ max: number
36
+ ): number => {
37
+ if (isNaN(num)) return min;
38
+ if (num < min) return min;
39
+ if (num > max) return max;
40
+ return num;
41
+ };
42
+
43
+ /**
44
+ *
45
+ * @param {number} value - The number.
46
+ * @param {Intl.NumberFormatOptions} options - The options.
47
+ * Default Value: { maximumFractionDigits: 2, minimumFractionDigits: 0 }
48
+ * @returns {string} Returns the number in as formatted string.
49
+ *
50
+ * @example
51
+ * const result = getFormattedString(3.012)
52
+ * console.log(result); // 3.01
53
+ */
54
+ export function getFormattedString(value: number, options: Intl.NumberFormatOptions = { maximumFractionDigits: 2, minimumFractionDigits: 0 }) {
55
+ return value.toLocaleString("en-US", options);
56
+ }
57
+
58
+ export function isNumber<T>(value: T | number): value is number {
59
+ return (typeof value === 'number');
60
+ };
61
+
62
+ export function isNonNANNumber<T>(value: T | number): value is number {
63
+ return isNumber(value) && !isDefined(value);
64
+ }
65
+
66
+ export function isStringNumber(value: string): boolean {
67
+ return !isNaN(Number(value));
68
+ }
69
+
70
+ export function isDefined<T>(value: T | undefined | null): value is T {
71
+ return value !== undefined && value !== null && (typeof value !== 'number' || !isNaN(value));
72
+ };
73
+
74
+ export function isFunction(value: any): value is Function {
75
+ return typeof value === 'function';
76
+ }
77
+
78
+ export function isString(node: ReactNode): node is string {
79
+ return typeof node === "string";
80
+ }
81
+
82
+ type ArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift'
83
+ export type FixedLengthArray<T, L extends number, TObj = [T, ...Array<T>]> =
84
+ Pick<TObj, Exclude<keyof TObj, ArrayLengthMutationKeys>>
85
+ & {
86
+ readonly length: L
87
+ [ I : number ] : T
88
+ [Symbol.iterator]: () => IterableIterator<T>
89
+ }