d3 / d3-selection

Transform the DOM by selecting elements and joining to data.

Home Page:https://d3js.org/d3-selection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: path attribute d expected number, on value with scientific notation

gg2 opened this issue · comments

Using d3 line generator, I get the following error:
"Error: attribute d: Expected number, "….96509819470895,7.69518687729657…"." at attr.js:30
(In Chrome 108.0.5359.125 (64-bit) on Windows 10)

Given the segment of numbers in the error, I believe it is erring on a number written using scientific notation.
The value (v) being given to setAttribute is:
M44.96509819470895,7.695186877296576e+39ZM114.6758646299928,357.4202389793762L149.53124784763475,357.5890210857933L161.14970892018204,363.40055146814456L172.76816999272936,363.3253476704727L184.38663106527667,363.46153846153845L196.00509213782397,363.4294973619078L207.62355321037126,363.35985288047874L219.24201428291857,363.4566458456325L230.8604753554659,363.1262822581218L242.4789364280132,363.2189283133634L254.0973975005605,361.77599394798705L265.7158585731078,363.4164076923922L277.3343196456551,363.1839223219395L288.9527807182024,361.08779231202016L300.57124179074975,363.454029511246L312.18970286329704,363.3477536532466L323.8081639358444,363.2434014324654L335.4266250083917,363.34693527126296L347.045086080939,363.4407872948834L358.6635471534863,363.42518572694445L370.28200822603367,363.4482050113274L381.9004692985809,363.3668617475122L393.51893037112825,363.4388459587585L405.1373914436755,363.44576464334716L416.75585251622283,363.41260474686874L428.3743135887702,363.35990324788156L439.9927746613174,363.3893245494086L451.61123573386476,363.44276302573934L463.22969680641205,363.44365245162106L474.8481578789594,363.39759590735093L486.4666189515067,362.29879748450657L498.085080024054,363.43124531806507L509.7035410966013,363.43730365449954L521.3220021691486,363.4089695927128L532.940463241696,363.435532762412L544.5589243142432,363.42517081400763L556.1773853867905,363.3717215853661L567.7958464593379,363.4345132440674L579.4143075318851,363.3794841572261L591.0327686044326,363.42044889166L602.6512296769797,363.45315072437006L614.2696907495272,363.2421562239008L649.125073967169,363.2226073665398L660.7435350397164,363.3834635152942L672.3619961122636,353.69727934423537L683.980457184811,363.45467844769246L695.5989182573582,36.538461538461554L707.2173793299056,363.33080949109984L718.8358404024528,355.139509352443L730.4543014750002,363.46153846153845L742.0727625475474,363.4615384615384L753.6912236200948,363.46152082370696L765.3096846926421,363.46097729235953L1334.6142772474602,363.34639719250697L1346.2327383200075,363.4575210417399L1357.8511993925547,363.4163783663935L1369.4696604651024,363.3664593081651L1381.0881215376496,363.41478307538694L1392.7065826101966,363.37956215105265L1404.325043682744,363.4054382126023L1415.9435047552915,363.28794135938546L1427.5619658278388,361.88120230131017L1439.180426900386,358.9807771045646L1450.7988879729332,344.9917728121869L1462.4173490454807,355.5572958477909L1474.035810118028,363.2851308623104L1485.6542711905752,363.43355021826017L1497.2727322631226,362.5546462416131L1508.8911933356699,361.88664392698826L1520.509654408217,363.4612006302512L1532.1281154807646,363.38733326077715L1543.746576553312,363.2652128039558L1555.3650376258593,363.35631259259617L1566.9834986984063,363.21984906974245L1578.6019597709537,363.37465325213583L1590.2204208435012,361.6386132678541L1601.8388819160484,362.12875212070566L1613.4573429885957,356.0904949709682L1636.6942651336904,363.21012899413455L1648.3127262062376,363.4389057288096L1659.9311872787848,362.87387018814246L1671.5496483513323,363.45670358077587L1683.1681094238795,363.2649897530757L1694.7865704964267,363.3942447388349L1706.4050315689742,363.3479295425888L1718.0234926415214,363.3646457750757L1729.641953714069,363.3313997168136L1741.260414786616,363.0688529949147L1752.8788758591634,362.5634463873019L1764.4973369317106,363.3855755137353L1776.1157980042578,363.41172279411796L1787.734259076805,363.3935218596321L1799.3527201493525,363.43523897589006L1810.9711812219,363.3433531805023L1822.5896422944472,363.32668388294326L1834.2081033669945,363.30827785975146L1845.826564439542,363.41619403249666L1857.4450255120894,359.38658195660514L1869.0634865846366,363.32947526479916L1880.6819476571839,363.33480430530227L1892.3004087297309,363.1264783957331L1903.9188698022783,363.4211518691738L1915.5373308748256,363.0452574030037L1927.155791947373,363.11858375690406L1938.7742530199203,363.42375387506064L1950.3927140924677,363.42447989014585L1962.011175165015,363.38524626274994L1973.6296362375624,363.4614878772173

Notes:

  • The first M command is the only oddity I can find (because it contains scientific notation), and matches the segment given in the error. That first value in the path is supposed to be an extremely large number; i.e. it is intentional that the path display it.
  • It looks like scientific notation is allowed in SVG -- as of 2019, at least.
  • I was troubleshooting this because one of two lines was not being rendered. And I noted the error in the console. So, it would make sense this error caused line rendering to fail.

If any further info is desired, please let me know.

You can reproduce this issue by typing pure SVG commands (in that sense it's not specific to d3.line). The following code reproduces it with d3.line, but I don't think if there is a way such a big number could be formatted in a way that pleases Chrome?
<svg><path d="${d3.line()([[1, 7e39]])}">
Not sure why you need these galactic dimensions :)

OK. Thank you for the response. Certainly the numbers were aberrations in data. ☺️ But who knows what numbers might be needed for whatever reasons. So if it needed to be handled and could ... never hurts. Thank you for looking it over.