@bashem/rn-charts 0.0.3 → 0.0.5

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 (79) hide show
  1. package/README.md +1 -1
  2. package/lib/module/skia/AreaChart/AreaChart.js +60 -51
  3. package/lib/module/skia/AreaChart/AreaChart.js.map +1 -1
  4. package/lib/module/skia/AreaChart/useAreaChart.js +18 -14
  5. package/lib/module/skia/AreaChart/useAreaChart.js.map +1 -1
  6. package/lib/module/skia/BarChart/BarChart.js +156 -69
  7. package/lib/module/skia/BarChart/BarChart.js.map +1 -1
  8. package/lib/module/skia/BarChart/useBarChart.js +53 -41
  9. package/lib/module/skia/BarChart/useBarChart.js.map +1 -1
  10. package/lib/module/skia/Common/HorizontalLabelView.js +121 -0
  11. package/lib/module/skia/Common/HorizontalLabelView.js.map +1 -0
  12. package/lib/module/skia/Common/VerticalLabelView.js +100 -0
  13. package/lib/module/skia/Common/VerticalLabelView.js.map +1 -0
  14. package/lib/module/skia/Common/useComponentLayout.js +13 -0
  15. package/lib/module/skia/Common/useComponentLayout.js.map +1 -0
  16. package/lib/module/skia/HeatMap/DateHeatMap.js +472 -0
  17. package/lib/module/skia/HeatMap/DateHeatMap.js.map +1 -0
  18. package/lib/module/skia/HeatMap/HeatMap.js +121 -33
  19. package/lib/module/skia/HeatMap/HeatMap.js.map +1 -1
  20. package/lib/module/skia/HeatMap/useHeatMap.js +132 -48
  21. package/lib/module/skia/HeatMap/useHeatMap.js.map +1 -1
  22. package/lib/module/skia/PieChart/PieChart.js +21 -17
  23. package/lib/module/skia/PieChart/PieChart.js.map +1 -1
  24. package/lib/module/skia/PieChart/usePieChart.js +241 -30
  25. package/lib/module/skia/PieChart/usePieChart.js.map +1 -1
  26. package/lib/module/skia/Popup.js +7 -5
  27. package/lib/module/skia/Popup.js.map +1 -1
  28. package/lib/module/skia/common.js +4 -41
  29. package/lib/module/skia/common.js.map +1 -1
  30. package/lib/typescript/src/index.d.ts +1 -0
  31. package/lib/typescript/src/index.d.ts.map +1 -1
  32. package/lib/typescript/src/skia/AreaChart/AreaChart.d.ts +15 -3
  33. package/lib/typescript/src/skia/AreaChart/AreaChart.d.ts.map +1 -1
  34. package/lib/typescript/src/skia/AreaChart/useAreaChart.d.ts +13 -14
  35. package/lib/typescript/src/skia/AreaChart/useAreaChart.d.ts.map +1 -1
  36. package/lib/typescript/src/skia/BarChart/BarChart.d.ts +16 -2
  37. package/lib/typescript/src/skia/BarChart/BarChart.d.ts.map +1 -1
  38. package/lib/typescript/src/skia/BarChart/useBarChart.d.ts +17 -5
  39. package/lib/typescript/src/skia/BarChart/useBarChart.d.ts.map +1 -1
  40. package/lib/typescript/src/skia/Common/HorizontalLabelView.d.ts +33 -0
  41. package/lib/typescript/src/skia/Common/HorizontalLabelView.d.ts.map +1 -0
  42. package/lib/typescript/src/skia/Common/VerticalLabelView.d.ts +24 -0
  43. package/lib/typescript/src/skia/Common/VerticalLabelView.d.ts.map +1 -0
  44. package/lib/typescript/src/skia/Common/useComponentLayout.d.ts +4 -0
  45. package/lib/typescript/src/skia/Common/useComponentLayout.d.ts.map +1 -0
  46. package/lib/typescript/src/skia/HeatMap/DateHeatMap.d.ts +1 -0
  47. package/lib/typescript/src/skia/HeatMap/DateHeatMap.d.ts.map +1 -0
  48. package/lib/typescript/src/skia/HeatMap/HeatMap.d.ts +28 -12
  49. package/lib/typescript/src/skia/HeatMap/HeatMap.d.ts.map +1 -1
  50. package/lib/typescript/src/skia/HeatMap/useHeatMap.d.ts +15 -4
  51. package/lib/typescript/src/skia/HeatMap/useHeatMap.d.ts.map +1 -1
  52. package/lib/typescript/src/skia/PieChart/PieChart.d.ts +5 -1
  53. package/lib/typescript/src/skia/PieChart/PieChart.d.ts.map +1 -1
  54. package/lib/typescript/src/skia/PieChart/usePieChart.d.ts +6 -1
  55. package/lib/typescript/src/skia/PieChart/usePieChart.d.ts.map +1 -1
  56. package/lib/typescript/src/skia/Popup.d.ts.map +1 -1
  57. package/lib/typescript/src/skia/common.d.ts +3 -10
  58. package/lib/typescript/src/skia/common.d.ts.map +1 -1
  59. package/package.json +11 -8
  60. package/src/index.tsx +6 -4
  61. package/src/skia/AreaChart/AreaChart.tsx +85 -62
  62. package/src/skia/AreaChart/useAreaChart.ts +25 -26
  63. package/src/skia/BarChart/BarChart.tsx +163 -95
  64. package/src/skia/BarChart/useBarChart.ts +55 -44
  65. package/src/skia/Common/HorizontalLabelView.tsx +153 -0
  66. package/src/skia/Common/VerticalLabelView.tsx +113 -0
  67. package/src/skia/Common/useComponentLayout.ts +14 -0
  68. package/src/skia/HeatMap/DateHeatMap.tsx +470 -0
  69. package/src/skia/HeatMap/HeatMap.tsx +168 -54
  70. package/src/skia/HeatMap/useHeatMap.ts +139 -65
  71. package/src/skia/PieChart/PieChart.tsx +16 -11
  72. package/src/skia/PieChart/usePieChart.ts +316 -66
  73. package/src/skia/Popup.tsx +38 -36
  74. package/src/skia/common.ts +8 -46
  75. package/lib/module/skia/Common/VerticalLabel.js +0 -73
  76. package/lib/module/skia/Common/VerticalLabel.js.map +0 -1
  77. package/lib/typescript/src/skia/Common/VerticalLabel.d.ts +0 -17
  78. package/lib/typescript/src/skia/Common/VerticalLabel.d.ts.map +0 -1
  79. package/src/skia/Common/VerticalLabel.tsx +0 -91
