react-native-gifted-charts 1.2.3 → 1.2.6
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/README.md +0 -1
- package/package.json +1 -1
- package/src/BarChart/index.tsx +3 -1
- package/src/LineChart/index.tsx +574 -313
- package/src/PieChart/index.tsx +79 -4
- package/src/todos.md +4 -4
package/README.md
CHANGED
|
@@ -96,7 +96,6 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
|
|
|
96
96
|
| Issue | Solution |
|
|
97
97
|
| ---------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
98
98
|
| [BarChart - Value and section line don't match](https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/35) | [Comment by the owner](https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/35#issuecomment-972673281) |
|
|
99
|
-
| **Invariant Violation: requireNativeComponent: "RNCWebView" was not found in the UIManager.** | install `react-native-webview` |
|
|
100
99
|
| Setting `height`, `maxValue`, `stepValue`, `stepHeight`, or `noOfSections` breaks the chart | Please make sure that<br/> `maxValue = noOfSections * stepValue;` <br/>is followed. [See this](https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/71) |
|
|
101
100
|
|
|
102
101
|
## To-dos
|
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.6",
|
|
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": [
|
package/src/BarChart/index.tsx
CHANGED
|
@@ -845,7 +845,9 @@ export const BarChart = (props: PropTypes) => {
|
|
|
845
845
|
props.hideAxesAndRules !== true &&
|
|
846
846
|
!hideYAxisText &&
|
|
847
847
|
horizSectionsBelow.map((sectionItems, index) => {
|
|
848
|
-
let label = getLabel(
|
|
848
|
+
let label = getLabel(
|
|
849
|
+
horizSectionsBelow[horizSectionsBelow.length - 1 - index].value,
|
|
850
|
+
);
|
|
849
851
|
return (
|
|
850
852
|
<View
|
|
851
853
|
key={index}
|
package/src/LineChart/index.tsx
CHANGED
|
@@ -323,7 +323,12 @@ type Pointer = {
|
|
|
323
323
|
height?: number;
|
|
324
324
|
width?: number;
|
|
325
325
|
radius?: number;
|
|
326
|
-
|
|
326
|
+
pointerColor?: ColorValue;
|
|
327
|
+
pointer1Color?: ColorValue;
|
|
328
|
+
pointer2Color?: ColorValue;
|
|
329
|
+
pointer3Color?: ColorValue;
|
|
330
|
+
pointer4Color?: ColorValue;
|
|
331
|
+
pointer5Color?: ColorValue;
|
|
327
332
|
pointerComponent?: Function;
|
|
328
333
|
showPointerStrip?: boolean;
|
|
329
334
|
pointerStripWidth?: number;
|
|
@@ -335,6 +340,13 @@ type Pointer = {
|
|
|
335
340
|
shiftPointerLabelY?: number;
|
|
336
341
|
pointerLabelWidth?: number;
|
|
337
342
|
pointerVanishDelay?: number;
|
|
343
|
+
activatePointersOnLongPress?: boolean;
|
|
344
|
+
activatePointersDelay?: number;
|
|
345
|
+
hidePointer1?: boolean;
|
|
346
|
+
hidePointer2?: boolean;
|
|
347
|
+
hidePointer3?: boolean;
|
|
348
|
+
hidePointer4?: boolean;
|
|
349
|
+
hidePointer5?: boolean;
|
|
338
350
|
};
|
|
339
351
|
|
|
340
352
|
export const LineChart = (props: propTypes) => {
|
|
@@ -345,6 +357,28 @@ export const LineChart = (props: propTypes) => {
|
|
|
345
357
|
pointerShiftX: 0,
|
|
346
358
|
pointerShiftY: 0,
|
|
347
359
|
});
|
|
360
|
+
const [pointerY2, setPointerY2] = useState(0);
|
|
361
|
+
const [pointerItem2, setPointerItem2] = useState({
|
|
362
|
+
pointerShiftX: 0,
|
|
363
|
+
pointerShiftY: 0,
|
|
364
|
+
});
|
|
365
|
+
const [pointerY3, setPointerY3] = useState(0);
|
|
366
|
+
const [pointerItem3, setPointerItem3] = useState({
|
|
367
|
+
pointerShiftX: 0,
|
|
368
|
+
pointerShiftY: 0,
|
|
369
|
+
});
|
|
370
|
+
const [pointerY4, setPointerY4] = useState(0);
|
|
371
|
+
const [pointerItem4, setPointerItem4] = useState({
|
|
372
|
+
pointerShiftX: 0,
|
|
373
|
+
pointerShiftY: 0,
|
|
374
|
+
});
|
|
375
|
+
const [pointerY5, setPointerY5] = useState(0);
|
|
376
|
+
const [pointerItem5, setPointerItem5] = useState({
|
|
377
|
+
pointerShiftX: 0,
|
|
378
|
+
pointerShiftY: 0,
|
|
379
|
+
});
|
|
380
|
+
const [responderStartTime, setResponderStartTime] = useState(0);
|
|
381
|
+
const [responderActive, setResponderActive] = useState(false);
|
|
348
382
|
const [points, setPoints] = useState('');
|
|
349
383
|
const [points2, setPoints2] = useState('');
|
|
350
384
|
const [points3, setPoints3] = useState('');
|
|
@@ -1167,11 +1201,16 @@ export const LineChart = (props: propTypes) => {
|
|
|
1167
1201
|
const stepValue = props.stepValue || maxValue / noOfSections;
|
|
1168
1202
|
const noOfSectionsBelowXAxis =
|
|
1169
1203
|
props.noOfSectionsBelowXAxis || -minValue / stepValue;
|
|
1170
|
-
const thickness1 =
|
|
1171
|
-
|
|
1172
|
-
const
|
|
1173
|
-
|
|
1174
|
-
const
|
|
1204
|
+
const thickness1 =
|
|
1205
|
+
props.thickness1 === 0 ? 0 : props.thickness1 || props.thickness || 1;
|
|
1206
|
+
const thickness2 =
|
|
1207
|
+
props.thickness2 === 0 ? 0 : props.thickness2 || props.thickness || 1;
|
|
1208
|
+
const thickness3 =
|
|
1209
|
+
props.thickness3 === 0 ? 0 : props.thickness3 || props.thickness || 1;
|
|
1210
|
+
const thickness4 =
|
|
1211
|
+
props.thickness4 === 0 ? 0 : props.thickness4 || props.thickness || 1;
|
|
1212
|
+
const thickness5 =
|
|
1213
|
+
props.thickness5 === 0 ? 0 : props.thickness5 || props.thickness || 1;
|
|
1175
1214
|
|
|
1176
1215
|
const strokeDashArray1 = props.strokeDashArray1 || props.strokeDashArray;
|
|
1177
1216
|
const strokeDashArray2 = props.strokeDashArray2 || props.strokeDashArray;
|
|
@@ -1268,7 +1307,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1268
1307
|
height: 0,
|
|
1269
1308
|
width: 0,
|
|
1270
1309
|
radius: 5,
|
|
1271
|
-
|
|
1310
|
+
pointerColor: 'red',
|
|
1272
1311
|
pointerComponent: null,
|
|
1273
1312
|
showPointerStrip: true,
|
|
1274
1313
|
pointerStripHeight: containerHeight,
|
|
@@ -1279,72 +1318,114 @@ export const LineChart = (props: propTypes) => {
|
|
|
1279
1318
|
shiftPointerLabelX: 0,
|
|
1280
1319
|
shiftPointerLabelY: 0,
|
|
1281
1320
|
pointerLabelWidth: 40,
|
|
1282
|
-
pointerVanishDelay:
|
|
1321
|
+
pointerVanishDelay: 150,
|
|
1322
|
+
activatePointersOnLongPress: false,
|
|
1323
|
+
activatePointersDelay: 150,
|
|
1324
|
+
hidePointer1: false,
|
|
1325
|
+
hidePointer2: false,
|
|
1326
|
+
hidePointer3: false,
|
|
1327
|
+
hidePointer4: false,
|
|
1328
|
+
hidePointer5: false,
|
|
1283
1329
|
};
|
|
1284
1330
|
const pointerConfig = props.pointerConfig || null;
|
|
1285
1331
|
const pointerHeight =
|
|
1286
1332
|
pointerConfig && pointerConfig.height
|
|
1287
|
-
?
|
|
1333
|
+
? pointerConfig.height
|
|
1288
1334
|
: defaultPointerConfig.height;
|
|
1289
1335
|
const pointerWidth =
|
|
1290
1336
|
pointerConfig && pointerConfig.width
|
|
1291
|
-
?
|
|
1337
|
+
? pointerConfig.width
|
|
1292
1338
|
: defaultPointerConfig.width;
|
|
1293
1339
|
const pointerRadius =
|
|
1294
1340
|
pointerConfig && pointerConfig.radius
|
|
1295
|
-
?
|
|
1341
|
+
? pointerConfig.radius
|
|
1296
1342
|
: defaultPointerConfig.radius;
|
|
1297
1343
|
const pointerColor =
|
|
1298
|
-
pointerConfig && pointerConfig.
|
|
1299
|
-
?
|
|
1300
|
-
: defaultPointerConfig.
|
|
1344
|
+
pointerConfig && pointerConfig.pointerColor
|
|
1345
|
+
? pointerConfig.pointerColor
|
|
1346
|
+
: defaultPointerConfig.pointerColor;
|
|
1301
1347
|
const pointerComponent =
|
|
1302
1348
|
pointerConfig && pointerConfig.pointerComponent
|
|
1303
|
-
?
|
|
1349
|
+
? pointerConfig.pointerComponent
|
|
1304
1350
|
: defaultPointerConfig.pointerComponent;
|
|
1305
1351
|
|
|
1306
1352
|
const showPointerStrip =
|
|
1307
1353
|
pointerConfig && pointerConfig.showPointerStrip
|
|
1308
|
-
?
|
|
1354
|
+
? pointerConfig.showPointerStrip
|
|
1309
1355
|
: defaultPointerConfig.showPointerStrip;
|
|
1310
1356
|
const pointerStripHeight =
|
|
1311
1357
|
pointerConfig && pointerConfig.pointerStripHeight
|
|
1312
|
-
?
|
|
1358
|
+
? pointerConfig.pointerStripHeight
|
|
1313
1359
|
: defaultPointerConfig.pointerStripHeight;
|
|
1314
1360
|
const pointerStripWidth =
|
|
1315
1361
|
pointerConfig && pointerConfig.pointerStripWidth
|
|
1316
|
-
?
|
|
1362
|
+
? pointerConfig.pointerStripWidth
|
|
1317
1363
|
: defaultPointerConfig.pointerStripWidth;
|
|
1318
1364
|
const pointerStripColor =
|
|
1319
1365
|
pointerConfig && pointerConfig.pointerStripColor
|
|
1320
|
-
?
|
|
1366
|
+
? pointerConfig.pointerStripColor
|
|
1321
1367
|
: defaultPointerConfig.pointerStripColor;
|
|
1322
1368
|
const pointerStripUptoDataPoint =
|
|
1323
1369
|
pointerConfig && pointerConfig.pointerStripUptoDataPoint
|
|
1324
|
-
?
|
|
1370
|
+
? pointerConfig.pointerStripUptoDataPoint
|
|
1325
1371
|
: defaultPointerConfig.pointerStripUptoDataPoint;
|
|
1326
1372
|
const pointerLabelComponent =
|
|
1327
1373
|
pointerConfig && pointerConfig.pointerLabelComponent
|
|
1328
|
-
?
|
|
1374
|
+
? pointerConfig.pointerLabelComponent
|
|
1329
1375
|
: defaultPointerConfig.pointerLabelComponent;
|
|
1330
1376
|
const shiftPointerLabelX =
|
|
1331
1377
|
pointerConfig && pointerConfig.shiftPointerLabelX
|
|
1332
|
-
?
|
|
1378
|
+
? pointerConfig.shiftPointerLabelX
|
|
1333
1379
|
: defaultPointerConfig.shiftPointerLabelX;
|
|
1334
1380
|
const shiftPointerLabelY =
|
|
1335
1381
|
pointerConfig && pointerConfig.shiftPointerLabelY
|
|
1336
|
-
?
|
|
1382
|
+
? pointerConfig.shiftPointerLabelY
|
|
1337
1383
|
: defaultPointerConfig.shiftPointerLabelY;
|
|
1338
1384
|
const pointerLabelWidth =
|
|
1339
1385
|
pointerConfig && pointerConfig.pointerLabelWidth
|
|
1340
|
-
?
|
|
1386
|
+
? pointerConfig.pointerLabelWidth
|
|
1341
1387
|
: defaultPointerConfig.pointerLabelWidth;
|
|
1342
1388
|
const pointerVanishDelay =
|
|
1343
1389
|
pointerConfig && pointerConfig.pointerVanishDelay
|
|
1344
|
-
?
|
|
1390
|
+
? pointerConfig.pointerVanishDelay
|
|
1345
1391
|
: defaultPointerConfig.pointerVanishDelay;
|
|
1346
|
-
|
|
1347
|
-
|
|
1392
|
+
const activatePointersOnLongPress =
|
|
1393
|
+
pointerConfig && pointerConfig.activatePointersOnLongPress
|
|
1394
|
+
? pointerConfig.activatePointersOnLongPress
|
|
1395
|
+
: defaultPointerConfig.activatePointersOnLongPress;
|
|
1396
|
+
const activatePointersDelay =
|
|
1397
|
+
pointerConfig && pointerConfig.activatePointersDelay
|
|
1398
|
+
? pointerConfig.activatePointersDelay
|
|
1399
|
+
: defaultPointerConfig.activatePointersDelay;
|
|
1400
|
+
const hidePointer1 =
|
|
1401
|
+
pointerConfig && pointerConfig.hidePointer1
|
|
1402
|
+
? pointerConfig.hidePointer1
|
|
1403
|
+
: defaultPointerConfig.hidePointer1;
|
|
1404
|
+
const hidePointer2 =
|
|
1405
|
+
pointerConfig && pointerConfig.hidePointer2
|
|
1406
|
+
? pointerConfig.hidePointer2
|
|
1407
|
+
: defaultPointerConfig.hidePointer2;
|
|
1408
|
+
const hidePointer3 =
|
|
1409
|
+
pointerConfig && pointerConfig.hidePointer3
|
|
1410
|
+
? pointerConfig.hidePointer3
|
|
1411
|
+
: defaultPointerConfig.hidePointer3;
|
|
1412
|
+
const hidePointer4 =
|
|
1413
|
+
pointerConfig && pointerConfig.hidePointer4
|
|
1414
|
+
? pointerConfig.hidePointer4
|
|
1415
|
+
: defaultPointerConfig.hidePointer4;
|
|
1416
|
+
const hidePointer5 =
|
|
1417
|
+
pointerConfig && pointerConfig.hidePointer5
|
|
1418
|
+
? pointerConfig.hidePointer5
|
|
1419
|
+
: defaultPointerConfig.hidePointer5;
|
|
1420
|
+
const disableScroll =
|
|
1421
|
+
props.disableScroll ||
|
|
1422
|
+
(pointerConfig
|
|
1423
|
+
? activatePointersOnLongPress
|
|
1424
|
+
? responderActive
|
|
1425
|
+
? true
|
|
1426
|
+
: false
|
|
1427
|
+
: true
|
|
1428
|
+
: false);
|
|
1348
1429
|
const showScrollIndicator = props.showScrollIndicator || false;
|
|
1349
1430
|
const hideOrigin = props.hideOrigin || false;
|
|
1350
1431
|
|
|
@@ -1785,7 +1866,9 @@ export const LineChart = (props: propTypes) => {
|
|
|
1785
1866
|
props.hideAxesAndRules !== true &&
|
|
1786
1867
|
!hideYAxisText &&
|
|
1787
1868
|
horizSectionsBelow.map((sectionItems, index) => {
|
|
1788
|
-
let label = getLabel(
|
|
1869
|
+
let label = getLabel(
|
|
1870
|
+
horizSectionsBelow[horizSectionsBelow.length - 1 - index].value,
|
|
1871
|
+
);
|
|
1789
1872
|
return (
|
|
1790
1873
|
<View
|
|
1791
1874
|
key={index}
|
|
@@ -2247,13 +2330,47 @@ export const LineChart = (props: propTypes) => {
|
|
|
2247
2330
|
});
|
|
2248
2331
|
};
|
|
2249
2332
|
|
|
2250
|
-
const renderPointer = () => {
|
|
2333
|
+
const renderPointer = (lineNumber: number) => {
|
|
2334
|
+
if (lineNumber === 1 && hidePointer1) return;
|
|
2335
|
+
if (lineNumber === 2 && hidePointer2) return;
|
|
2336
|
+
if (lineNumber === 3 && hidePointer3) return;
|
|
2337
|
+
if (lineNumber === 4 && hidePointer4) return;
|
|
2338
|
+
if (lineNumber === 5 && hidePointer5) return;
|
|
2339
|
+
let pointerItemLocal, pointerYLocal, pointerColorLocal;
|
|
2340
|
+
switch (lineNumber) {
|
|
2341
|
+
case 1:
|
|
2342
|
+
pointerItemLocal = pointerItem;
|
|
2343
|
+
pointerYLocal = pointerY;
|
|
2344
|
+
pointerColorLocal = pointerConfig.pointer1Color || pointerColor;
|
|
2345
|
+
break;
|
|
2346
|
+
case 2:
|
|
2347
|
+
pointerItemLocal = pointerItem2;
|
|
2348
|
+
pointerYLocal = pointerY2;
|
|
2349
|
+
pointerColorLocal = pointerConfig.pointer2Color || pointerColor;
|
|
2350
|
+
break;
|
|
2351
|
+
case 3:
|
|
2352
|
+
pointerItemLocal = pointerItem3;
|
|
2353
|
+
pointerYLocal = pointerY3;
|
|
2354
|
+
pointerColorLocal = pointerConfig.pointer3Color || pointerColor;
|
|
2355
|
+
break;
|
|
2356
|
+
case 4:
|
|
2357
|
+
pointerItemLocal = pointerItem4;
|
|
2358
|
+
pointerYLocal = pointerY4;
|
|
2359
|
+
pointerColorLocal = pointerConfig.pointer4Color || pointerColor;
|
|
2360
|
+
break;
|
|
2361
|
+
case 5:
|
|
2362
|
+
pointerItemLocal = pointerItem5;
|
|
2363
|
+
pointerYLocal = pointerY5;
|
|
2364
|
+
pointerColorLocal = pointerConfig.pointer5Color || pointerColor;
|
|
2365
|
+
break;
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2251
2368
|
return (
|
|
2252
2369
|
<View
|
|
2253
2370
|
style={{
|
|
2254
2371
|
position: 'absolute',
|
|
2255
|
-
left: pointerX + (
|
|
2256
|
-
top:
|
|
2372
|
+
left: pointerX + (pointerItemLocal.pointerShiftX || 0),
|
|
2373
|
+
top: pointerYLocal,
|
|
2257
2374
|
}}>
|
|
2258
2375
|
{pointerComponent ? (
|
|
2259
2376
|
pointerComponent()
|
|
@@ -2262,8 +2379,8 @@ export const LineChart = (props: propTypes) => {
|
|
|
2262
2379
|
style={{
|
|
2263
2380
|
height: pointerHeight || pointerRadius * 2,
|
|
2264
2381
|
width: pointerWidth || pointerRadius * 2,
|
|
2265
|
-
marginTop:
|
|
2266
|
-
backgroundColor:
|
|
2382
|
+
marginTop: pointerItemLocal.pointerShiftY || 0,
|
|
2383
|
+
backgroundColor: pointerColorLocal,
|
|
2267
2384
|
borderRadius: pointerRadius || 0,
|
|
2268
2385
|
}}
|
|
2269
2386
|
/>
|
|
@@ -2275,9 +2392,9 @@ export const LineChart = (props: propTypes) => {
|
|
|
2275
2392
|
left: pointerRadius || pointerWidth / 2,
|
|
2276
2393
|
top: pointerStripUptoDataPoint
|
|
2277
2394
|
? pointerRadius || pointerStripHeight / 2
|
|
2278
|
-
: -
|
|
2395
|
+
: -pointerYLocal + 8,
|
|
2279
2396
|
height: pointerStripUptoDataPoint
|
|
2280
|
-
? containerHeight -
|
|
2397
|
+
? containerHeight - pointerYLocal - 10
|
|
2281
2398
|
: pointerStripHeight,
|
|
2282
2399
|
width: pointerStripWidth,
|
|
2283
2400
|
backgroundColor: pointerStripColor,
|
|
@@ -2297,7 +2414,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2297
2414
|
top:
|
|
2298
2415
|
(pointerStripUptoDataPoint
|
|
2299
2416
|
? pointerRadius || pointerStripHeight / 2
|
|
2300
|
-
: -
|
|
2417
|
+
: -pointerYLocal + 8) -
|
|
2301
2418
|
pointerLabelWidth / 2 +
|
|
2302
2419
|
shiftPointerLabelY,
|
|
2303
2420
|
marginTop: pointerStripUptoDataPoint
|
|
@@ -2305,14 +2422,161 @@ export const LineChart = (props: propTypes) => {
|
|
|
2305
2422
|
: containerHeight - pointerStripHeight,
|
|
2306
2423
|
width: pointerLabelWidth,
|
|
2307
2424
|
}}>
|
|
2308
|
-
{pointerLabelComponent(
|
|
2425
|
+
{pointerLabelComponent(pointerItemLocal)}
|
|
2309
2426
|
</View>
|
|
2310
2427
|
)}
|
|
2311
2428
|
</View>
|
|
2312
2429
|
);
|
|
2313
2430
|
};
|
|
2314
2431
|
|
|
2432
|
+
const lineSvgComponent = (
|
|
2433
|
+
points: any,
|
|
2434
|
+
currentLineThickness: number | undefined,
|
|
2435
|
+
color: string,
|
|
2436
|
+
fillPoints: any,
|
|
2437
|
+
startFillColor: string,
|
|
2438
|
+
endFillColor: string,
|
|
2439
|
+
startOpacity: number,
|
|
2440
|
+
endOpacity: number,
|
|
2441
|
+
strokeDashArray: Array<number> | undefined | null,
|
|
2442
|
+
) => {
|
|
2443
|
+
return (
|
|
2444
|
+
<Svg>
|
|
2445
|
+
{strokeDashArray &&
|
|
2446
|
+
strokeDashArray.length === 2 &&
|
|
2447
|
+
typeof strokeDashArray[0] === 'number' &&
|
|
2448
|
+
typeof strokeDashArray[1] === 'number' ? (
|
|
2449
|
+
<Path
|
|
2450
|
+
d={points}
|
|
2451
|
+
fill="none"
|
|
2452
|
+
stroke={color}
|
|
2453
|
+
strokeWidth={currentLineThickness || thickness}
|
|
2454
|
+
strokeDasharray={strokeDashArray}
|
|
2455
|
+
/>
|
|
2456
|
+
) : (
|
|
2457
|
+
<Path
|
|
2458
|
+
d={points}
|
|
2459
|
+
fill="none"
|
|
2460
|
+
stroke={color}
|
|
2461
|
+
strokeWidth={currentLineThickness || thickness}
|
|
2462
|
+
/>
|
|
2463
|
+
)}
|
|
2464
|
+
|
|
2465
|
+
{/*********************** For Area Chart ************/}
|
|
2466
|
+
|
|
2467
|
+
{areaChart && (
|
|
2468
|
+
<LinearGradient
|
|
2469
|
+
id="Gradient"
|
|
2470
|
+
x1="0"
|
|
2471
|
+
y1="0"
|
|
2472
|
+
x2={gradientDirection === 'horizontal' ? '1' : '0'}
|
|
2473
|
+
y2={gradientDirection === 'vertical' ? '1' : '0'}>
|
|
2474
|
+
<Stop
|
|
2475
|
+
offset="0"
|
|
2476
|
+
stopColor={startFillColor}
|
|
2477
|
+
stopOpacity={startOpacity.toString()}
|
|
2478
|
+
/>
|
|
2479
|
+
<Stop
|
|
2480
|
+
offset="1"
|
|
2481
|
+
stopColor={endFillColor}
|
|
2482
|
+
stopOpacity={endOpacity.toString()}
|
|
2483
|
+
/>
|
|
2484
|
+
</LinearGradient>
|
|
2485
|
+
)}
|
|
2486
|
+
{areaChart && (
|
|
2487
|
+
<Path
|
|
2488
|
+
d={fillPoints}
|
|
2489
|
+
fill="url(#Gradient)"
|
|
2490
|
+
stroke={'transparent'}
|
|
2491
|
+
strokeWidth={currentLineThickness || thickness}
|
|
2492
|
+
/>
|
|
2493
|
+
)}
|
|
2494
|
+
|
|
2495
|
+
{/******************************************************************/}
|
|
2496
|
+
|
|
2497
|
+
{renderSpecificVerticalLines(data)}
|
|
2498
|
+
{renderSpecificVerticalLines(data2)}
|
|
2499
|
+
{renderSpecificVerticalLines(data3)}
|
|
2500
|
+
{renderSpecificVerticalLines(data4)}
|
|
2501
|
+
{renderSpecificVerticalLines(data5)}
|
|
2502
|
+
|
|
2503
|
+
{/*** !!! Here it's done thrice intentionally, trying to make it to only 1 breaks things !!! ***/}
|
|
2504
|
+
{!hideDataPoints1
|
|
2505
|
+
? renderDataPoints(
|
|
2506
|
+
data,
|
|
2507
|
+
dataPointsShape1,
|
|
2508
|
+
dataPointsWidth1,
|
|
2509
|
+
dataPointsHeight1,
|
|
2510
|
+
dataPointsColor1,
|
|
2511
|
+
dataPointsRadius1,
|
|
2512
|
+
textColor1,
|
|
2513
|
+
textFontSize1,
|
|
2514
|
+
startIndex1,
|
|
2515
|
+
endIndex1,
|
|
2516
|
+
)
|
|
2517
|
+
: null}
|
|
2518
|
+
{!hideDataPoints2
|
|
2519
|
+
? renderDataPoints(
|
|
2520
|
+
data2,
|
|
2521
|
+
dataPointsShape2,
|
|
2522
|
+
dataPointsWidth2,
|
|
2523
|
+
dataPointsHeight2,
|
|
2524
|
+
dataPointsColor2,
|
|
2525
|
+
dataPointsRadius2,
|
|
2526
|
+
textColor2,
|
|
2527
|
+
textFontSize2,
|
|
2528
|
+
startIndex2,
|
|
2529
|
+
endIndex2,
|
|
2530
|
+
)
|
|
2531
|
+
: null}
|
|
2532
|
+
{!hideDataPoints3
|
|
2533
|
+
? renderDataPoints(
|
|
2534
|
+
data3,
|
|
2535
|
+
dataPointsShape3,
|
|
2536
|
+
dataPointsWidth3,
|
|
2537
|
+
dataPointsHeight3,
|
|
2538
|
+
dataPointsColor3,
|
|
2539
|
+
dataPointsRadius3,
|
|
2540
|
+
textColor3,
|
|
2541
|
+
textFontSize3,
|
|
2542
|
+
startIndex3,
|
|
2543
|
+
endIndex3,
|
|
2544
|
+
)
|
|
2545
|
+
: null}
|
|
2546
|
+
{!hideDataPoints4
|
|
2547
|
+
? renderDataPoints(
|
|
2548
|
+
data4,
|
|
2549
|
+
dataPointsShape4,
|
|
2550
|
+
dataPointsWidth4,
|
|
2551
|
+
dataPointsHeight4,
|
|
2552
|
+
dataPointsColor4,
|
|
2553
|
+
dataPointsRadius4,
|
|
2554
|
+
textColor4,
|
|
2555
|
+
textFontSize4,
|
|
2556
|
+
startIndex4,
|
|
2557
|
+
endIndex4,
|
|
2558
|
+
)
|
|
2559
|
+
: null}
|
|
2560
|
+
{!hideDataPoints5
|
|
2561
|
+
? renderDataPoints(
|
|
2562
|
+
data5,
|
|
2563
|
+
dataPointsShape5,
|
|
2564
|
+
dataPointsWidth5,
|
|
2565
|
+
dataPointsHeight5,
|
|
2566
|
+
dataPointsColor5,
|
|
2567
|
+
dataPointsRadius5,
|
|
2568
|
+
textColor5,
|
|
2569
|
+
textFontSize5,
|
|
2570
|
+
startIndex5,
|
|
2571
|
+
endIndex5,
|
|
2572
|
+
)
|
|
2573
|
+
: null}
|
|
2574
|
+
</Svg>
|
|
2575
|
+
);
|
|
2576
|
+
};
|
|
2577
|
+
|
|
2315
2578
|
const renderLine = (
|
|
2579
|
+
lineNumber: number,
|
|
2316
2580
|
points: any,
|
|
2317
2581
|
currentLineThickness: number | undefined,
|
|
2318
2582
|
color: string,
|
|
@@ -2329,6 +2593,10 @@ export const LineChart = (props: propTypes) => {
|
|
|
2329
2593
|
onMoveShouldSetResponder={evt => (pointerConfig ? true : false)}
|
|
2330
2594
|
onResponderGrant={evt => {
|
|
2331
2595
|
if (!pointerConfig) return;
|
|
2596
|
+
setResponderStartTime(evt.timeStamp);
|
|
2597
|
+
if (activatePointersOnLongPress) {
|
|
2598
|
+
return;
|
|
2599
|
+
}
|
|
2332
2600
|
let x = evt.nativeEvent.locationX;
|
|
2333
2601
|
let factor = (x - initialSpacing) / spacing;
|
|
2334
2602
|
factor = Math.round(factor);
|
|
@@ -2338,19 +2606,77 @@ export const LineChart = (props: propTypes) => {
|
|
|
2338
2606
|
initialSpacing +
|
|
2339
2607
|
spacing * factor -
|
|
2340
2608
|
(pointerRadius || pointerWidth / 2) -
|
|
2341
|
-
|
|
2609
|
+
2;
|
|
2342
2610
|
setPointerX(z);
|
|
2343
|
-
let item
|
|
2344
|
-
|
|
2611
|
+
let item, y;
|
|
2612
|
+
setPointerX(z);
|
|
2613
|
+
item = data[factor];
|
|
2614
|
+
y =
|
|
2345
2615
|
containerHeight -
|
|
2346
2616
|
(item.value * containerHeight) / maxValue -
|
|
2347
2617
|
(pointerRadius || pointerHeight / 2) +
|
|
2348
2618
|
10;
|
|
2349
2619
|
setPointerY(y);
|
|
2350
2620
|
setPointerItem(item);
|
|
2621
|
+
if (data2 && data2.length) {
|
|
2622
|
+
item = data2[factor];
|
|
2623
|
+
if (item) {
|
|
2624
|
+
y =
|
|
2625
|
+
containerHeight -
|
|
2626
|
+
(item.value * containerHeight) / maxValue -
|
|
2627
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2628
|
+
10;
|
|
2629
|
+
setPointerY2(y);
|
|
2630
|
+
setPointerItem2(item);
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
if (data3 && data3.length) {
|
|
2634
|
+
item = data3[factor];
|
|
2635
|
+
if (item) {
|
|
2636
|
+
y =
|
|
2637
|
+
containerHeight -
|
|
2638
|
+
(item.value * containerHeight) / maxValue -
|
|
2639
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2640
|
+
10;
|
|
2641
|
+
setPointerY3(y);
|
|
2642
|
+
setPointerItem3(item);
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
if (data4 && data4.length) {
|
|
2646
|
+
item = data4[factor];
|
|
2647
|
+
if (item) {
|
|
2648
|
+
y =
|
|
2649
|
+
containerHeight -
|
|
2650
|
+
(item.value * containerHeight) / maxValue -
|
|
2651
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2652
|
+
10;
|
|
2653
|
+
setPointerY4(y);
|
|
2654
|
+
setPointerItem4(item);
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
if (data5 && data5.length) {
|
|
2658
|
+
item = data5[factor];
|
|
2659
|
+
if (item) {
|
|
2660
|
+
y =
|
|
2661
|
+
containerHeight -
|
|
2662
|
+
(item.value * containerHeight) / maxValue -
|
|
2663
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2664
|
+
10;
|
|
2665
|
+
setPointerY5(y);
|
|
2666
|
+
setPointerItem5(item);
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2351
2669
|
}}
|
|
2352
2670
|
onResponderMove={evt => {
|
|
2353
2671
|
if (!pointerConfig) return;
|
|
2672
|
+
if (
|
|
2673
|
+
activatePointersOnLongPress &&
|
|
2674
|
+
evt.timeStamp - responderStartTime < activatePointersDelay
|
|
2675
|
+
) {
|
|
2676
|
+
return;
|
|
2677
|
+
} else {
|
|
2678
|
+
setResponderActive(true);
|
|
2679
|
+
}
|
|
2354
2680
|
let x = evt.nativeEvent.locationX;
|
|
2355
2681
|
let factor = (x - initialSpacing) / spacing;
|
|
2356
2682
|
factor = Math.round(factor);
|
|
@@ -2360,18 +2686,69 @@ export const LineChart = (props: propTypes) => {
|
|
|
2360
2686
|
initialSpacing +
|
|
2361
2687
|
spacing * factor -
|
|
2362
2688
|
(pointerRadius || pointerWidth / 2) -
|
|
2363
|
-
|
|
2689
|
+
2;
|
|
2690
|
+
let item, y;
|
|
2364
2691
|
setPointerX(z);
|
|
2365
|
-
|
|
2366
|
-
|
|
2692
|
+
item = data[factor];
|
|
2693
|
+
y =
|
|
2367
2694
|
containerHeight -
|
|
2368
2695
|
(item.value * containerHeight) / maxValue -
|
|
2369
2696
|
(pointerRadius || pointerHeight / 2) +
|
|
2370
2697
|
10;
|
|
2371
2698
|
setPointerY(y);
|
|
2372
2699
|
setPointerItem(item);
|
|
2700
|
+
if (data2 && data2.length) {
|
|
2701
|
+
item = data2[factor];
|
|
2702
|
+
if (item) {
|
|
2703
|
+
y =
|
|
2704
|
+
containerHeight -
|
|
2705
|
+
(item.value * containerHeight) / maxValue -
|
|
2706
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2707
|
+
10;
|
|
2708
|
+
setPointerY2(y);
|
|
2709
|
+
setPointerItem2(item);
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
if (data3 && data3.length) {
|
|
2713
|
+
item = data3[factor];
|
|
2714
|
+
if (item) {
|
|
2715
|
+
y =
|
|
2716
|
+
containerHeight -
|
|
2717
|
+
(item.value * containerHeight) / maxValue -
|
|
2718
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2719
|
+
10;
|
|
2720
|
+
setPointerY3(y);
|
|
2721
|
+
setPointerItem3(item);
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
if (data4 && data4.length) {
|
|
2725
|
+
item = data4[factor];
|
|
2726
|
+
if (item) {
|
|
2727
|
+
y =
|
|
2728
|
+
containerHeight -
|
|
2729
|
+
(item.value * containerHeight) / maxValue -
|
|
2730
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2731
|
+
10;
|
|
2732
|
+
setPointerY4(y);
|
|
2733
|
+
setPointerItem4(item);
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
if (data5 && data5.length) {
|
|
2737
|
+
item = data5[factor];
|
|
2738
|
+
if (item) {
|
|
2739
|
+
y =
|
|
2740
|
+
containerHeight -
|
|
2741
|
+
(item.value * containerHeight) / maxValue -
|
|
2742
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2743
|
+
10;
|
|
2744
|
+
setPointerY5(y);
|
|
2745
|
+
setPointerItem5(item);
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2373
2748
|
}}
|
|
2374
2749
|
onResponderRelease={evt => {
|
|
2750
|
+
setResponderStartTime(0);
|
|
2751
|
+
setResponderActive(false);
|
|
2375
2752
|
setTimeout(() => setPointerX(0), pointerVanishDelay);
|
|
2376
2753
|
}}
|
|
2377
2754
|
style={{
|
|
@@ -2381,143 +2758,24 @@ export const LineChart = (props: propTypes) => {
|
|
|
2381
2758
|
width: totalWidth,
|
|
2382
2759
|
zIndex: 20,
|
|
2383
2760
|
}}>
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
) : (
|
|
2397
|
-
<Path
|
|
2398
|
-
d={points}
|
|
2399
|
-
fill="none"
|
|
2400
|
-
stroke={color}
|
|
2401
|
-
strokeWidth={currentLineThickness || thickness}
|
|
2402
|
-
/>
|
|
2403
|
-
)}
|
|
2404
|
-
|
|
2405
|
-
{/*********************** For Area Chart ************/}
|
|
2406
|
-
|
|
2407
|
-
{areaChart && (
|
|
2408
|
-
<LinearGradient
|
|
2409
|
-
id="Gradient"
|
|
2410
|
-
x1="0"
|
|
2411
|
-
y1="0"
|
|
2412
|
-
x2={gradientDirection === 'horizontal' ? '1' : '0'}
|
|
2413
|
-
y2={gradientDirection === 'vertical' ? '1' : '0'}>
|
|
2414
|
-
<Stop
|
|
2415
|
-
offset="0"
|
|
2416
|
-
stopColor={startFillColor}
|
|
2417
|
-
stopOpacity={startOpacity.toString()}
|
|
2418
|
-
/>
|
|
2419
|
-
<Stop
|
|
2420
|
-
offset="1"
|
|
2421
|
-
stopColor={endFillColor}
|
|
2422
|
-
stopOpacity={endOpacity.toString()}
|
|
2423
|
-
/>
|
|
2424
|
-
</LinearGradient>
|
|
2425
|
-
)}
|
|
2426
|
-
{areaChart && (
|
|
2427
|
-
<Path
|
|
2428
|
-
d={fillPoints}
|
|
2429
|
-
fill="url(#Gradient)"
|
|
2430
|
-
stroke={'transparent'}
|
|
2431
|
-
strokeWidth={currentLineThickness || thickness}
|
|
2432
|
-
/>
|
|
2433
|
-
)}
|
|
2434
|
-
|
|
2435
|
-
{/******************************************************************/}
|
|
2436
|
-
|
|
2437
|
-
{renderSpecificVerticalLines(data)}
|
|
2438
|
-
{renderSpecificVerticalLines(data2)}
|
|
2439
|
-
{renderSpecificVerticalLines(data3)}
|
|
2440
|
-
{renderSpecificVerticalLines(data4)}
|
|
2441
|
-
{renderSpecificVerticalLines(data5)}
|
|
2442
|
-
|
|
2443
|
-
{/*** !!! Here it's done thrice intentionally, trying to make it to only 1 breaks things !!! ***/}
|
|
2444
|
-
{!hideDataPoints1
|
|
2445
|
-
? renderDataPoints(
|
|
2446
|
-
data,
|
|
2447
|
-
dataPointsShape1,
|
|
2448
|
-
dataPointsWidth1,
|
|
2449
|
-
dataPointsHeight1,
|
|
2450
|
-
dataPointsColor1,
|
|
2451
|
-
dataPointsRadius1,
|
|
2452
|
-
textColor1,
|
|
2453
|
-
textFontSize1,
|
|
2454
|
-
startIndex1,
|
|
2455
|
-
endIndex1,
|
|
2456
|
-
)
|
|
2457
|
-
: null}
|
|
2458
|
-
{!hideDataPoints2
|
|
2459
|
-
? renderDataPoints(
|
|
2460
|
-
data2,
|
|
2461
|
-
dataPointsShape2,
|
|
2462
|
-
dataPointsWidth2,
|
|
2463
|
-
dataPointsHeight2,
|
|
2464
|
-
dataPointsColor2,
|
|
2465
|
-
dataPointsRadius2,
|
|
2466
|
-
textColor2,
|
|
2467
|
-
textFontSize2,
|
|
2468
|
-
startIndex2,
|
|
2469
|
-
endIndex2,
|
|
2470
|
-
)
|
|
2471
|
-
: null}
|
|
2472
|
-
{!hideDataPoints3
|
|
2473
|
-
? renderDataPoints(
|
|
2474
|
-
data3,
|
|
2475
|
-
dataPointsShape3,
|
|
2476
|
-
dataPointsWidth3,
|
|
2477
|
-
dataPointsHeight3,
|
|
2478
|
-
dataPointsColor3,
|
|
2479
|
-
dataPointsRadius3,
|
|
2480
|
-
textColor3,
|
|
2481
|
-
textFontSize3,
|
|
2482
|
-
startIndex3,
|
|
2483
|
-
endIndex3,
|
|
2484
|
-
)
|
|
2485
|
-
: null}
|
|
2486
|
-
{!hideDataPoints4
|
|
2487
|
-
? renderDataPoints(
|
|
2488
|
-
data4,
|
|
2489
|
-
dataPointsShape4,
|
|
2490
|
-
dataPointsWidth4,
|
|
2491
|
-
dataPointsHeight4,
|
|
2492
|
-
dataPointsColor4,
|
|
2493
|
-
dataPointsRadius4,
|
|
2494
|
-
textColor4,
|
|
2495
|
-
textFontSize4,
|
|
2496
|
-
startIndex4,
|
|
2497
|
-
endIndex4,
|
|
2498
|
-
)
|
|
2499
|
-
: null}
|
|
2500
|
-
{!hideDataPoints5
|
|
2501
|
-
? renderDataPoints(
|
|
2502
|
-
data5,
|
|
2503
|
-
dataPointsShape5,
|
|
2504
|
-
dataPointsWidth5,
|
|
2505
|
-
dataPointsHeight5,
|
|
2506
|
-
dataPointsColor5,
|
|
2507
|
-
dataPointsRadius5,
|
|
2508
|
-
textColor5,
|
|
2509
|
-
textFontSize5,
|
|
2510
|
-
startIndex5,
|
|
2511
|
-
endIndex5,
|
|
2512
|
-
)
|
|
2513
|
-
: null}
|
|
2514
|
-
</Svg>
|
|
2515
|
-
{pointerX ? renderPointer() : null}
|
|
2761
|
+
{lineSvgComponent(
|
|
2762
|
+
points,
|
|
2763
|
+
currentLineThickness,
|
|
2764
|
+
color,
|
|
2765
|
+
fillPoints,
|
|
2766
|
+
startFillColor,
|
|
2767
|
+
endFillColor,
|
|
2768
|
+
startOpacity,
|
|
2769
|
+
endOpacity,
|
|
2770
|
+
strokeDashArray,
|
|
2771
|
+
)}
|
|
2772
|
+
{pointerX ? renderPointer(lineNumber) : null}
|
|
2516
2773
|
</View>
|
|
2517
2774
|
);
|
|
2518
2775
|
};
|
|
2519
2776
|
|
|
2520
2777
|
const renderAnimatedLine = (
|
|
2778
|
+
lineNumber: number,
|
|
2521
2779
|
points: any,
|
|
2522
2780
|
animatedWidth: any,
|
|
2523
2781
|
currentLineThickness: number | undefined,
|
|
@@ -2536,6 +2794,10 @@ export const LineChart = (props: propTypes) => {
|
|
|
2536
2794
|
onMoveShouldSetResponder={evt => (pointerConfig ? true : false)}
|
|
2537
2795
|
onResponderGrant={evt => {
|
|
2538
2796
|
if (!pointerConfig) return;
|
|
2797
|
+
setResponderStartTime(evt.timeStamp);
|
|
2798
|
+
if (activatePointersOnLongPress) {
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2539
2801
|
let x = evt.nativeEvent.locationX;
|
|
2540
2802
|
let factor = (x - initialSpacing) / spacing;
|
|
2541
2803
|
factor = Math.round(factor);
|
|
@@ -2545,19 +2807,77 @@ export const LineChart = (props: propTypes) => {
|
|
|
2545
2807
|
initialSpacing +
|
|
2546
2808
|
spacing * factor -
|
|
2547
2809
|
(pointerRadius || pointerWidth / 2) -
|
|
2548
|
-
|
|
2810
|
+
2;
|
|
2811
|
+
setPointerX(z);
|
|
2812
|
+
let item, y;
|
|
2549
2813
|
setPointerX(z);
|
|
2550
|
-
|
|
2551
|
-
|
|
2814
|
+
item = data[factor];
|
|
2815
|
+
y =
|
|
2552
2816
|
containerHeight -
|
|
2553
2817
|
(item.value * containerHeight) / maxValue -
|
|
2554
2818
|
(pointerRadius || pointerHeight / 2) +
|
|
2555
2819
|
10;
|
|
2556
2820
|
setPointerY(y);
|
|
2557
2821
|
setPointerItem(item);
|
|
2822
|
+
if (data2 && data2.length) {
|
|
2823
|
+
item = data2[factor];
|
|
2824
|
+
if (item) {
|
|
2825
|
+
y =
|
|
2826
|
+
containerHeight -
|
|
2827
|
+
(item.value * containerHeight) / maxValue -
|
|
2828
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2829
|
+
10;
|
|
2830
|
+
setPointerY2(y);
|
|
2831
|
+
setPointerItem2(item);
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
if (data3 && data3.length) {
|
|
2835
|
+
item = data3[factor];
|
|
2836
|
+
if (item) {
|
|
2837
|
+
y =
|
|
2838
|
+
containerHeight -
|
|
2839
|
+
(item.value * containerHeight) / maxValue -
|
|
2840
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2841
|
+
10;
|
|
2842
|
+
setPointerY3(y);
|
|
2843
|
+
setPointerItem3(item);
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
if (data4 && data4.length) {
|
|
2847
|
+
item = data4[factor];
|
|
2848
|
+
if (item) {
|
|
2849
|
+
y =
|
|
2850
|
+
containerHeight -
|
|
2851
|
+
(item.value * containerHeight) / maxValue -
|
|
2852
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2853
|
+
10;
|
|
2854
|
+
setPointerY4(y);
|
|
2855
|
+
setPointerItem4(item);
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
if (data5 && data5.length) {
|
|
2859
|
+
item = data5[factor];
|
|
2860
|
+
if (item) {
|
|
2861
|
+
y =
|
|
2862
|
+
containerHeight -
|
|
2863
|
+
(item.value * containerHeight) / maxValue -
|
|
2864
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2865
|
+
10;
|
|
2866
|
+
setPointerY5(y);
|
|
2867
|
+
setPointerItem5(item);
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2558
2870
|
}}
|
|
2559
2871
|
onResponderMove={evt => {
|
|
2560
2872
|
if (!pointerConfig) return;
|
|
2873
|
+
if (
|
|
2874
|
+
activatePointersOnLongPress &&
|
|
2875
|
+
evt.timeStamp - responderStartTime < activatePointersDelay
|
|
2876
|
+
) {
|
|
2877
|
+
return;
|
|
2878
|
+
} else {
|
|
2879
|
+
setResponderActive(true);
|
|
2880
|
+
}
|
|
2561
2881
|
let x = evt.nativeEvent.locationX;
|
|
2562
2882
|
let factor = (x - initialSpacing) / spacing;
|
|
2563
2883
|
factor = Math.round(factor);
|
|
@@ -2567,18 +2887,69 @@ export const LineChart = (props: propTypes) => {
|
|
|
2567
2887
|
initialSpacing +
|
|
2568
2888
|
spacing * factor -
|
|
2569
2889
|
(pointerRadius || pointerWidth / 2) -
|
|
2570
|
-
|
|
2890
|
+
2;
|
|
2891
|
+
let item, y;
|
|
2571
2892
|
setPointerX(z);
|
|
2572
|
-
|
|
2573
|
-
|
|
2893
|
+
item = data[factor];
|
|
2894
|
+
y =
|
|
2574
2895
|
containerHeight -
|
|
2575
2896
|
(item.value * containerHeight) / maxValue -
|
|
2576
2897
|
(pointerRadius || pointerHeight / 2) +
|
|
2577
2898
|
10;
|
|
2578
2899
|
setPointerY(y);
|
|
2579
2900
|
setPointerItem(item);
|
|
2901
|
+
if (data2 && data2.length) {
|
|
2902
|
+
item = data2[factor];
|
|
2903
|
+
if (item) {
|
|
2904
|
+
y =
|
|
2905
|
+
containerHeight -
|
|
2906
|
+
(item.value * containerHeight) / maxValue -
|
|
2907
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2908
|
+
10;
|
|
2909
|
+
setPointerY2(y);
|
|
2910
|
+
setPointerItem2(item);
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
if (data3 && data3.length) {
|
|
2914
|
+
item = data3[factor];
|
|
2915
|
+
if (item) {
|
|
2916
|
+
y =
|
|
2917
|
+
containerHeight -
|
|
2918
|
+
(item.value * containerHeight) / maxValue -
|
|
2919
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2920
|
+
10;
|
|
2921
|
+
setPointerY3(y);
|
|
2922
|
+
setPointerItem3(item);
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
if (data4 && data4.length) {
|
|
2926
|
+
item = data4[factor];
|
|
2927
|
+
if (item) {
|
|
2928
|
+
y =
|
|
2929
|
+
containerHeight -
|
|
2930
|
+
(item.value * containerHeight) / maxValue -
|
|
2931
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2932
|
+
10;
|
|
2933
|
+
setPointerY4(y);
|
|
2934
|
+
setPointerItem4(item);
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
if (data5 && data5.length) {
|
|
2938
|
+
item = data5[factor];
|
|
2939
|
+
if (item) {
|
|
2940
|
+
y =
|
|
2941
|
+
containerHeight -
|
|
2942
|
+
(item.value * containerHeight) / maxValue -
|
|
2943
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2944
|
+
10;
|
|
2945
|
+
setPointerY5(y);
|
|
2946
|
+
setPointerItem5(item);
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2580
2949
|
}}
|
|
2581
2950
|
onResponderRelease={evt => {
|
|
2951
|
+
setResponderStartTime(0);
|
|
2952
|
+
setResponderActive(false);
|
|
2582
2953
|
setTimeout(() => setPointerX(0), pointerVanishDelay);
|
|
2583
2954
|
}}
|
|
2584
2955
|
style={{
|
|
@@ -2589,138 +2960,18 @@ export const LineChart = (props: propTypes) => {
|
|
|
2589
2960
|
zIndex: -1,
|
|
2590
2961
|
// backgroundColor: 'wheat',
|
|
2591
2962
|
}}>
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
) : (
|
|
2605
|
-
<Path
|
|
2606
|
-
d={points}
|
|
2607
|
-
fill="none"
|
|
2608
|
-
stroke={color}
|
|
2609
|
-
strokeWidth={currentLineThickness || thickness}
|
|
2610
|
-
/>
|
|
2611
|
-
)}
|
|
2612
|
-
|
|
2613
|
-
{/*********************** For Area Chart ************/}
|
|
2614
|
-
|
|
2615
|
-
{areaChart && (
|
|
2616
|
-
<LinearGradient
|
|
2617
|
-
id="Gradient"
|
|
2618
|
-
x1="0"
|
|
2619
|
-
y1="0"
|
|
2620
|
-
x2={gradientDirection === 'horizontal' ? '1' : '0'}
|
|
2621
|
-
y2={gradientDirection === 'vertical' ? '1' : '0'}>
|
|
2622
|
-
<Stop
|
|
2623
|
-
offset="0"
|
|
2624
|
-
stopColor={startFillColor}
|
|
2625
|
-
stopOpacity={startOpacity.toString()}
|
|
2626
|
-
/>
|
|
2627
|
-
<Stop
|
|
2628
|
-
offset="1"
|
|
2629
|
-
stopColor={endFillColor}
|
|
2630
|
-
stopOpacity={endOpacity.toString()}
|
|
2631
|
-
/>
|
|
2632
|
-
</LinearGradient>
|
|
2633
|
-
)}
|
|
2634
|
-
{areaChart && (
|
|
2635
|
-
<Path
|
|
2636
|
-
d={fillPoints}
|
|
2637
|
-
fill="url(#Gradient)"
|
|
2638
|
-
stroke={'transparent'}
|
|
2639
|
-
strokeWidth={currentLineThickness || thickness}
|
|
2640
|
-
/>
|
|
2641
|
-
)}
|
|
2642
|
-
|
|
2643
|
-
{/******************************************************************/}
|
|
2644
|
-
|
|
2645
|
-
{renderSpecificVerticalLines(data)}
|
|
2646
|
-
{renderSpecificVerticalLines(data2)}
|
|
2647
|
-
{renderSpecificVerticalLines(data3)}
|
|
2648
|
-
{renderSpecificVerticalLines(data4)}
|
|
2649
|
-
{renderSpecificVerticalLines(data5)}
|
|
2650
|
-
|
|
2651
|
-
{/*** !!! Here it's done thrice intentionally, trying to make it to only 1 breaks things !!! ***/}
|
|
2652
|
-
{!hideDataPoints1
|
|
2653
|
-
? renderDataPoints(
|
|
2654
|
-
data,
|
|
2655
|
-
dataPointsShape1,
|
|
2656
|
-
dataPointsWidth1,
|
|
2657
|
-
dataPointsHeight1,
|
|
2658
|
-
dataPointsColor1,
|
|
2659
|
-
dataPointsRadius1,
|
|
2660
|
-
textColor1,
|
|
2661
|
-
textFontSize1,
|
|
2662
|
-
startIndex1,
|
|
2663
|
-
endIndex1,
|
|
2664
|
-
)
|
|
2665
|
-
: null}
|
|
2666
|
-
{!hideDataPoints2
|
|
2667
|
-
? renderDataPoints(
|
|
2668
|
-
data2,
|
|
2669
|
-
dataPointsShape2,
|
|
2670
|
-
dataPointsWidth2,
|
|
2671
|
-
dataPointsHeight2,
|
|
2672
|
-
dataPointsColor2,
|
|
2673
|
-
dataPointsRadius2,
|
|
2674
|
-
textColor2,
|
|
2675
|
-
textFontSize2,
|
|
2676
|
-
startIndex2,
|
|
2677
|
-
endIndex2,
|
|
2678
|
-
)
|
|
2679
|
-
: null}
|
|
2680
|
-
{!hideDataPoints3
|
|
2681
|
-
? renderDataPoints(
|
|
2682
|
-
data3,
|
|
2683
|
-
dataPointsShape3,
|
|
2684
|
-
dataPointsWidth3,
|
|
2685
|
-
dataPointsHeight3,
|
|
2686
|
-
dataPointsColor3,
|
|
2687
|
-
dataPointsRadius3,
|
|
2688
|
-
textColor3,
|
|
2689
|
-
textFontSize3,
|
|
2690
|
-
startIndex3,
|
|
2691
|
-
endIndex3,
|
|
2692
|
-
)
|
|
2693
|
-
: null}
|
|
2694
|
-
{!hideDataPoints4
|
|
2695
|
-
? renderDataPoints(
|
|
2696
|
-
data4,
|
|
2697
|
-
dataPointsShape4,
|
|
2698
|
-
dataPointsWidth4,
|
|
2699
|
-
dataPointsHeight4,
|
|
2700
|
-
dataPointsColor4,
|
|
2701
|
-
dataPointsRadius4,
|
|
2702
|
-
textColor4,
|
|
2703
|
-
textFontSize4,
|
|
2704
|
-
startIndex4,
|
|
2705
|
-
endIndex4,
|
|
2706
|
-
)
|
|
2707
|
-
: null}
|
|
2708
|
-
{!hideDataPoints5
|
|
2709
|
-
? renderDataPoints(
|
|
2710
|
-
data5,
|
|
2711
|
-
dataPointsShape5,
|
|
2712
|
-
dataPointsWidth5,
|
|
2713
|
-
dataPointsHeight5,
|
|
2714
|
-
dataPointsColor5,
|
|
2715
|
-
dataPointsRadius5,
|
|
2716
|
-
textColor5,
|
|
2717
|
-
textFontSize5,
|
|
2718
|
-
startIndex5,
|
|
2719
|
-
endIndex5,
|
|
2720
|
-
)
|
|
2721
|
-
: null}
|
|
2722
|
-
</Svg>
|
|
2723
|
-
{pointerX ? renderPointer() : null}
|
|
2963
|
+
{lineSvgComponent(
|
|
2964
|
+
points,
|
|
2965
|
+
currentLineThickness,
|
|
2966
|
+
color,
|
|
2967
|
+
fillPoints,
|
|
2968
|
+
startFillColor,
|
|
2969
|
+
endFillColor,
|
|
2970
|
+
startOpacity,
|
|
2971
|
+
endOpacity,
|
|
2972
|
+
strokeDashArray,
|
|
2973
|
+
)}
|
|
2974
|
+
{pointerX ? renderPointer(lineNumber) : null}
|
|
2724
2975
|
</Animated.View>
|
|
2725
2976
|
);
|
|
2726
2977
|
};
|
|
@@ -2819,6 +3070,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2819
3070
|
|
|
2820
3071
|
{isAnimated
|
|
2821
3072
|
? renderAnimatedLine(
|
|
3073
|
+
1,
|
|
2822
3074
|
points,
|
|
2823
3075
|
animatedWidth,
|
|
2824
3076
|
thickness1,
|
|
@@ -2831,6 +3083,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2831
3083
|
strokeDashArray1,
|
|
2832
3084
|
)
|
|
2833
3085
|
: renderLine(
|
|
3086
|
+
1,
|
|
2834
3087
|
points,
|
|
2835
3088
|
thickness1,
|
|
2836
3089
|
color1,
|
|
@@ -2844,6 +3097,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2844
3097
|
{points2
|
|
2845
3098
|
? isAnimated
|
|
2846
3099
|
? renderAnimatedLine(
|
|
3100
|
+
2,
|
|
2847
3101
|
points2,
|
|
2848
3102
|
animatedWidth2,
|
|
2849
3103
|
thickness2,
|
|
@@ -2856,6 +3110,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2856
3110
|
strokeDashArray2,
|
|
2857
3111
|
)
|
|
2858
3112
|
: renderLine(
|
|
3113
|
+
2,
|
|
2859
3114
|
points2,
|
|
2860
3115
|
thickness2,
|
|
2861
3116
|
color2,
|
|
@@ -2870,6 +3125,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2870
3125
|
{points3
|
|
2871
3126
|
? isAnimated
|
|
2872
3127
|
? renderAnimatedLine(
|
|
3128
|
+
3,
|
|
2873
3129
|
points3,
|
|
2874
3130
|
animatedWidth3,
|
|
2875
3131
|
thickness3,
|
|
@@ -2882,6 +3138,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2882
3138
|
strokeDashArray3,
|
|
2883
3139
|
)
|
|
2884
3140
|
: renderLine(
|
|
3141
|
+
3,
|
|
2885
3142
|
points3,
|
|
2886
3143
|
thickness3,
|
|
2887
3144
|
color3,
|
|
@@ -2896,6 +3153,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2896
3153
|
{points4
|
|
2897
3154
|
? isAnimated
|
|
2898
3155
|
? renderAnimatedLine(
|
|
3156
|
+
4,
|
|
2899
3157
|
points4,
|
|
2900
3158
|
animatedWidth4,
|
|
2901
3159
|
thickness4,
|
|
@@ -2908,6 +3166,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2908
3166
|
strokeDashArray4,
|
|
2909
3167
|
)
|
|
2910
3168
|
: renderLine(
|
|
3169
|
+
4,
|
|
2911
3170
|
points4,
|
|
2912
3171
|
thickness4,
|
|
2913
3172
|
color4,
|
|
@@ -2922,6 +3181,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2922
3181
|
{points5
|
|
2923
3182
|
? isAnimated
|
|
2924
3183
|
? renderAnimatedLine(
|
|
3184
|
+
5,
|
|
2925
3185
|
points5,
|
|
2926
3186
|
animatedWidth5,
|
|
2927
3187
|
thickness5,
|
|
@@ -2934,6 +3194,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
2934
3194
|
strokeDashArray5,
|
|
2935
3195
|
)
|
|
2936
3196
|
: renderLine(
|
|
3197
|
+
5,
|
|
2937
3198
|
points5,
|
|
2938
3199
|
thickness5,
|
|
2939
3200
|
color5,
|
package/src/PieChart/index.tsx
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import {ColorValue, View} from 'react-native';
|
|
3
|
-
import Svg, {
|
|
3
|
+
import Svg, {
|
|
4
|
+
Path,
|
|
5
|
+
Circle,
|
|
6
|
+
Text as SvgText,
|
|
7
|
+
FontStyle,
|
|
8
|
+
Defs,
|
|
9
|
+
RadialGradient,
|
|
10
|
+
Stop,
|
|
11
|
+
} from 'react-native-svg';
|
|
4
12
|
|
|
5
13
|
type propTypes = {
|
|
6
14
|
radius?: number;
|
|
@@ -36,12 +44,17 @@ type propTypes = {
|
|
|
36
44
|
tiltAngle?: string;
|
|
37
45
|
initialAngle?: number;
|
|
38
46
|
labelsPosition?: 'onBorder' | 'outward' | 'inward' | 'mid';
|
|
47
|
+
showGradient?: boolean;
|
|
48
|
+
gradientCenterColor?: string;
|
|
49
|
+
onPress?: Function;
|
|
50
|
+
onLabelPress?: Function;
|
|
39
51
|
};
|
|
40
52
|
type itemType = {
|
|
41
53
|
value: number;
|
|
42
54
|
shiftX?: number;
|
|
43
55
|
shiftY?: number;
|
|
44
56
|
color?: string;
|
|
57
|
+
gradientCenterColor?: string;
|
|
45
58
|
text?: string;
|
|
46
59
|
textColor?: string;
|
|
47
60
|
textSize?: number;
|
|
@@ -53,6 +66,8 @@ type itemType = {
|
|
|
53
66
|
shiftTextX?: number;
|
|
54
67
|
shiftTextY?: number;
|
|
55
68
|
labelPosition?: 'onBorder' | 'outward' | 'inward' | 'mid';
|
|
69
|
+
onPress?: Function;
|
|
70
|
+
onLabelPress?: Function;
|
|
56
71
|
};
|
|
57
72
|
|
|
58
73
|
export const PieChart = (props: propTypes) => {
|
|
@@ -102,6 +117,8 @@ export const PieChart = (props: propTypes) => {
|
|
|
102
117
|
const showTextBackground = props.showTextBackground || false;
|
|
103
118
|
const textBackgroundColor = props.textBackgroundColor || 'white';
|
|
104
119
|
const showValuesAsLabels = props.showValuesAsLabels || false;
|
|
120
|
+
const showGradient = props.showGradient || false;
|
|
121
|
+
const gradientCenterColor = props.gradientCenterColor || 'white';
|
|
105
122
|
|
|
106
123
|
const colors = [
|
|
107
124
|
'cyan',
|
|
@@ -186,6 +203,32 @@ export const PieChart = (props: propTypes) => {
|
|
|
186
203
|
}`}
|
|
187
204
|
height={radius * 2 + strokeWidth}
|
|
188
205
|
width={radius * 2 + strokeWidth}>
|
|
206
|
+
<Defs>
|
|
207
|
+
{data.map((item, index) => {
|
|
208
|
+
return (
|
|
209
|
+
<RadialGradient
|
|
210
|
+
id={'grad' + index}
|
|
211
|
+
cx="50%"
|
|
212
|
+
cy="50%"
|
|
213
|
+
rx="50%"
|
|
214
|
+
ry="50%"
|
|
215
|
+
fx="50%"
|
|
216
|
+
fy="50%"
|
|
217
|
+
gradientUnits="userSpaceOnUse">
|
|
218
|
+
<Stop
|
|
219
|
+
offset="0%"
|
|
220
|
+
stopColor={item.gradientCenterColor || gradientCenterColor}
|
|
221
|
+
stopOpacity="1"
|
|
222
|
+
/>
|
|
223
|
+
<Stop
|
|
224
|
+
offset="100%"
|
|
225
|
+
stopColor={item.color || colors[index % 9]}
|
|
226
|
+
stopOpacity="1"
|
|
227
|
+
/>
|
|
228
|
+
</RadialGradient>
|
|
229
|
+
);
|
|
230
|
+
})}
|
|
231
|
+
</Defs>
|
|
189
232
|
{data.map((item, index) => {
|
|
190
233
|
console.log('index', index);
|
|
191
234
|
let nextItem;
|
|
@@ -219,14 +262,24 @@ export const PieChart = (props: propTypes) => {
|
|
|
219
262
|
}`}
|
|
220
263
|
stroke={strokeColor}
|
|
221
264
|
strokeWidth={strokeWidth}
|
|
222
|
-
fill={
|
|
265
|
+
fill={
|
|
266
|
+
showGradient
|
|
267
|
+
? `url(#grad${index})`
|
|
268
|
+
: item.color || colors[index % 9]
|
|
269
|
+
}
|
|
270
|
+
onPress={() => {
|
|
271
|
+
item.onPress
|
|
272
|
+
? item.onPress
|
|
273
|
+
: props.onPress
|
|
274
|
+
? props.onPress(item, index)
|
|
275
|
+
: null;
|
|
276
|
+
}}
|
|
223
277
|
/>
|
|
224
278
|
);
|
|
225
279
|
})}
|
|
226
280
|
|
|
227
281
|
{showText &&
|
|
228
282
|
data.map((item, index) => {
|
|
229
|
-
|
|
230
283
|
let mx = cx * (1 + Math.sin(2 * pi * mData[index] + initialAngle));
|
|
231
284
|
let my = cy * (1 - Math.cos(2 * pi * mData[index] + initialAngle));
|
|
232
285
|
|
|
@@ -270,6 +323,17 @@ export const PieChart = (props: propTypes) => {
|
|
|
270
323
|
textSize
|
|
271
324
|
}
|
|
272
325
|
fill={item.textBackgroundColor || textBackgroundColor}
|
|
326
|
+
onPress={() => {
|
|
327
|
+
item.onLabelPress
|
|
328
|
+
? item.onLabelPress()
|
|
329
|
+
: props.onLabelPress
|
|
330
|
+
? props.onLabelPress(item, index)
|
|
331
|
+
: item.onPress
|
|
332
|
+
? item.onPress()
|
|
333
|
+
: props.onPress
|
|
334
|
+
? props.onPress(item, index)
|
|
335
|
+
: null;
|
|
336
|
+
}}
|
|
273
337
|
/>
|
|
274
338
|
)}
|
|
275
339
|
<SvgText
|
|
@@ -283,7 +347,18 @@ export const PieChart = (props: propTypes) => {
|
|
|
283
347
|
(item.shiftTextX || 0) -
|
|
284
348
|
(item.textSize || textSize) / 1.8
|
|
285
349
|
}
|
|
286
|
-
y={y + (item.shiftTextY || 0)}
|
|
350
|
+
y={y + (item.shiftTextY || 0)}
|
|
351
|
+
onPress={() => {
|
|
352
|
+
item.onLabelPress
|
|
353
|
+
? item.onLabelPress()
|
|
354
|
+
: props.onLabelPress
|
|
355
|
+
? props.onLabelPress(item, index)
|
|
356
|
+
: item.onPress
|
|
357
|
+
? item.onPress()
|
|
358
|
+
: props.onPress
|
|
359
|
+
? props.onPress(item, index)
|
|
360
|
+
: null;
|
|
361
|
+
}}>
|
|
287
362
|
{item.text || (showValuesAsLabels ? item.value + '' : '')}
|
|
288
363
|
</SvgText>
|
|
289
364
|
</>
|
package/src/todos.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
## Feature requests
|
|
2
2
|
|
|
3
3
|
1. OnPress function on Pie Chart https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/111
|
|
4
|
-
2. Change startingPoint default props on PieChart https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/132
|
|
5
4
|
|
|
6
5
|
## To-dos in documentation-
|
|
7
6
|
|
|
@@ -14,9 +13,10 @@
|
|
|
14
13
|
7. Prepare a doc for Bar chart with barMarginBottom
|
|
15
14
|
8. Prepare a doc for reference lines
|
|
16
15
|
9. Prepare a doc for labelsPosition in Pie and Donut charts
|
|
16
|
+
8. Prepare a doc for adjustToWidth in Line and Area charts
|
|
17
|
+
9. Prepare a doc for xAxisLabelTexts and xAxisLabelTextStyle in Bar, Line And Area Charts
|
|
17
18
|
|
|
18
19
|
## Architecture Enhancement
|
|
19
20
|
|
|
20
|
-
1.
|
|
21
|
-
2.
|
|
22
|
-
3. Write tests
|
|
21
|
+
1. Make it compliant with React js
|
|
22
|
+
2. Write tests
|