react-native-gifted-charts 1.0.21 → 1.2.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.
@@ -0,0 +1,569 @@
1
+ // import React from 'react';
2
+ // import {ColorValue, View} from 'react-native';
3
+ // import Canvas from 'react-native-canvas';
4
+
5
+ // type propTypes = {
6
+ // radius?: number;
7
+ // isThreeD?: Boolean;
8
+ // donut?: Boolean;
9
+ // innerRadius?: number;
10
+ // shadow?: Boolean;
11
+ // innerCircleColor?: ColorValue;
12
+ // innerCircleBorderWidth?: number;
13
+ // innerCircleBorderColor?: ColorValue;
14
+ // shiftInnerCenterX?: number;
15
+ // shiftInnerCenterY?: number;
16
+ // shadowColor?: string;
17
+ // shadowWidth?: number;
18
+ // strokeWidth?: number;
19
+ // strokeColor?: string;
20
+ // backgroundColor?: string;
21
+ // data: Array<itemType>;
22
+ // semiCircle?: Boolean;
23
+
24
+ // showText?: Boolean;
25
+ // textColor?: string;
26
+ // textSize?: number;
27
+ // fontStyle?: string;
28
+ // fontWeight?: string;
29
+ // font?: string;
30
+ // showTextBackground?: Boolean;
31
+ // textBackgroundColor?: string;
32
+ // textBackgroundRadius?: number;
33
+ // showValuesAsLabels?: Boolean;
34
+
35
+ // centerLabelComponent?: Function;
36
+ // tilt?: number;
37
+ // initialAngle?: number;
38
+ // };
39
+ // type itemType = {
40
+ // value: number;
41
+ // shiftX?: number;
42
+ // shiftY?: number;
43
+ // color?: string;
44
+ // text?: string;
45
+ // textColor?: string;
46
+ // textSize?: number;
47
+ // fontStyle?: string;
48
+ // fontWeight?: string;
49
+ // font?: string;
50
+ // textBackgroundColor?: string;
51
+ // textBackgroundRadius?: number;
52
+ // shiftTextX?: number;
53
+ // shiftTextY?: number;
54
+ // };
55
+ // export const PieChart = (props: propTypes) => {
56
+ // const {data, isThreeD} = props;
57
+ // const radius = props.radius || 120;
58
+ // const shadowWidth = props.shadowWidth || (4 * radius) / 3;
59
+ // const backgroundColor = props.backgroundColor || 'white';
60
+ // const shadowColor = props.shadowColor || 'lightgray';
61
+ // let total = 0;
62
+ // let pi = Math.PI;
63
+ // const shadow = props.shadow || false;
64
+ // const donut = props.donut || false;
65
+ // const innerRadius = props.innerRadius || radius / 2;
66
+ // const innerCircleColor = props.innerCircleColor || 'white';
67
+ // const innerCircleBorderWidth =
68
+ // props.innerCircleBorderWidth || (props.innerCircleBorderColor ? 5 : 0);
69
+ // const innerCircleBorderColor = props.innerCircleBorderColor || 'gray';
70
+ // const shiftInnerCenterX = props.shiftInnerCenterX || 0;
71
+ // const shiftInnerCenterY = props.shiftInnerCenterY || 0;
72
+ // const strokeWidth = props.strokeWidth || 0;
73
+ // const strokeColor =
74
+ // props.strokeColor || (strokeWidth ? 'gray' : 'transparent');
75
+
76
+ // const showText = props.showText || false;
77
+ // const textColor = props.textColor || '';
78
+ // const textSize = props.textSize ? Math.min(props.textSize, radius / 5) : 16;
79
+ // const tilt = props.tilt ? Math.min(props.tilt, 1) : props.isThreeD ? 0.5 : 1;
80
+
81
+ // const showTextBackground = props.showTextBackground || false;
82
+ // const showValuesAsLabels = props.showValuesAsLabels || false;
83
+ // const semiCircle = props.semiCircle || false;
84
+ // const fontStyleList = ['normal', 'italic', 'oblique'];
85
+ // const fontWeightList = [
86
+ // 'normal',
87
+ // 'bold',
88
+ // 'bolder',
89
+ // 'lighter',
90
+ // '100',
91
+ // '200',
92
+ // '300',
93
+ // '400',
94
+ // '500',
95
+ // '600',
96
+ // '700',
97
+ // '800',
98
+ // '900',
99
+ // ];
100
+ // const initialAngle = props.initialAngle || 0;
101
+
102
+ // let isDataShifted = false;
103
+ // data.forEach((item: any) => {
104
+ // total += item.value;
105
+ // if (item.shiftX || item.shiftY) {
106
+ // isDataShifted = true;
107
+ // }
108
+ // });
109
+
110
+ // if (semiCircle) {
111
+ // pi = Math.PI / 2;
112
+ // }
113
+
114
+ // const canvasHeight = isThreeD ? radius * 2.5 + 60 : radius * 2 + 60;
115
+ // const canvasWidth = radius * 2 + 60;
116
+
117
+ // const handleCanvas = async (canvas: Canvas) => {
118
+ // if (!canvas) {
119
+ // return null;
120
+ // }
121
+
122
+ // if (isThreeD) {
123
+ // canvas.height = canvasHeight;
124
+ // } else {
125
+ // canvas.height = canvasHeight;
126
+ // }
127
+ // canvas.width = canvasWidth;
128
+ // const ctx = canvas.getContext('2d');
129
+ // ctx.lineWidth = strokeWidth;
130
+ // ctx.strokeStyle = strokeColor;
131
+ // const initialValue = 30;
132
+
133
+ // /****************** SHADOW ***************/
134
+ // if (!semiCircle && isThreeD && shadow) {
135
+ // ctx.beginPath();
136
+ // ctx.moveTo(initialValue, radius + initialValue);
137
+ // ctx.lineTo(initialValue, shadowWidth + initialValue);
138
+ // ctx.arc(
139
+ // radius + initialValue,
140
+ // shadowWidth + initialValue,
141
+ // radius,
142
+ // pi,
143
+ // 0,
144
+ // true,
145
+ // );
146
+ // ctx.lineTo(2 * radius + initialValue, radius + initialValue);
147
+ // ctx.fillStyle = shadowColor;
148
+ // ctx.fill();
149
+ // }
150
+ // /******************************************************/
151
+
152
+ // let i = 0,
153
+ // angleSum = initialAngle;
154
+ // let colors = [
155
+ // 'cyan',
156
+ // 'green',
157
+ // 'orange',
158
+ // 'purple',
159
+ // 'yellow',
160
+ // 'red',
161
+ // 'blue',
162
+ // 'pink',
163
+ // ];
164
+
165
+ // i = 0;
166
+ // let semiSum, yy, xx;
167
+ // data.forEach((dataItem, index) => {
168
+ // if (!dataItem.value) {
169
+ // return;
170
+ // }
171
+ // const shiftX = dataItem.shiftX || 0;
172
+ // const shiftY = dataItem.shiftY || 0;
173
+
174
+ // const shiftTextX = dataItem.shiftTextX || 0;
175
+ // const shiftTextY = dataItem.shiftTextY || 0;
176
+
177
+ // /**************** This section is to prevent the shadow from ***************/
178
+ // /**************** being visible inside the chart content if ***************/
179
+ // /**************** the color of sections is transparent ***************/
180
+
181
+ // if (isThreeD && shadow) {
182
+ // ctx.beginPath();
183
+
184
+ // ctx.moveTo(
185
+ // radius + initialValue + shiftX,
186
+ // radius + initialValue + shiftY,
187
+ // );
188
+ // ctx.arc(
189
+ // radius + initialValue + shiftX,
190
+ // radius + initialValue + shiftY,
191
+ // radius,
192
+ // angleSum,
193
+ // angleSum + (2 * pi * dataItem.value) / total,
194
+ // );
195
+ // ctx.stroke();
196
+ // ctx.lineTo(
197
+ // radius + initialValue + shiftX,
198
+ // radius + initialValue + shiftY,
199
+ // );
200
+
201
+ // ctx.fillStyle = backgroundColor;
202
+ // ctx.fill();
203
+
204
+ // // Stroke at the end again
205
+
206
+ // ctx.moveTo(
207
+ // radius + initialValue + shiftX,
208
+ // radius + initialValue + shiftY,
209
+ // );
210
+ // ctx.lineTo(
211
+ // radius + initialValue + shiftX,
212
+ // radius + initialValue + shiftY,
213
+ // );
214
+ // ctx.stroke();
215
+ // }
216
+
217
+ // /*************************************************************************************/
218
+ // /*************************************************************************************/
219
+
220
+ // ctx.beginPath();
221
+
222
+ // ctx.moveTo(
223
+ // radius + initialValue + shiftX,
224
+ // radius + initialValue + shiftY,
225
+ // );
226
+ // ctx.arc(
227
+ // radius + initialValue + shiftX,
228
+ // radius + initialValue + shiftY,
229
+ // radius,
230
+ // angleSum,
231
+ // angleSum + (2 * pi * dataItem.value) / total,
232
+ // );
233
+ // ctx.stroke();
234
+ // ctx.lineTo(
235
+ // radius + initialValue + shiftX,
236
+ // radius + initialValue + shiftY,
237
+ // );
238
+
239
+ // ctx.fillStyle = dataItem.color || colors[i++ % 9];
240
+ // ctx.fill();
241
+
242
+ // // Stroke at the end again
243
+
244
+ // ctx.moveTo(
245
+ // radius + initialValue + shiftX,
246
+ // radius + initialValue + shiftY,
247
+ // );
248
+ // ctx.lineTo(
249
+ // radius + initialValue + shiftX,
250
+ // radius + initialValue + shiftY,
251
+ // );
252
+ // ctx.stroke();
253
+
254
+ // /************************* Displaying Text Labels **********************/
255
+
256
+ // if (index !== 0 && showText) {
257
+ // let fontSize, font;
258
+
259
+ // /*************** Font size **************/
260
+ // if (dataItem.textSize) {
261
+ // fontSize = Math.min(dataItem.textSize, radius / 5);
262
+ // } else if (props.textSize) {
263
+ // fontSize = Math.min(props.textSize, radius / 5);
264
+ // } else {
265
+ // fontSize = 16;
266
+ // }
267
+
268
+ // /*************** Font family **************/
269
+ // if (dataItem.font) {
270
+ // font = dataItem.font;
271
+ // } else if (props.font) {
272
+ // font = props.font;
273
+ // } else {
274
+ // font = 'Comic Sans MS';
275
+ // }
276
+
277
+ // let fontText = fontSize + 'px ' + font;
278
+
279
+ // /*************** Font weight **************/
280
+ // if (
281
+ // dataItem.fontWeight &&
282
+ // fontWeightList.includes(dataItem.fontWeight)
283
+ // ) {
284
+ // fontText = dataItem.fontWeight + ' ' + fontText;
285
+ // } else if (
286
+ // props.fontWeight &&
287
+ // fontWeightList.includes(props.fontWeight)
288
+ // ) {
289
+ // fontText = props.fontWeight + ' ' + fontText;
290
+ // }
291
+
292
+ // /*************** Font style **************/
293
+ // if (dataItem.fontStyle && fontStyleList.includes(dataItem.fontStyle)) {
294
+ // fontText = dataItem.fontStyle + ' ' + fontText;
295
+ // } else if (props.fontStyle && fontStyleList.includes(props.fontStyle)) {
296
+ // fontText = props.fontStyle + ' ' + fontText;
297
+ // }
298
+
299
+ // ctx.font = fontText;
300
+ // semiSum = angleSum + (pi * dataItem.value) / total;
301
+ // yy = Math.sin(semiSum) * radius + (radius + initialValue + shiftX);
302
+ // xx = Math.cos(semiSum) * radius + (radius + initialValue + shiftY);
303
+
304
+ // // console.log('semisum==>>', semiSum);
305
+ // // console.log('sin(semisum)==>>', Math.sin(semiSum));
306
+ // if (semiCircle) {
307
+ // if (semiSum > 0 && semiSum <= pi / 2) {
308
+ // yy -= 6;
309
+ // } else if (semiSum > pi / 2 && semiSum <= pi) {
310
+ // yy -= 10;
311
+ // } else if (semiSum > pi && semiSum <= 1.5 * pi) {
312
+ // xx += 10;
313
+ // yy -= 20;
314
+ // } else {
315
+ // xx += 25;
316
+ // yy -= 8;
317
+ // }
318
+ // } else {
319
+ // if (semiSum > 0 && semiSum <= pi / 2) {
320
+ // xx -= 20;
321
+ // } else if (semiSum > pi && semiSum <= 1.5 * pi) {
322
+ // xx += 10;
323
+ // yy += 16;
324
+ // } else if (semiSum > 1.5 * pi) {
325
+ // xx -= 16;
326
+ // yy += 16;
327
+ // }
328
+ // }
329
+
330
+ // if (showTextBackground && (dataItem.text || showValuesAsLabels)) {
331
+ // let textBackgroundX =
332
+ // xx -
333
+ // (semiCircle ? 18 : 0) +
334
+ // (props.textBackgroundRadius ||
335
+ // dataItem.textBackgroundRadius ||
336
+ // textSize) /
337
+ // 2;
338
+ // let textBackgroundY =
339
+ // yy +
340
+ // (semiCircle ? 8 : 0) -
341
+ // (props.textBackgroundRadius ||
342
+ // dataItem.textBackgroundRadius ||
343
+ // textSize) /
344
+ // 3;
345
+ // ctx.beginPath();
346
+ // ctx.arc(
347
+ // textBackgroundX,
348
+ // textBackgroundY,
349
+ // props.textBackgroundRadius ||
350
+ // dataItem.textBackgroundRadius ||
351
+ // textSize,
352
+ // 0,
353
+ // 2 * Math.PI,
354
+ // false,
355
+ // );
356
+ // ctx.fillStyle =
357
+ // props.textBackgroundColor ||
358
+ // dataItem.textBackgroundColor ||
359
+ // 'white';
360
+ // ctx.fill();
361
+ // }
362
+
363
+ // xx += shiftTextX;
364
+ // yy += shiftTextY;
365
+
366
+ // ctx.fillStyle = dataItem.textColor || textColor || colors[i++ % 9];
367
+ // let labelText = dataItem.text || '';
368
+ // if (showValuesAsLabels && !labelText) {
369
+ // labelText = dataItem.value.toString();
370
+ // }
371
+ // if (semiCircle) {
372
+ // ctx.translate(xx, yy);
373
+ // ctx.rotate(Math.PI);
374
+ // ctx.fillText(labelText, 4, 4);
375
+ // ctx.rotate(Math.PI);
376
+ // ctx.translate(-xx, -yy);
377
+ // } else {
378
+ // ctx.fillText(labelText, xx, yy);
379
+ // }
380
+ // }
381
+ // /*******************************************************************************************************/
382
+
383
+ // angleSum += (2 * pi * dataItem.value) / total;
384
+ // });
385
+
386
+ // /**********************************************************************************************************/
387
+ // /******************* Displaying Text Labels for the 1st pie, to avoid overlapping *************/
388
+ // /**********************************************************************************************************/
389
+ // if (showText) {
390
+ // let dataItem = data[0];
391
+ // angleSum = initialAngle;
392
+ // const shiftX = dataItem.shiftX || 0;
393
+ // const shiftY = dataItem.shiftY || 0;
394
+
395
+ // const shiftTextX = dataItem.shiftTextX || 0;
396
+ // const shiftTextY = dataItem.shiftTextY || 0;
397
+ // let fontSize, font;
398
+
399
+ // /*************** Font size **************/
400
+ // if (dataItem.textSize) {
401
+ // fontSize = Math.min(dataItem.textSize, radius / 5);
402
+ // } else if (props.textSize) {
403
+ // fontSize = Math.min(props.textSize, radius / 5);
404
+ // } else {
405
+ // fontSize = 16;
406
+ // }
407
+
408
+ // /*************** Font family **************/
409
+ // if (dataItem.font) {
410
+ // font = dataItem.font;
411
+ // } else if (props.font) {
412
+ // font = props.font;
413
+ // } else {
414
+ // font = 'Comic Sans MS';
415
+ // }
416
+
417
+ // let fontText = fontSize + 'px ' + font;
418
+
419
+ // /*************** Font weight **************/
420
+ // if (dataItem.fontWeight && fontWeightList.includes(dataItem.fontWeight)) {
421
+ // fontText = dataItem.fontWeight + ' ' + fontText;
422
+ // } else if (
423
+ // props.fontWeight &&
424
+ // fontWeightList.includes(props.fontWeight)
425
+ // ) {
426
+ // fontText = props.fontWeight + ' ' + fontText;
427
+ // }
428
+
429
+ // /*************** Font style **************/
430
+ // if (dataItem.fontStyle && fontStyleList.includes(dataItem.fontStyle)) {
431
+ // fontText = dataItem.fontStyle + ' ' + fontText;
432
+ // } else if (props.fontStyle && fontStyleList.includes(props.fontStyle)) {
433
+ // fontText = props.fontStyle + ' ' + fontText;
434
+ // }
435
+
436
+ // ctx.font = fontText;
437
+ // semiSum = angleSum + (pi * dataItem.value) / total;
438
+ // yy = Math.sin(semiSum) * radius + (radius + initialValue + shiftX);
439
+ // xx = Math.cos(semiSum) * radius + (radius + initialValue + shiftY);
440
+
441
+ // // console.log('semisum==>>', semiSum);
442
+ // // console.log('sin(semisum)==>>', Math.sin(semiSum));
443
+ // if (semiCircle) {
444
+ // if (semiSum > 0 && semiSum <= pi / 2) {
445
+ // yy -= 6;
446
+ // } else if (semiSum > pi / 2 && semiSum <= pi) {
447
+ // yy -= 10;
448
+ // } else if (semiSum > pi && semiSum <= 1.5 * pi) {
449
+ // xx += 10;
450
+ // yy -= 20;
451
+ // } else {
452
+ // xx += 25;
453
+ // yy -= 8;
454
+ // }
455
+ // } else {
456
+ // if (semiSum > 0 && semiSum <= pi / 2) {
457
+ // xx -= 20;
458
+ // } else if (semiSum > pi && semiSum <= 1.5 * pi) {
459
+ // xx += 10;
460
+ // yy += 16;
461
+ // } else if (semiSum > 1.5 * pi) {
462
+ // xx -= 16;
463
+ // yy += 16;
464
+ // }
465
+ // }
466
+
467
+ // if (showTextBackground && (dataItem.text || showValuesAsLabels)) {
468
+ // let textBackgroundX =
469
+ // xx -
470
+ // (semiCircle ? 18 : 0) +
471
+ // (props.textBackgroundRadius ||
472
+ // dataItem.textBackgroundRadius ||
473
+ // textSize) /
474
+ // 2;
475
+ // let textBackgroundY =
476
+ // yy +
477
+ // (semiCircle ? 8 : 0) -
478
+ // (props.textBackgroundRadius ||
479
+ // dataItem.textBackgroundRadius ||
480
+ // textSize) /
481
+ // 3;
482
+ // ctx.beginPath();
483
+ // ctx.arc(
484
+ // textBackgroundX,
485
+ // textBackgroundY,
486
+ // props.textBackgroundRadius ||
487
+ // dataItem.textBackgroundRadius ||
488
+ // textSize,
489
+ // 0,
490
+ // 2 * Math.PI,
491
+ // false,
492
+ // );
493
+ // ctx.fillStyle =
494
+ // props.textBackgroundColor || dataItem.textBackgroundColor || 'white';
495
+ // ctx.fill();
496
+ // }
497
+
498
+ // xx += shiftTextX;
499
+ // yy += shiftTextY;
500
+
501
+ // ctx.fillStyle = dataItem.textColor || textColor || colors[i++ % 9];
502
+ // let labelText = dataItem.text || '';
503
+ // if (showValuesAsLabels && !labelText) {
504
+ // labelText = dataItem.value.toString();
505
+ // }
506
+ // if (semiCircle) {
507
+ // ctx.translate(xx, yy);
508
+ // ctx.rotate(Math.PI);
509
+ // ctx.fillText(labelText, 4, 4);
510
+ // ctx.rotate(Math.PI);
511
+ // ctx.translate(-xx, -yy);
512
+ // } else {
513
+ // ctx.fillText(labelText, xx, yy);
514
+ // }
515
+ // }
516
+
517
+ // /*******************************************************************************************************/
518
+ // };
519
+
520
+ // return total === 0 ? null : (
521
+ // <View style={{transform: [{scaleY: tilt}]}}>
522
+ // <Canvas
523
+ // style={semiCircle && {transform: [{rotate: '180deg'}]}}
524
+ // ref={handleCanvas}
525
+ // />
526
+ // {(props.centerLabelComponent || (donut && !isDataShifted)) && (
527
+ // <View
528
+ // style={[
529
+ // {
530
+ // height: innerRadius * 2,
531
+ // width: innerRadius * 2,
532
+ // borderRadius: innerRadius,
533
+ // position: 'absolute',
534
+ // alignSelf: 'center',
535
+ // left: canvasWidth / 2 - innerRadius + shiftInnerCenterX,
536
+ // top:
537
+ // canvasHeight / 2 -
538
+ // innerRadius * (isThreeD ? 1.5 : 1) +
539
+ // shiftInnerCenterY +
540
+ // (isThreeD && semiCircle ? radius / 2 : 0),
541
+ // borderWidth: innerCircleBorderWidth,
542
+ // borderColor: innerCircleBorderColor,
543
+ // backgroundColor: innerCircleColor,
544
+ // justifyContent: 'center',
545
+ // alignItems: 'center',
546
+ // },
547
+ // isThreeD && {
548
+ // borderTopWidth: innerCircleBorderWidth * 5,
549
+ // borderLeftWidth: shiftInnerCenterX
550
+ // ? innerCircleBorderWidth * 2
551
+ // : innerCircleBorderWidth,
552
+ // },
553
+ // semiCircle && {
554
+ // borderTopWidth: isThreeD
555
+ // ? innerCircleBorderWidth * 5
556
+ // : innerCircleBorderWidth,
557
+ // borderLeftWidth: 0.5,
558
+ // borderLeftColor: innerCircleColor,
559
+ // borderBottomWidth: 0,
560
+ // borderRightWidth: 0.5,
561
+ // borderRightColor: innerCircleColor,
562
+ // },
563
+ // ]}>
564
+ // {props.centerLabelComponent ? props.centerLabelComponent() : null}
565
+ // </View>
566
+ // )}
567
+ // </View>
568
+ // );
569
+ // };
package/src/todos.md CHANGED
@@ -12,6 +12,8 @@
12
12
  5. Prepare a doc for Bar chart combined with Line chart having a separate data for the Line chart
13
13
  6. Prepare a doc for Line chart with smoothly scrolling data pointer and strip (along with pointerShiftX)
14
14
  7. Prepare a doc for Bar chart with barMarginBottom
15
+ 8. Prepare a doc for reference lines
16
+ 9. Prepare a doc for labelsPosition in Pie and Donut charts
15
17
 
16
18
  ## Architecture Enhancement
17
19