@@ -0,0 +1,472 @@
1
+ // import type { View } from "react-native-reanimated/lib/typescript/Animated";
2
+ // import type { DayData, HeatMapProps } from "./HeatMap";
3
+ // import { useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
4
+ // import { getPaddings } from "../common";
5
+
6
+ // function useHeatMap({
7
+ // rows
8
+ // style,
9
+ // minValue,
10
+ // maxValue,
11
+ // ref,
12
+ // popupStyle
13
+ // }: HeatMapProps) {
14
+
15
+ // const cellSize = style?.cellSize ?? 24;
16
+ // const cellGap = style?.cellGap ?? 4;
17
+ // const cellMaxColor = style?.cellMaxColor ?? '#50f555ff';
18
+ // const cellMinColor = style?.cellMinColor ?? '#ffffffff';
19
+
20
+ // const [verticalLabelWidth, setVerticalLabelWidth] = useState<number>(0);
21
+ // const [horizontalLabelHeight, setHorizontalLabelHeight] = useState<number>(0);
22
+ // const {
23
+ // paddingLeft,
24
+ // paddingRight,
25
+ // paddingTop,
26
+ // paddingBottom
27
+ // } = getPaddings(style);
28
+
29
+ // const numberOfDaysInWeek = 7;
30
+ // const numberOfRows = rows;
31
+ // const numberOfMsInDay = 1000 * 60 * 60 * 24;
32
+ // const xLabels = useMemo(() => {
33
+ // return (data ?? []).map(())
34
+ // }, [data])
35
+
36
+ // const [popupData, setPopupData] = useState<
37
+ // { x: number; y: number; day: DayData; } | undefined
38
+ // >(undefined);
39
+
40
+ // const [popupDimension, setPopupDimension] = useState({
41
+ // width: 0,
42
+ // height: 0,
43
+ // });
44
+
45
+ // const popupRef = useRef<View>(null);
46
+
47
+ // const formatDate = (date: Date) =>
48
+ // `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
49
+ // 2,
50
+ // '0'
51
+ // )}-${String(date.getDate()).padStart(2, '0')}`;
52
+
53
+ // const { daysInRange, computedMin, computedMax } = useMemo(() => {
54
+ // const start = new Date(startDate);
55
+ // const end = new Date(endDate);
56
+
57
+ // const output: DayData[] = [];
58
+ // let computedMax = Number.MIN_VALUE;
59
+ // let computedMin = Number.MAX_VALUE;
60
+
61
+ // const startDayOfWeek = start.getDay();
62
+
63
+ // for (let d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
64
+ // const dateStr = formatDate(d);
65
+ // const value = data?.[dateStr] ?? 0;
66
+
67
+ // const dayOfWeek = d.getDay();
68
+ // const daysFromStart = Math.floor(
69
+ // (d.getTime() - start.getTime()) / numberOfMsInDay
70
+ // );
71
+
72
+ // const week = Math.floor(
73
+ // (startDayOfWeek + daysFromStart) / numberOfDaysInWeek
74
+ // );
75
+
76
+ // computedMax = Math.max(computedMax, value);
77
+ // computedMin = Math.min(computedMin, value);
78
+
79
+ // output.push({
80
+ // date: dateStr,
81
+ // value,
82
+ // dayOfWeek,
83
+ // week,
84
+ // x: week * (cellSize + cellGap),
85
+ // y: dayOfWeek * (cellSize + cellGap),
86
+ // });
87
+ // }
88
+
89
+ // return {
90
+ // daysInRange: output,
91
+ // computedMin: minValue !== undefined ? minValue : computedMin,
92
+ // computedMax: maxValue !== undefined ? maxValue : computedMax,
93
+ // };
94
+ // }, [startDate, endDate, data, minValue, maxValue, cellSize, cellGap]);
95
+
96
+ // // --- COLOR LOGIC ---
97
+ // const getColor = (value: number) => {
98
+ // if (value <= 0) return cellMinColor;
99
+
100
+ // const intensity = Math.min(
101
+ // 1,
102
+ // Math.max(0, (value - computedMin) / (computedMax - computedMin || 1))
103
+ // );
104
+
105
+ // const bigint = parseInt(cellMaxColor.replace('#', ''), 16);
106
+ // const r = (bigint >> 16) & 255;
107
+ // const g = (bigint >> 8) & 255;
108
+ // const b = bigint & 255;
109
+
110
+ // const mix = (base: number) => Math.round(255 - (255 - base) * intensity);
111
+
112
+ // return `rgb(${mix(r)}, ${mix(g)}, ${mix(b)})`;
113
+ // };
114
+
115
+ // // Heatmap size
116
+ // const numWeeks = Math.ceil(daysInRange.length / 7 + 1);
117
+ // const totalWidth = numWeeks * (cellSize + cellGap) + verticalLabelWidth;
118
+ // const totalHeight = 7 * (cellSize + cellGap);
119
+
120
+ // // --- POPUP MEASUREMENT ---
121
+ // useLayoutEffect(() => {
122
+ // if (popupRef.current) {
123
+ // popupRef.current.measure((x, y, width, height) => {
124
+ // setPopupDimension({ width, height });
125
+ // });
126
+ // }
127
+ // }, [popupData]);
128
+
129
+ // // --- TOUCH HANDLER ---
130
+ // const touchHandler = (x: number, y: number) => {
131
+ // if (!popupStyle?.renderPopup || (x < 0 || y < 0 || x >= totalWidth || y >= totalHeight)) {
132
+ // setPopupData(undefined);
133
+ // return;
134
+ // }
135
+
136
+ // const col = Math.floor(x / (cellSize + cellGap));
137
+ // const row = Math.floor(y / (cellSize + cellGap));
138
+
139
+ // const start = new Date(startDate);
140
+ // const startDayOfWeek = start.getDay();
141
+
142
+ // const index = col * numberOfDaysInWeek + row;
143
+
144
+ // if (
145
+ // index >= startDayOfWeek &&
146
+ // index - startDayOfWeek < daysInRange.length
147
+ // ) {
148
+ // const day = daysInRange[index - startDayOfWeek];
149
+ // if (day) {
150
+ // setPopupData({
151
+ // x: col * (cellSize + cellGap),
152
+ // y: row * (cellSize + cellGap),
153
+ // day,
154
+ // });
155
+ // return;
156
+ // }
157
+ // }
158
+
159
+ // setPopupData(undefined);
160
+ // };
161
+ // const onTouchOutside = () => {
162
+ // setPopupData(undefined);
163
+ // };
164
+
165
+ // useImperativeHandle(ref, () => ({
166
+ // touchedOutside: () => {
167
+ // setPopupData(undefined);
168
+ // }
169
+ // }), [ref]);
170
+
171
+ // return {
172
+ // daysInRange,
173
+ // computedMin,
174
+ // computedMax,
175
+ // totalWidth,
176
+ // totalHeight,
177
+ // popupData,
178
+ // popupRef,
179
+ // popupDimension,
180
+ // touchHandler,
181
+ // getColor,
182
+ // cellSize,
183
+ // onTouchOutside,
184
+ // verticalLabelWidth,
185
+ // setVerticalLabelWidth,
186
+ // horizontalLabelHeight,
187
+ // setHorizontalLabelHeight,
188
+ // numberOfRows,
189
+ // paddingLeft,
190
+ // paddingRight,
191
+ // paddingTop,
192
+ // paddingBottom
193
+ // };
194
+ // }
195
+
196
+ // export default useHeatMap;
197
+
198
+ // import React, { type Ref } from 'react';
199
+ // import { View } from 'react-native';
200
+ // import { Canvas, Group, Rect, rect, type SkHostRect } from '@shopify/react-native-skia';
201
+ // import useHeatMap from './useHeatMap';
202
+ // import type { CommonStyle, HandleOutSideTouch } from '../common';
203
+ // import Popup, { type PopupStyle } from '../Popup';
204
+ // import VerticalLabelView, { type VerticalLabelStyle } from "../Common/VerticalLabelView";
205
+ // import HorizontalLabelView, { type HorizontalLabelStyleExtended } from "../Common/HorizontalLabelView";
206
+
207
+ // export type DayData = {
208
+ // date: string;
209
+ // value: number;
210
+ // dayOfWeek: number;
211
+ // week: number;
212
+ // x: number;
213
+ // y: number;
214
+ // };
215
+
216
+ // export interface HeatMapDataGroup {
217
+ // cols: number;
218
+ // data?: Record<string, number>;
219
+ // }
220
+
221
+ // export interface HeatMapStyle extends CommonStyle, VerticalLabelStyle {
222
+ // cellSize?: number;
223
+ // cellGap?: number;
224
+ // cellMaxColor?: string;
225
+ // cellMinColor?: string;
226
+ // horizontalLabelStyle?: HorizontalLabelStyleExtended;
227
+ // verticalLabelStyle?: VerticalLabelStyle;
228
+ // interGroupSpacing?: number;
229
+ // }
230
+
231
+ // export interface HeatMapProps {
232
+ // rows: number;
233
+ // data: HeatMapDataGroup[];
234
+ // // InterGroupSpacing is only applied when coalesceGroups is false
235
+ // coalesceGroups: boolean;
236
+ // style?: HeatMapStyle;
237
+ // minValue?: number;
238
+ // maxValue?: number;
239
+ // xLabelSkiaView?: (
240
+ // label: string,
241
+ // position: { x: number; y: number; }
242
+ // ) => React.JSX.Element | undefined;
243
+ // yLabelSkiaView?: (
244
+ // index: number,
245
+ // yPosition: number
246
+ // ) => React.JSX.Element | undefined;
247
+
248
+ // xLabelView?: (
249
+ // label: string
250
+ // ) => React.JSX.Element | undefined;
251
+ // yLabelView?: (
252
+ // index: number
253
+ // ) => React.JSX.Element | undefined;
254
+
255
+ // daySkiaView?: (
256
+ // rect: SkHostRect,
257
+ // day: DayData
258
+ // ) => React.JSX.Element | undefined;
259
+
260
+ // onSelectSkiaView?: (
261
+ // rect: SkHostRect,
262
+ // day: DayData
263
+ // ) => React.JSX.Element | undefined;
264
+ // onSelectView?: (
265
+ // rect: SkHostRect,
266
+ // day: DayData
267
+ // ) => React.JSX.Element | undefined;
268
+ // ref?: Ref<HandleOutSideTouch | undefined>;
269
+ // popupStyle?: PopupStyle<DayData>;
270
+ // }
271
+
272
+ // function HeatMap({ yLabelView, yLabelSkiaView, xLabelView, xLabelSkiaView, daySkiaView, onSelectView, onSelectSkiaView, ...props }: HeatMapProps) {
273
+ // const {
274
+ // daysInRange,
275
+ // totalWidth,
276
+ // totalHeight,
277
+ // popupData,
278
+ // popupRef,
279
+ // popupDimension,
280
+ // touchHandler,
281
+ // getColor,
282
+ // cellSize,
283
+ // onTouchOutside,
284
+ // horizontalLabelHeight,
285
+ // verticalLabelWidth,
286
+ // setHorizontalLabelHeight,
287
+ // setVerticalLabelWidth,
288
+ // numberOfRows,
289
+ // paddingTop,
290
+ // paddingBottom,
291
+ // paddingLeft,
292
+ // paddingRight
293
+ // } = useHeatMap(props);
294
+
295
+ // const [viewOffset, setViewOffset] = React.useState({ x: 0, y: 0 });
296
+ // const onSelectSkiaViewMemo = React.useMemo(() => {
297
+ // if (!popupData || !onSelectSkiaView) {
298
+ // return undefined;
299
+ // }
300
+ // return onSelectSkiaView?.(rect(popupData.x, popupData.y, cellSize, cellSize), popupData.day);
301
+ // }, [popupData, onSelectSkiaView, cellSize]);
302
+
303
+ // const onSelectViewMemo = React.useMemo(() => {
304
+ // if (!popupData || !onSelectView) {
305
+ // return undefined;
306
+ // }
307
+ // return onSelectView(rect(popupData.x, popupData.y, cellSize, cellSize), popupData.day);
308
+ // }, [popupData, onSelectView, cellSize]);
309
+
310
+ // return <View
311
+ // style={{ backgroundColor: props.style?.backgroundColor }}
312
+ // ref={(view) => {
313
+ // view?.measureInWindow((fx, fy) => {
314
+ // setViewOffset((prev) => {
315
+ // if (prev.x === fx && prev.y === fy) {
316
+ // return prev;
317
+ // }
318
+ // return { x: fx, y: fy };
319
+ // });
320
+ // });
321
+ // }}
322
+ // >
323
+ // <View style={{ flexDirection: "row" }}>
324
+ // {
325
+ // (yLabelView || yLabelSkiaView) && (<VerticalLabelView
326
+ // onLayout={(event) => {
327
+ // setVerticalLabelWidth(event.nativeEvent.layout.width);
328
+ // }}
329
+ // labelPercentages={Array.from({ length: numberOfRows }, (_, i) => (i + 1) / numberOfRows)}
330
+ // styles={{
331
+ // height: totalHeight,
332
+ // verticalLabelStyle: props.style?.verticalLabelStyle,
333
+ // }}
334
+ // labelSkiaView={(_percentage, yPosition, index) => yLabelSkiaView?.(index, yPosition)}
335
+ // >
336
+ // {(_percentage, index) => yLabelView?.(index)}
337
+ // </VerticalLabelView>)
338
+ // }
339
+ // <View style={{ width: totalWidth, height: totalHeight }}>
340
+ // {
341
+ // (xLabelView || xLabelSkiaView) &&
342
+ // <HorizontalLabelView
343
+ // labels={}
344
+ // positions={xLabelsData.map(labelData => labelData.xPosition)}
345
+ // style={{
346
+ // width: totalWidth,
347
+ // height: props.style?.x ?? 0
348
+ // }}
349
+ // onLayout={(event) => setHorizontalLabelHeight(event.nativeEvent.layout.height)}
350
+ // >
351
+ // {label => xLabelView(label)}
352
+ // </HorizontalLabelView>
353
+ // }
354
+ // <Canvas
355
+ // style={{ width: totalWidth, height: totalHeight }}
356
+ // onTouchStart={(event) =>
357
+ // touchHandler(event.nativeEvent.locationX, event.nativeEvent.locationY)
358
+ // }
359
+ // >
360
+ // <Group>
361
+ // {daysInRange.map((day) => {
362
+ // let skiaView = daySkiaView?.(rect(day.x, day.y, cellSize, cellSize), day);
363
+ // if (skiaView !== undefined) { return skiaView; }
364
+
365
+ // return (
366
+ // <Rect
367
+ // key={day.date}
368
+ // x={day.x}
369
+ // y={day.y}
370
+ // width={cellSize}
371
+ // height={cellSize}
372
+ // color={getColor(day.value)}
373
+ // />
374
+ // );
375
+ // })}
376
+ // {onSelectSkiaViewMemo}
377
+ // </Group>
378
+ // </Canvas>
379
+ // </View>
380
+ // </View>
381
+
382
+ // {
383
+ // popupData && (<>
384
+ // {onSelectViewMemo &&
385
+ // <View
386
+ // style={{
387
+ // position: "absolute",
388
+ // top: popupData.y + (props.style?.horizontalLabelStyle?.viewPosition === "bottom" ? 0 : horizontalLabelHeight),
389
+ // left: popupData.x + verticalLabelWidth
390
+ // }}
391
+ // >
392
+ // {onSelectViewMemo}
393
+ // </View>
394
+ // }
395
+ // <Popup
396
+ // popupData={{ x: popupData.x + verticalLabelWidth, y: popupData.y + (props.style?.horizontalLabelStyle?.viewPosition === "bottom" ? 0 : horizontalLabelHeight), data: popupData.day }}
397
+ // totalWidth={totalWidth}
398
+ // totalHeight={totalHeight}
399
+ // touchHandler={(x, y) => {
400
+ // touchHandler(x - verticalLabelWidth - paddingLeft, y - (props.style?.horizontalLabelStyle?.viewPosition === "bottom" ? 0 : horizontalLabelHeight));
401
+ // }}
402
+ // onTouchOutside={onTouchOutside}
403
+ // popupStyle={props.popupStyle}
404
+ // viewOffset={viewOffset}
405
+ // />
406
+ // </>
407
+ // )
408
+ // }
409
+ // </View >;
410
+ // }
411
+
412
+ // export default HeatMap;
413
+
414
+ // <HeatMap
415
+ // startDate="2020-10-22"
416
+ // endDate="2020-12-21"
417
+ // data={[{
418
+ // "2020-10-22": 50,
419
+ // "2020-10-23": 10,
420
+ // "2020-10-24": 15,
421
+ // "2020-10-25": 20,
422
+ // "2020-10-26": 25,
423
+ // "2020-10-27": 30,
424
+ // "2020-10-28": 35,
425
+ // "2020-10-29": 40,
426
+ // "2020-10-30": 45,
427
+ // "2020-10-31": 50,
428
+ // "2020-12-20": 50,
429
+ // "2020-12-21": 50,
430
+ // }]}
431
+ // style={{ verticalLabelStyle: { width: 70, strokeWidth: 0 } }}
432
+ // yLabelView={(index) => <View><Text>Hello - {index}</Text></View>}
433
+ // yLabelSkiaView={(index, yPosition) => <Rect x={0} y={yPosition} width={20} height={20} color={"red"} />}
434
+ // daySkiaView={(rect, day) => {
435
+ // if ((day.week + day.dayOfWeek) % 2 === 0) { return undefined; }
436
+ // return <Rect
437
+ // key={day.date}
438
+ // x={rect.x}
439
+ // y={rect.y}
440
+ // width={rect.width}
441
+ // height={rect.height}
442
+ // color={"green"}
443
+ // />;
444
+ // }}
445
+ // onSelectView={(rect, day) => {
446
+ // return <View style={{ backgroundColor: "yellow", opacity: 0.2, padding: 10 }}>
447
+ // <Text style={{ color: "green" }}>Selected {day.date}</Text>
448
+ // </View>;
449
+ // }}
450
+ // onSelectSkiaView={(rect, day) => {
451
+ // return <Rect
452
+ // key={day.date}
453
+ // x={rect.x}
454
+ // y={rect.y}
455
+ // width={rect.width}
456
+ // height={rect.height}
457
+ // color={"yellow"}
458
+ // />;
459
+ // }}
460
+ // popupStyle={{
461
+ // width: 10,
462
+ // height: 10,
463
+ // renderPopup: (day) => (
464
+ // <VStack style={{ padding: 8, backgroundColor: "black", borderRadius: 8 }}>
465
+ // <Text>{day.value}</Text>
466
+ // <Text>{day.date}</Text>
467
+ // </VStack>
468
+ // ),
469
+ // }}
470
+ // />
471
+ "use strict";
472
+ //# sourceMappingURL=DateHeatMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["skia/HeatMap/DateHeatMap.tsx"],"mappings":"AAAA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA","ignoreList":[]}
@@ -2,13 +2,24 @@
2
2
 
