@@ -42,20 +42,20 @@ export function makeDonut(item, cx, cy, rx, ry, piProportion = 1.99999, piMult =
4242 degrees ,
4343 piMult ,
4444 true
45- )
45+ ) ;
4646
4747 ratios . push ( {
4848 arcSlice : `${ path } L ${ inner . startX } ${ inner . startY } ${ inner . path } L ${ startX } ${ startY } ` ,
49- cx,
50- cy,
49+ cx : checkNaN ( cx ) ,
50+ cy : checkNaN ( cy ) ,
5151 ...series [ i ] ,
52- proportion,
53- ratio : ratio ,
54- path,
55- startX,
56- startY,
57- endX,
58- endY,
52+ proportion : checkNaN ( proportion ) ,
53+ ratio : checkNaN ( ratio ) ,
54+ path : path . replaceAll ( 'NaN' , '0' ) ,
55+ startX : checkNaN ( startX ) ,
56+ startY : checkNaN ( startY ) ,
57+ endX : checkNaN ( endX ) ,
58+ endY : checkNaN ( endY ) ,
5959 center : createArc (
6060 [ cx , cy ] ,
6161 [ rx * arcAmpl , ry * arcAmpl ] ,
@@ -105,18 +105,18 @@ export function createArc([cx, cy], [rx, ry], [position, ratio], phi, degrees =
105105 const fA = ratio > Math . PI ? 1 : 0 ;
106106 const fS = ratio > 0 ? reverse ? 0 : 1 : reverse ? 1 : 0 ;
107107 return {
108- startX : reverse ? eX : sX ,
109- startY : reverse ? eY : sY ,
110- endX : reverse ? sX : eX ,
111- endY : reverse ? sY : eY ,
112- path : `M${ reverse ? eX : sX } ${ reverse ? eY : sY } A ${ [
113- rx ,
114- ry ,
115- ( phi / ( piMult * Math . PI ) ) * degrees ,
116- fA ,
117- fS ,
118- reverse ? sX : eX ,
119- reverse ? sY : eY ,
108+ startX : reverse ? checkNaN ( eX ) : checkNaN ( sX ) ,
109+ startY : reverse ? checkNaN ( eY ) : checkNaN ( sY ) ,
110+ endX : reverse ? checkNaN ( sX ) : checkNaN ( eX ) ,
111+ endY : reverse ? checkNaN ( sY ) : checkNaN ( eY ) ,
112+ path : `M${ reverse ? checkNaN ( eX ) : checkNaN ( sX ) } ${ reverse ? checkNaN ( eY ) : checkNaN ( sY ) } A ${ [
113+ checkNaN ( rx ) ,
114+ checkNaN ( ry ) ,
115+ checkNaN ( ( phi / ( piMult * Math . PI ) ) * degrees ) ,
116+ checkNaN ( fA ) ,
117+ checkNaN ( fS ) ,
118+ reverse ? checkNaN ( sX ) : checkNaN ( eX ) ,
119+ reverse ? checkNaN ( sY ) : checkNaN ( eY ) ,
120120 ] . join ( " " ) } `,
121121 } ;
122122}
@@ -859,9 +859,11 @@ export function sumByAttribute(arr, attr) {
859859}
860860
861861export function makePath ( plots , closed = true , bare = false ) {
862+ if ( ! plots . length ) return "M0,0" ;
862863 let path = "" ;
863864 plots . forEach ( plot => {
864- path += `${ plot . x } ,${ plot . y } `
865+ if ( ! plot ) return '' ;
866+ path += `${ plot . x } ,${ plot . y } ` ;
865867 } )
866868 if ( bare ) {
867869 return path . trim ( ) ;
@@ -1726,7 +1728,7 @@ export function sumSeries(source) {
17261728export function checkFormatter ( func , { value, config } ) {
17271729 let isValid = false ;
17281730 let formattedValue = value ;
1729-
1731+
17301732 if ( typeof func === 'function' ) {
17311733 try {
17321734 // Ensure that the function is called with an object containing `value` and `config`
@@ -1764,6 +1766,37 @@ export function hasDeepProperty(obj, path) {
17641766 } ) ;
17651767}
17661768
1769+ export function sanitizeArray ( arr , keys = [ ] ) {
1770+
1771+ function sanitizeValue ( value ) {
1772+ if ( [ NaN , undefined , Infinity , - Infinity , null ] . includes ( value ) ) {
1773+ console . warn ( `A non processable value was detected : ${ value } ` )
1774+ }
1775+ return ( typeof value === 'number' && isFinite ( value ) ) ? value : 0 ;
1776+ }
1777+
1778+ function sanitize ( data ) {
1779+ if ( Array . isArray ( data ) ) {
1780+ return data . map ( item => sanitize ( item ) ) ;
1781+ } else if ( typeof data === 'object' && data !== null ) {
1782+
1783+ let sanitizedObject = { ...data } ;
1784+ keys . forEach ( key => {
1785+ if ( sanitizedObject . hasOwnProperty ( key ) && Array . isArray ( sanitizedObject [ key ] ) ) {
1786+ sanitizedObject [ key ] = sanitize ( sanitizedObject [ key ] ) ;
1787+ }
1788+ } ) ;
1789+ return Object . fromEntries (
1790+ Object . entries ( sanitizedObject ) . map ( ( [ k , v ] ) => [ k , sanitize ( v ) ] )
1791+ ) ;
1792+ } else {
1793+ return sanitizeValue ( data ) ;
1794+ }
1795+ }
1796+
1797+ return sanitize ( arr ) ;
1798+ }
1799+
17671800const lib = {
17681801 XMLNS ,
17691802 abbreviate,
@@ -1821,6 +1854,7 @@ const lib = {
18211854 opacity,
18221855 palette,
18231856 rotateMatrix,
1857+ sanitizeArray,
18241858 shiftHue,
18251859 sumByAttribute,
18261860 sumSeries,
0 commit comments