react-native-gifted-charts 1.2.6 → 1.2.9
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/package.json +1 -1
- package/src/BarChart/RenderBars.tsx +8 -1
- package/src/BarChart/index.tsx +2 -0
- package/src/LineChart/index.tsx +133 -48
- package/src/PieChart/index.tsx +1 -1
- package/src/todos.md +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
4
4
|
"description": "The most complete library for Bar, Line, Area, Pie, Donut and Stacked Bar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"files": [
|
|
@@ -63,6 +63,7 @@ type Props = {
|
|
|
63
63
|
barBackgroundPattern?: Function;
|
|
64
64
|
patternId?: String;
|
|
65
65
|
barMarginBottom?: number;
|
|
66
|
+
onPress?: Function;
|
|
66
67
|
};
|
|
67
68
|
type itemType = {
|
|
68
69
|
value?: number;
|
|
@@ -319,7 +320,13 @@ const RenderBars = (props: Props) => {
|
|
|
319
320
|
<TouchableOpacity
|
|
320
321
|
disabled={item.disablePress || props.disablePress}
|
|
321
322
|
activeOpacity={props.activeOpacity || 0.2}
|
|
322
|
-
onPress={
|
|
323
|
+
onPress={() => {
|
|
324
|
+
item.onPress
|
|
325
|
+
? item.onPress()
|
|
326
|
+
: props.onPress
|
|
327
|
+
? props.onPress(item, index)
|
|
328
|
+
: null;
|
|
329
|
+
}}
|
|
323
330
|
style={[
|
|
324
331
|
{
|
|
325
332
|
// overflow: 'visible',
|
package/src/BarChart/index.tsx
CHANGED
|
@@ -130,6 +130,7 @@ type PropTypes = {
|
|
|
130
130
|
barBackgroundPattern?: Function;
|
|
131
131
|
patternId?: String;
|
|
132
132
|
barMarginBottom?: number;
|
|
133
|
+
onPress?: Function;
|
|
133
134
|
};
|
|
134
135
|
type lineConfigType = {
|
|
135
136
|
initialSpacing?: number;
|
|
@@ -1458,6 +1459,7 @@ export const BarChart = (props: PropTypes) => {
|
|
|
1458
1459
|
labelTextStyle={
|
|
1459
1460
|
item.labelTextStyle || props.xAxisLabelTextStyle
|
|
1460
1461
|
}
|
|
1462
|
+
onPress={props.onPress}
|
|
1461
1463
|
/>
|
|
1462
1464
|
))}
|
|
1463
1465
|
</Fragment>
|
package/src/LineChart/index.tsx
CHANGED
|
@@ -22,6 +22,7 @@ import Svg, {
|
|
|
22
22
|
Circle,
|
|
23
23
|
Rect,
|
|
24
24
|
Text as CanvasText,
|
|
25
|
+
Line,
|
|
25
26
|
} from 'react-native-svg';
|
|
26
27
|
import {svgPath, bezierCommand} from '../utils';
|
|
27
28
|
import Rule from '../Components/lineSvg';
|
|
@@ -347,6 +348,7 @@ type Pointer = {
|
|
|
347
348
|
hidePointer3?: boolean;
|
|
348
349
|
hidePointer4?: boolean;
|
|
349
350
|
hidePointer5?: boolean;
|
|
351
|
+
strokeDashArray?: Array<number>;
|
|
350
352
|
};
|
|
351
353
|
|
|
352
354
|
export const LineChart = (props: propTypes) => {
|
|
@@ -819,7 +821,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
819
821
|
ppp4 = '',
|
|
820
822
|
ppp5 = '';
|
|
821
823
|
|
|
822
|
-
if (!animateOnDataChange) {
|
|
824
|
+
if (data.length && !animateOnDataChange) {
|
|
823
825
|
ppp =
|
|
824
826
|
'L' +
|
|
825
827
|
(initialSpacing - dataPointsWidth1 / 2) +
|
|
@@ -1007,35 +1009,37 @@ export const LineChart = (props: propTypes) => {
|
|
|
1007
1009
|
|
|
1008
1010
|
// console.log('xx---->>>', xx)
|
|
1009
1011
|
if (areaChart) {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1012
|
+
if (data.length) {
|
|
1013
|
+
xx =
|
|
1014
|
+
'M ' +
|
|
1015
|
+
(initialSpacing - dataPointsWidth1 / 2) +
|
|
1016
|
+
',' +
|
|
1017
|
+
(containerHeight + 10 - xAxisThickness) +
|
|
1018
|
+
' ' +
|
|
1019
|
+
'L ' +
|
|
1020
|
+
(initialSpacing - dataPointsWidth1 / 2) +
|
|
1021
|
+
',' +
|
|
1022
|
+
(containerHeight +
|
|
1023
|
+
10 -
|
|
1024
|
+
(data[0].value * containerHeight) / maxValue) +
|
|
1025
|
+
' ' +
|
|
1026
|
+
xx +
|
|
1027
|
+
' ' +
|
|
1028
|
+
'L ' +
|
|
1029
|
+
(initialSpacing -
|
|
1030
|
+
dataPointsWidth1 / 2 +
|
|
1031
|
+
spacing * (data.length - 1)) +
|
|
1032
|
+
',' +
|
|
1033
|
+
(containerHeight + 10 - xAxisThickness) +
|
|
1034
|
+
' ' +
|
|
1035
|
+
'L ' +
|
|
1036
|
+
(initialSpacing - dataPointsWidth1 / 2) +
|
|
1037
|
+
',' +
|
|
1038
|
+
(containerHeight + 10 - xAxisThickness) +
|
|
1039
|
+
' ';
|
|
1040
|
+
setFillPoints(xx);
|
|
1041
|
+
// console.log('xx later ---->>>', xx)
|
|
1042
|
+
}
|
|
1039
1043
|
|
|
1040
1044
|
if (data2.length) {
|
|
1041
1045
|
xx2 =
|
|
@@ -1240,32 +1244,44 @@ export const LineChart = (props: propTypes) => {
|
|
|
1240
1244
|
const startFillColor1 =
|
|
1241
1245
|
props.startFillColor1 || props.startFillColor || 'gray';
|
|
1242
1246
|
const endFillColor1 = props.endFillColor1 || props.endFillColor || 'white';
|
|
1243
|
-
const
|
|
1244
|
-
const
|
|
1247
|
+
const startOpacity = props.startOpacity === 0 ? 0 : props.startOpacity || 1;
|
|
1248
|
+
const endOpacity = props.endOpacity === 0 ? 0 : props.endOpacity || 1;
|
|
1249
|
+
const startOpacity1 =
|
|
1250
|
+
props.startOpacity1 === 0 ? 0 : props.startOpacity1 || startOpacity;
|
|
1251
|
+
const endOpacity1 =
|
|
1252
|
+
props.endOpacity1 === 0 ? 0 : props.endOpacity1 || endOpacity;
|
|
1245
1253
|
|
|
1246
1254
|
const startFillColor2 =
|
|
1247
1255
|
props.startFillColor2 || props.startFillColor || 'gray';
|
|
1248
1256
|
const endFillColor2 = props.endFillColor2 || props.endFillColor || 'white';
|
|
1249
|
-
const startOpacity2 =
|
|
1250
|
-
|
|
1257
|
+
const startOpacity2 =
|
|
1258
|
+
props.startOpacity2 === 0 ? 0 : props.startOpacity2 || startOpacity;
|
|
1259
|
+
const endOpacity2 =
|
|
1260
|
+
props.endOpacity2 === 0 ? 0 : props.endOpacity2 || endOpacity;
|
|
1251
1261
|
|
|
1252
1262
|
const startFillColor3 =
|
|
1253
1263
|
props.startFillColor3 || props.startFillColor || 'gray';
|
|
1254
1264
|
const endFillColor3 = props.endFillColor3 || props.endFillColor || 'white';
|
|
1255
|
-
const startOpacity3 =
|
|
1256
|
-
|
|
1265
|
+
const startOpacity3 =
|
|
1266
|
+
props.startOpacity3 === 0 ? 0 : props.startOpacity3 || startOpacity;
|
|
1267
|
+
const endOpacity3 =
|
|
1268
|
+
props.endOpacity3 === 0 ? 0 : props.endOpacity3 || endOpacity;
|
|
1257
1269
|
|
|
1258
1270
|
const startFillColor4 =
|
|
1259
1271
|
props.startFillColor4 || props.startFillColor || 'gray';
|
|
1260
1272
|
const endFillColor4 = props.endFillColor4 || props.endFillColor || 'white';
|
|
1261
|
-
const startOpacity4 =
|
|
1262
|
-
|
|
1273
|
+
const startOpacity4 =
|
|
1274
|
+
props.startOpacity4 === 0 ? 0 : props.startOpacity4 || startOpacity;
|
|
1275
|
+
const endOpacity4 =
|
|
1276
|
+
props.endOpacity4 === 0 ? 0 : props.endOpacity4 || endOpacity;
|
|
1263
1277
|
|
|
1264
1278
|
const startFillColor5 =
|
|
1265
1279
|
props.startFillColor5 || props.startFillColor || 'gray';
|
|
1266
1280
|
const endFillColor5 = props.endFillColor5 || props.endFillColor || 'white';
|
|
1267
|
-
const startOpacity5 =
|
|
1268
|
-
|
|
1281
|
+
const startOpacity5 =
|
|
1282
|
+
props.startOpacity5 === 0 ? 0 : props.startOpacity5 || startOpacity;
|
|
1283
|
+
const endOpacity5 =
|
|
1284
|
+
props.endOpacity5 === 0 ? 0 : props.endOpacity5 || endOpacity;
|
|
1269
1285
|
|
|
1270
1286
|
const rulesThickness =
|
|
1271
1287
|
props.rulesThickness === 0 ? 0 : props.rulesThickness || 1;
|
|
@@ -2385,24 +2401,77 @@ export const LineChart = (props: propTypes) => {
|
|
|
2385
2401
|
}}
|
|
2386
2402
|
/>
|
|
2387
2403
|
)}
|
|
2404
|
+
</View>
|
|
2405
|
+
);
|
|
2406
|
+
};
|
|
2407
|
+
|
|
2408
|
+
const renderStripAndLabel = () => {
|
|
2409
|
+
let pointerItemLocal, pointerYLocal;
|
|
2410
|
+
|
|
2411
|
+
pointerItemLocal = [pointerItem];
|
|
2412
|
+
let arr = [pointerY];
|
|
2413
|
+
if (pointerY2 !== 0) {
|
|
2414
|
+
arr.push(pointerY2);
|
|
2415
|
+
pointerItemLocal.push(pointerItem2);
|
|
2416
|
+
}
|
|
2417
|
+
if (pointerY3 !== 0) {
|
|
2418
|
+
arr.push(pointerY3);
|
|
2419
|
+
pointerItemLocal.push(pointerItem3);
|
|
2420
|
+
}
|
|
2421
|
+
if (pointerY4 !== 0) {
|
|
2422
|
+
arr.push(pointerY4);
|
|
2423
|
+
pointerItemLocal.push(pointerItem4);
|
|
2424
|
+
}
|
|
2425
|
+
if (pointerY5 !== 0) {
|
|
2426
|
+
arr.push(pointerY5);
|
|
2427
|
+
pointerItemLocal.push(pointerItem5);
|
|
2428
|
+
}
|
|
2429
|
+
pointerYLocal = Math.min(...arr);
|
|
2430
|
+
|
|
2431
|
+
return (
|
|
2432
|
+
<View
|
|
2433
|
+
style={{
|
|
2434
|
+
position: 'absolute',
|
|
2435
|
+
left: pointerX + (pointerItemLocal[0].pointerShiftX || 0),
|
|
2436
|
+
top: pointerYLocal,
|
|
2437
|
+
}}>
|
|
2388
2438
|
{showPointerStrip && (
|
|
2389
2439
|
<View
|
|
2390
2440
|
style={{
|
|
2391
2441
|
position: 'absolute',
|
|
2392
|
-
left: pointerRadius || pointerWidth /
|
|
2442
|
+
left: (pointerRadius || pointerWidth) - pointerStripWidth / 4,
|
|
2393
2443
|
top: pointerStripUptoDataPoint
|
|
2394
2444
|
? pointerRadius || pointerStripHeight / 2
|
|
2395
2445
|
: -pointerYLocal + 8,
|
|
2446
|
+
width: pointerStripWidth,
|
|
2396
2447
|
height: pointerStripUptoDataPoint
|
|
2397
|
-
? containerHeight - pointerYLocal -
|
|
2448
|
+
? containerHeight - pointerYLocal + 5 - xAxisThickness
|
|
2398
2449
|
: pointerStripHeight,
|
|
2399
|
-
width: pointerStripWidth,
|
|
2400
|
-
backgroundColor: pointerStripColor,
|
|
2401
2450
|
marginTop: pointerStripUptoDataPoint
|
|
2402
2451
|
? 0
|
|
2403
2452
|
: containerHeight - pointerStripHeight,
|
|
2404
|
-
}}
|
|
2405
|
-
|
|
2453
|
+
}}>
|
|
2454
|
+
<Svg>
|
|
2455
|
+
<Line
|
|
2456
|
+
stroke={pointerStripColor}
|
|
2457
|
+
strokeWidth={pointerStripWidth}
|
|
2458
|
+
strokeDasharray={
|
|
2459
|
+
pointerConfig.strokeDashArray
|
|
2460
|
+
? pointerConfig.strokeDashArray
|
|
2461
|
+
: ''
|
|
2462
|
+
}
|
|
2463
|
+
x1={0}
|
|
2464
|
+
y1={0}
|
|
2465
|
+
x2={0}
|
|
2466
|
+
// strokeLinecap="round"
|
|
2467
|
+
y2={
|
|
2468
|
+
pointerStripUptoDataPoint
|
|
2469
|
+
? containerHeight - pointerYLocal + 5 - xAxisThickness
|
|
2470
|
+
: pointerStripHeight
|
|
2471
|
+
}
|
|
2472
|
+
/>
|
|
2473
|
+
</Svg>
|
|
2474
|
+
</View>
|
|
2406
2475
|
)}
|
|
2407
2476
|
|
|
2408
2477
|
{pointerLabelComponent && (
|
|
@@ -2769,7 +2838,6 @@ export const LineChart = (props: propTypes) => {
|
|
|
2769
2838
|
endOpacity,
|
|
2770
2839
|
strokeDashArray,
|
|
2771
2840
|
)}
|
|
2772
|
-
{pointerX ? renderPointer(lineNumber) : null}
|
|
2773
2841
|
</View>
|
|
2774
2842
|
);
|
|
2775
2843
|
};
|
|
@@ -2971,7 +3039,6 @@ export const LineChart = (props: propTypes) => {
|
|
|
2971
3039
|
endOpacity,
|
|
2972
3040
|
strokeDashArray,
|
|
2973
3041
|
)}
|
|
2974
|
-
{pointerX ? renderPointer(lineNumber) : null}
|
|
2975
3042
|
</Animated.View>
|
|
2976
3043
|
);
|
|
2977
3044
|
};
|
|
@@ -3206,6 +3273,24 @@ export const LineChart = (props: propTypes) => {
|
|
|
3206
3273
|
strokeDashArray5,
|
|
3207
3274
|
)
|
|
3208
3275
|
: null}
|
|
3276
|
+
{pointerX ? (
|
|
3277
|
+
<View
|
|
3278
|
+
style={{
|
|
3279
|
+
position: 'absolute',
|
|
3280
|
+
height:
|
|
3281
|
+
containerHeight + 10 + horizSectionsBelow.length * stepHeight,
|
|
3282
|
+
bottom: 60 + labelsExtraHeight,
|
|
3283
|
+
width: totalWidth,
|
|
3284
|
+
zIndex: 20,
|
|
3285
|
+
}}>
|
|
3286
|
+
{renderPointer(1)}
|
|
3287
|
+
{points2 ? renderPointer(2) : null}
|
|
3288
|
+
{points3 ? renderPointer(3) : null}
|
|
3289
|
+
{points4 ? renderPointer(4) : null}
|
|
3290
|
+
{points5 ? renderPointer(5) : null}
|
|
3291
|
+
{renderStripAndLabel()}
|
|
3292
|
+
</View>
|
|
3293
|
+
) : null}
|
|
3209
3294
|
{data.map((item: itemType, index: number) => {
|
|
3210
3295
|
// console.log('item', item)
|
|
3211
3296
|
return (
|
package/src/PieChart/index.tsx
CHANGED
|
@@ -230,7 +230,7 @@ export const PieChart = (props: propTypes) => {
|
|
|
230
230
|
})}
|
|
231
231
|
</Defs>
|
|
232
232
|
{data.map((item, index) => {
|
|
233
|
-
console.log('index', index);
|
|
233
|
+
// console.log('index', index);
|
|
234
234
|
let nextItem;
|
|
235
235
|
if (index === pData.length - 1) nextItem = pData[0];
|
|
236
236
|
else nextItem = pData[index + 1];
|