3
3
  import React from 'react';
4
4
  import { View } from 'react-native';
5
- import { Canvas, Group, Rect } from '@shopify/react-native-skia';
5
+ import { Canvas, Group, Rect, rect } from '@shopify/react-native-skia';
6
6
  import useHeatMap from "./useHeatMap.js";
7
7
  import Popup from "../Popup.js";
8
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
- function HeatMap(props) {
8
+ import VerticalLabelView from "../Common/VerticalLabelView.js";
9
+ import HorizontalLabelView from "../Common/HorizontalLabelView.js";
10
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
+ function HeatMap({
12
+ yLabelView,
13
+ yLabelSkiaView,
14
+ xLabelView,
15
+ xLabelSkiaView,
16
+ cellSkiaView,
17
+ onSelectView,
18
+ onSelectSkiaView,
19
+ ...props
20
+ }) {
10
21
  const {
11
- daysInRange,
22
+ cellData,
12
23
  totalWidth,
13
24
  totalHeight,
14
25
  popupData,
@@ -17,15 +28,41 @@ function HeatMap(props) {
17
28
  touchHandler,
18
29
  getColor,
19
30
  cellSize,
20
- onTouchOutside
31
+ onTouchOutside,
32
+ horizontalLabelHeight,
33
+ verticalLabelWidth,
34
+ setHorizontalLabelHeight,
35
+ setVerticalLabelWidth,
36
+ numberOfRows,
37
+ paddingTop,
38
+ paddingBottom,
39
+ paddingLeft,
40
+ paddingRight,
41
+ xLabelsRect
21
42
  } = useHeatMap(props);
22
43
  const [viewOffset, setViewOffset] = React.useState({
23
44
  x: 0,
24
45
  y: 0
25
46
  });
47
+ const onSelectSkiaViewMemo = React.useMemo(() => {
48
+ if (!popupData || !onSelectSkiaView) {
49
+ return undefined;
50
+ }
51
+ return onSelectSkiaView?.(rect(popupData.x, popupData.y, cellSize, cellSize), popupData.data);
52
+ }, [popupData, onSelectSkiaView, cellSize]);
53
+ const onSelectViewMemo = React.useMemo(() => {
54
+ if (!popupData || !onSelectView) {
55
+ return undefined;
56
+ }
57
+ return onSelectView(rect(popupData.x, popupData.y, cellSize, cellSize), popupData.data);
58
+ }, [popupData, onSelectView, cellSize]);
26
59
  return /*#__PURE__*/_jsxs(View, {
27
60
  style: {
28
- backgroundColor: props.style?.backgroundColor
61
+ backgroundColor: props.style?.backgroundColor,
62
+ paddingLeft,
63
+ paddingRight,
64
+ paddingTop,
65
+ paddingBottom
29
66
  },
30
67
  ref: view => {
31
68
  view?.measureInWindow((fx, fy) => {
@@ -40,35 +77,86 @@ function HeatMap(props) {
40
77
  });
41
78
  });
42
79
  },
43
- children: [/*#__PURE__*/_jsx(Canvas, {
80
+ children: [/*#__PURE__*/_jsxs(View, {
44
81
  style: {
45
- width: totalWidth,
46
- height: totalHeight
82
+ flexDirection: "row"
47
83
  },
48
- onTouchStart: event => touchHandler(event.nativeEvent.locationX, event.nativeEvent.locationY),
49
- children: /*#__PURE__*/_jsx(Group, {
50
- children: daysInRange.map(day => {
51
- return /*#__PURE__*/_jsx(Rect, {
52
- x: day.x,
53
- y: day.y,
54
- width: cellSize,
55
- height: cellSize,
56
- color: getColor(day.value)
57
- }, day.date);
58
- })
59
- })
60
- }), popupData && props.popupStyle && /*#__PURE__*/_jsx(Popup, {
61
- popupData: {
62
- x: popupData.x,
63
- y: popupData.y,
64
- data: popupData.day
65
- },
66
- totalWidth: totalWidth,
67
- totalHeight: totalHeight,
68
- touchHandler: touchHandler,
69
- onTouchOutside: onTouchOutside,
70
- popupStyle: props.popupStyle,
71
- viewOffset: viewOffset
84
+ children: [(yLabelView || yLabelSkiaView) && /*#__PURE__*/_jsx(VerticalLabelView, {
85
+ onLayout: event => {
86
+ setVerticalLabelWidth(event.nativeEvent.layout.width);
87
+ },
88
+ labelPercentages: Array.from({
89
+ length: numberOfRows
90
+ }, (_, i) => (i + 1) / numberOfRows),
91
+ styles: {
92
+ height: totalHeight,
93
+ top: horizontalLabelHeight,
94
+ verticalLabelStyle: props.style?.verticalLabelStyle
95
+ },
96
+ labelSkiaView: (_percentage, yPosition, index) => yLabelSkiaView?.(index, yPosition),
97
+ children: (_percentage, index) => yLabelView?.(index)
98
+ }), /*#__PURE__*/_jsxs(View, {
99
+ style: {
100
+ width: totalWidth,
101
+ height: totalHeight
102
+ },
103
+ children: [(xLabelView || xLabelSkiaView) && /*#__PURE__*/_jsx(HorizontalLabelView, {
104
+ labels: xLabelsRect.map(rect => rect),
105
+ positions: xLabelsRect.map(rect => rect.x),
106
+ style: {
107
+ width: totalWidth,
108
+ horizontalLabelStyle: props.style?.horizontalLabelStyle
109
+ },
110
+ onLayout: event => setHorizontalLabelHeight(event.nativeEvent.layout.height),
111
+ labelSkiaView: (yPostion, index, data) => xLabelSkiaView?.(index, data),
112
+ children: (index, rect) => xLabelView?.(index, rect.width)
113
+ }), /*#__PURE__*/_jsx(Canvas, {
114
+ style: {
115
+ width: totalWidth,
116
+ height: totalHeight
117
+ },
118
+ onTouchStart: event => touchHandler(event.nativeEvent.locationX, event.nativeEvent.locationY),
119
+ children: /*#__PURE__*/_jsxs(Group, {
120
+ children: [cellData.map(datum => {
121
+ let skiaView = cellSkiaView?.(rect(datum.x, datum.y, cellSize, cellSize), datum);
122
+ if (skiaView !== undefined) {
123
+ return skiaView;
124
+ }
125
+ return /*#__PURE__*/_jsx(Rect, {
126
+ x: datum.x,
127
+ y: datum.y,
128
+ width: cellSize,
129
+ height: cellSize,
130
+ color: getColor(datum.value)
131
+ }, datum.x + '-' + datum.y);
132
+ }), onSelectSkiaViewMemo]
133
+ })
134
+ })]
135
+ })]
136
+ }), popupData && /*#__PURE__*/_jsxs(_Fragment, {
137
+ children: [onSelectViewMemo && /*#__PURE__*/_jsx(View, {
138
+ style: {
139
+ position: "absolute",
140
+ top: popupData.y + (props.style?.horizontalLabelStyle?.viewPosition === "bottom" ? 0 : horizontalLabelHeight) + paddingTop,
141
+ left: popupData.x + verticalLabelWidth + paddingLeft
142
+ },
143
+ children: onSelectViewMemo
144
+ }), /*#__PURE__*/_jsx(Popup, {
145
+ popupData: {
146
+ x: popupData.x + verticalLabelWidth + paddingLeft,
147
+ y: popupData.y + (props.style?.horizontalLabelStyle?.viewPosition === "bottom" ? 0 : horizontalLabelHeight) + paddingTop,
148
+ data: popupData.data
149
+ },
150
+ totalWidth: totalWidth,
151
+ totalHeight: totalHeight,
152
+ touchHandler: (x, y) => {
153
+ console.log(x, y);
154
+ touchHandler(x - verticalLabelWidth - paddingLeft, y - (props.style?.horizontalLabelStyle?.viewPosition === "bottom" ? 0 : horizontalLabelHeight) - paddingTop);
155
+ },
156
+ onTouchOutside: onTouchOutside,
157
+ popupStyle: props.popupStyle,
158
+ viewOffset: viewOffset
159
+ })]
72
160
  })]
73
161
  });
74
162
  }