react-native-gifted-charts 1.2.17 → 1.2.18
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/LICENSE +21 -0
- package/package.json +1 -1
- package/src/LineChart/index.tsx +1 -1
- package/src/PieChart/index.tsx +80 -42
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Abhinandan Kushwaha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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.18",
|
|
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/LineChart/index.tsx
CHANGED
package/src/PieChart/index.tsx
CHANGED
|
@@ -210,6 +210,7 @@ export const PieChart = (props: propTypes) => {
|
|
|
210
210
|
{data.map((item, index) => {
|
|
211
211
|
return (
|
|
212
212
|
<RadialGradient
|
|
213
|
+
key={index + ''}
|
|
213
214
|
id={'grad' + index}
|
|
214
215
|
cx="50%"
|
|
215
216
|
cy="50%"
|
|
@@ -232,54 +233,75 @@ export const PieChart = (props: propTypes) => {
|
|
|
232
233
|
);
|
|
233
234
|
})}
|
|
234
235
|
</Defs>
|
|
235
|
-
{data.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
cx * (1 + Math.sin(2 * pi * pData[index] + initialAngle)) +
|
|
242
|
-
(item.shiftX || 0);
|
|
243
|
-
let sy =
|
|
244
|
-
cy * (1 - Math.cos(2 * pi * pData[index] + initialAngle)) +
|
|
245
|
-
(item.shiftY || 0);
|
|
246
|
-
let ax =
|
|
247
|
-
cx * (1 + Math.sin(2 * pi * nextItem + initialAngle)) +
|
|
248
|
-
(item.shiftX || 0);
|
|
249
|
-
let ay =
|
|
250
|
-
cy * (1 - Math.cos(2 * pi * nextItem + initialAngle)) +
|
|
251
|
-
(item.shiftY || 0);
|
|
252
|
-
|
|
253
|
-
// console.log('sx', sx);
|
|
254
|
-
// console.log('sy', sy);
|
|
255
|
-
// console.log('ax', ax);
|
|
256
|
-
// console.log('ay', ay);
|
|
257
|
-
return (
|
|
258
|
-
<Path
|
|
259
|
-
d={`M ${cx + (item.shiftX || 0)} ${
|
|
260
|
-
cy + (item.shiftY || 0)
|
|
261
|
-
} L ${sx} ${sy} A ${radius} ${radius} 0 ${
|
|
262
|
-
semiCircle ? 0 : data[index].value > total / 2 ? 1 : 0
|
|
263
|
-
} 1 ${ax} ${ay} L ${cx + (item.shiftX || 0)} ${
|
|
264
|
-
cy + (item.shiftY || 0)
|
|
265
|
-
}`}
|
|
266
|
-
stroke={strokeColor}
|
|
267
|
-
strokeWidth={strokeWidth}
|
|
236
|
+
{data.length === 1 ? (
|
|
237
|
+
<>
|
|
238
|
+
<Circle
|
|
239
|
+
cx={cx}
|
|
240
|
+
cy={cy}
|
|
241
|
+
r={radius}
|
|
268
242
|
fill={
|
|
269
|
-
showGradient
|
|
270
|
-
? `url(#grad${index})`
|
|
271
|
-
: item.color || colors[index % 9]
|
|
243
|
+
showGradient ? `url(#grad${0})` : data[0].color || colors[0 % 9]
|
|
272
244
|
}
|
|
273
245
|
onPress={() => {
|
|
274
|
-
|
|
275
|
-
?
|
|
246
|
+
data[0].onPress
|
|
247
|
+
? data[0].onPress
|
|
276
248
|
: props.onPress
|
|
277
|
-
? props.onPress(
|
|
249
|
+
? props.onPress(data[0], 0)
|
|
278
250
|
: null;
|
|
279
251
|
}}
|
|
280
252
|
/>
|
|
281
|
-
|
|
282
|
-
|
|
253
|
+
</>
|
|
254
|
+
) : (
|
|
255
|
+
data.map((item, index) => {
|
|
256
|
+
// console.log('index', index);
|
|
257
|
+
let nextItem;
|
|
258
|
+
if (index === pData.length - 1) nextItem = pData[0];
|
|
259
|
+
else nextItem = pData[index + 1];
|
|
260
|
+
let sx =
|
|
261
|
+
cx * (1 + Math.sin(2 * pi * pData[index] + initialAngle)) +
|
|
262
|
+
(item.shiftX || 0);
|
|
263
|
+
let sy =
|
|
264
|
+
cy * (1 - Math.cos(2 * pi * pData[index] + initialAngle)) +
|
|
265
|
+
(item.shiftY || 0);
|
|
266
|
+
let ax =
|
|
267
|
+
cx * (1 + Math.sin(2 * pi * nextItem + initialAngle)) +
|
|
268
|
+
(item.shiftX || 0);
|
|
269
|
+
let ay =
|
|
270
|
+
cy * (1 - Math.cos(2 * pi * nextItem + initialAngle)) +
|
|
271
|
+
(item.shiftY || 0);
|
|
272
|
+
|
|
273
|
+
// console.log('sx', sx);
|
|
274
|
+
// console.log('sy', sy);
|
|
275
|
+
// console.log('ax', ax);
|
|
276
|
+
// console.log('ay', ay);
|
|
277
|
+
return (
|
|
278
|
+
<Path
|
|
279
|
+
key={index + 'a'}
|
|
280
|
+
d={`M ${cx + (item.shiftX || 0)} ${
|
|
281
|
+
cy + (item.shiftY || 0)
|
|
282
|
+
} L ${sx} ${sy} A ${radius} ${radius} 0 ${
|
|
283
|
+
semiCircle ? 0 : data[index].value > total / 2 ? 1 : 0
|
|
284
|
+
} 1 ${ax} ${ay} L ${cx + (item.shiftX || 0)} ${
|
|
285
|
+
cy + (item.shiftY || 0)
|
|
286
|
+
}`}
|
|
287
|
+
stroke={strokeColor}
|
|
288
|
+
strokeWidth={strokeWidth}
|
|
289
|
+
fill={
|
|
290
|
+
showGradient
|
|
291
|
+
? `url(#grad${index})`
|
|
292
|
+
: item.color || colors[index % 9]
|
|
293
|
+
}
|
|
294
|
+
onPress={() => {
|
|
295
|
+
item.onPress
|
|
296
|
+
? item.onPress
|
|
297
|
+
: props.onPress
|
|
298
|
+
? props.onPress(item, index)
|
|
299
|
+
: null;
|
|
300
|
+
}}
|
|
301
|
+
/>
|
|
302
|
+
);
|
|
303
|
+
})
|
|
304
|
+
)}
|
|
283
305
|
|
|
284
306
|
{showText &&
|
|
285
307
|
data.map((item, index) => {
|
|
@@ -308,6 +330,21 @@ export const PieChart = (props: propTypes) => {
|
|
|
308
330
|
x += item.shiftX || 0;
|
|
309
331
|
y += item.shiftY || 0;
|
|
310
332
|
|
|
333
|
+
if (data.length === 1) {
|
|
334
|
+
if (donut) {
|
|
335
|
+
y =
|
|
336
|
+
(radius -
|
|
337
|
+
innerRadius +
|
|
338
|
+
(item.textBackgroundRadius ||
|
|
339
|
+
props.textBackgroundRadius ||
|
|
340
|
+
item.textSize ||
|
|
341
|
+
textSize)) /
|
|
342
|
+
2;
|
|
343
|
+
} else {
|
|
344
|
+
y = cy;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
311
348
|
// console.log('sx', sx);
|
|
312
349
|
// console.log('sy', sy);
|
|
313
350
|
// console.log('ax', ax);
|
|
@@ -317,6 +354,7 @@ export const PieChart = (props: propTypes) => {
|
|
|
317
354
|
{/* <Line x1={mx} x2={cx} y1={my} y2={cy} stroke="black" /> */}
|
|
318
355
|
{showTextBackground && (
|
|
319
356
|
<Circle
|
|
357
|
+
key={index + 'b'}
|
|
320
358
|
cx={x}
|
|
321
359
|
cy={y - (item.textSize || textSize) / 4}
|
|
322
360
|
r={
|
|
@@ -340,7 +378,7 @@ export const PieChart = (props: propTypes) => {
|
|
|
340
378
|
/>
|
|
341
379
|
)}
|
|
342
380
|
<SvgText
|
|
343
|
-
fill={item.textColor || textColor || colors[(index +
|
|
381
|
+
fill={item.textColor || textColor || colors[(index + 2) % 9]}
|
|
344
382
|
fontSize={item.textSize || textSize}
|
|
345
383
|
fontFamily={item.font || props.font}
|
|
346
384
|
fontWeight={item.fontWeight || props.fontWeight}
|