How to provide a Leaflet GeoJSON feature collection to turf.centroid? - leaflet
I would like to find the centroid of a group of polygons, where each polygon represents a farm field. Currently, my code looks like this:
$('#field-group').multiselect({
nonSelectedText: 'Choose Field(s):',
onChange: function(option, checked, select) {
var fieldList=[];
$('option:selected', $('#field-group')).each(function() {
// fieldList.push({value:$(this).val(),text:$(this).text()});
fieldList.push($(this).val());
});
var queryString = $.param({field_name__exact:fieldList}, true);
var centroid;
fields = new L.GeoJSON.AJAX("{% url 'fields' %}?"+queryString, {
style: { color: 'blue', fillOpacity: 0.0},
onEachFeature: function (feature, layer) {
//layer.bindPopup(feature.properties.description.toString());
centroid = turf.centroid(feature);
var lon = centroid.geometry.coordinates[0];
var lat = centroid.geometry.coordinates[1];
map.setView([lat, lon], 14)
}
}).addTo(map);
}
});
The map pans to the centroid of last field added, which is not what I want. However, I can't seem to get it to pan to the centroid of the Feature Collection. I have tried using this:
$('#field-group').multiselect({
nonSelectedText: 'Choose Field(s):',
onChange: function(option, checked, select) {
var fieldList=[];
$('option:selected', $('#field-group')).each(function() {
// fieldList.push({value:$(this).val(),text:$(this).text()});
fieldList.push($(this).val());
});
var queryString = $.param({field_name__exact:fieldList}, true);
var centroid;
fields = new L.GeoJSON.AJAX("{% url 'fields' %}?"+queryString, {
style: { color: 'blue', fillOpacity: 0.0},
onEachFeature: function (feature, layer) {
//layer.bindPopup(feature.properties.description.toString());
}
}).addTo(map);
var test = fields.toGetJSON() // make a Feature Collection
centroid = turf.centroid(test); // takes a Feature Collection
var lon = centroid.geometry.coordinates[0];
var lat = centroid.geometry.coordinates[1];
map.setView([lat, lon], 14)
}
});
But with this code, I get a 'Uncaught Error: coordinates must contain numbers'. I don't know what I'm doing wrong. Can someone advise please?
Here is the GeoJSON feature collection I would like to get the centroid of:
{"type": "FeatureCollection", "crs": {"type": "name", "properties": {"name": "EPSG:4326"}}, "features": [{"type": "Feature", "properties": {"client_nam": "MSFF", "farm_name": "Lauderdale", "field_name": "064", "polygontyp": 0, "shape_leng": 6403.54792475, "shape_area": 2500990.45035, "area_ac": 618.008199278, "farm": 0, "grower": 1, "pk": "2"}, "geometry": {"type": "MultiPolygon", "coordinates": [[[[-89.89392924524434, 35.69692900010964], [-89.89397896493877, 35.69693891373261], [-89.89399774773102, 35.69694972946372], [-89.89406293561315, 35.696974063403445], [-89.89413475280982, 35.69698578042825], [-89.89513577562231, 35.69707680953917], [-89.89515787422303, 35.69707861278143], [-89.89561750436316, 35.69710655119105], [-89.89564402249842, 35.69710835519184], [-89.89579207576386, 35.69712637962693], [-89.89683398047805, 35.69721831004002], [-89.89686712670081, 35.69721831021136], [-89.89709252256554, 35.697246250628424], [-89.8971245633863, 35.697247151586424], [-89.8973676380404, 35.697264275799874], [-89.89740520383717, 35.69726607824239], [-89.89792891817353, 35.69731384653144], [-89.89795101564596, 35.69731384584378], [-89.89899291882548, 35.697400368743054], [-89.89901501694698, 35.697401270013415], [-89.89909346354239, 35.69741659245474], [-89.89916749031224, 35.69741839419948], [-89.89928350312223, 35.6974310129386], [-89.8994691231003, 35.69744362987771], [-89.89949453575302, 35.697442728829], [-89.89985583120854, 35.697479680993375], [-89.90027679129888, 35.69751483098848], [-89.90191533231281, 35.697651826118836], [-89.90193963914663, 35.69765272673085], [-89.90422674478353, 35.69785371257284], [-89.90425105193212, 35.69785641614321], [-89.90649727673167, 35.69804388296781], [-89.9065392630568, 35.698042079694346], [-89.90702651593764, 35.69807182205378], [-89.90705082254311, 35.698073624700754], [-89.90739886149775, 35.69810607067188], [-89.90742427341385, 35.69810697229438], [-89.90794798698916, 35.69814662845909], [-89.90845954718644, 35.69817637118887], [-89.90850153345474, 35.69817727192989], [-89.90887387745295, 35.69818898792924], [-89.90890039505622, 35.6981880870011], [-89.90891807295093, 35.69820160653022], [-89.9089700030801, 35.69824937398365], [-89.90895563914198, 35.69827370860559], [-89.90894238118688, 35.698378257112324], [-89.90894238083057, 35.69839718371234], [-89.90893354203203, 35.69844044467485], [-89.90891144476537, 35.69861529394119], [-89.90886503945832, 35.69892262963565], [-89.9087655989153, 35.69959858878641], [-89.90876338976926, 35.699622924129216], [-89.9085711413809, 35.70084776272312], [-89.90856782604114, 35.70087480067237], [-89.9080419019526, 35.70429605630674], [-89.90803748178027, 35.7043248982493], [-89.90795461558803, 35.70478364910501], [-89.90789384742043, 35.705188323173424], [-89.90762757091309, 35.70710534475526], [-89.90762315211987, 35.7071278768855], [-89.9075844808395, 35.70730362587183], [-89.90758779569457, 35.707324355947996], [-89.90758448133349, 35.70739375422304], [-89.9075634882039, 35.70754607097185], [-89.90746073472926, 35.70823464732061], [-89.9072905826364, 35.70928193439962], [-89.9072894773355, 35.70930266318926], [-89.90715136819534, 35.710229179069685], [-89.90714915672828, 35.71024990846188], [-89.90647959977048, 35.71453368916356], [-89.90645860599905, 35.71454360310321], [-89.90640336149664, 35.71454360271376], [-89.90632712584683, 35.714532787955854], [-89.90593489302691, 35.7145039465292], [-89.90542664711816, 35.71447510585435], [-89.90435601582725, 35.71441021411642], [-89.90021270870528, 35.71415244792596], [-89.90016851292069, 35.714148842590795], [-89.89414138257374, 35.71376399734617], [-89.89411597010145, 35.71376309483678], [-89.89221004898428, 35.713653139423826], [-89.89217690311492, 35.713648632668345], [-89.89169075409323, 35.71360807501945], [-89.89167639026059, 35.71359185240414], [-89.89167639091588, 35.71355399909158], [-89.89168743993552, 35.713508033647635], [-89.89172832058478, 35.7132592800101], [-89.8917305295669, 35.713233143263324], [-89.8917614668002, 35.71295915435798], [-89.8918940526648, 35.711935301224926], [-89.89221225899834, 35.709628927164225], [-89.89220010485218, 35.70961090208179], [-89.8923072780561, 35.708815972655245], [-89.89238351477313, 35.70817606467339], [-89.89238351461397, 35.70814632278711], [-89.89241334681158, 35.7079858949243], [-89.89246306712592, 35.7076434090494], [-89.89246306734469, 35.70762358021529], [-89.89250615691903, 35.70744602838808], [-89.89250615777065, 35.70742169409251], [-89.89252162582412, 35.7072783906253], [-89.89252825393596, 35.70725675935841], [-89.89256250652191, 35.707026032463844], [-89.89256361186202, 35.70699719139074], [-89.89259565271125, 35.70670878235815], [-89.89266084029182, 35.706156298066496], [-89.89266194606505, 35.706135568406005], [-89.89277574909512, 35.70528025432009], [-89.89277795814698, 35.705260425525275], [-89.89343536294747, 35.700285363804724], [-89.89343757236203, 35.70026643715484], [-89.89388284038843, 35.696993891451505], [-89.89388615396734, 35.69697406308933], [-89.89390493749985, 35.69693711149333], [-89.89392924524434, 35.69692900010964]]]]}}, {"type": "Feature", "properties": {"client_nam": "MSFF", "farm_name": "Lauderdale", "field_name": "053", "polygontyp": 0, "shape_leng": 10388.1939987, "shape_area": 2702155.83411, "area_ac": 667.729728166, "farm": 0, "grower": 1, "pk": "1"}, "geometry": {"type": "MultiPolygon", "coordinates": [[[[-89.86060511911957, 35.686488718320284], [-89.8606946589609, 35.6865061205794], [-89.86077092887423, 35.686534997107344], [-89.86087390624193, 35.68664136043166], [-89.86102641730923, 35.68679397718338], [-89.86111563659816, 35.68686107158934], [-89.8612449626168, 35.68687261691992], [-89.86134725883414, 35.686866848883355], [-89.86146301554896, 35.686868199721594], [-89.86162415600155, 35.68687257522511], [-89.86178529752841, 35.686876949584985], [-89.86195678568744, 35.68688928641177], [-89.86209560024024, 35.68690240131702], [-89.86227860687073, 35.68695550607839], [-89.86241215506962, 35.68703236092858], [-89.86254155652192, 35.68713393996], [-89.86272166334875, 35.68724662450333], [-89.8629468636845, 35.68735413289169], [-89.86298551522484, 35.6873798899144], [-89.86309778566167, 35.68742441589675], [-89.8632101295819, 35.687470993135705], [-89.86347346959133, 35.687589904132544], [-89.86371240996301, 35.68772991664179], [-89.86378742280553, 35.687787642222624], [-89.86391519401468, 35.68791388505358], [-89.86396551336874, 35.68798451080842], [-89.86399743335353, 35.688033002094436], [-89.86402188652336, 35.68808372246544], [-89.8640685924546, 35.68812365373161], [-89.86412520526521, 35.68815924376366], [-89.86420739113244, 35.68820653811011], [-89.86418743525888, 35.688256082508744], [-89.86427064148921, 35.68828758193634], [-89.86437023451838, 35.68829916037972], [-89.86450380015556, 35.68830434990677], [-89.86469505641104, 35.68829700483276], [-89.86486922772414, 35.688290067268724], [-89.86505806410379, 35.68831068013206], [-89.86517202532495, 35.688341446382026], [-89.86525543262334, 35.68837852014156], [-89.86535350416558, 35.68844314540221], [-89.86547931338545, 35.6885182712439], [-89.8655983876962, 35.688596345949776], [-89.86564712438954, 35.68862029629761], [-89.86569224517979, 35.68863875205435], [-89.86574419973047, 35.688657044082575], [-89.86584429344377, 35.68868256024541], [-89.86601302768106, 35.68871481104317], [-89.86613674200389, 35.68873139398575], [-89.8662567394727, 35.688739694295286], [-89.86636960267423, 35.688739795221956], [-89.86649321615366, 35.68875358984033], [-89.8665897940502, 35.6887763997012], [-89.86666938459017, 35.68880240378432], [-89.86674645723576, 35.68885357742887], [-89.86681981308108, 35.68889647033742], [-89.86687558590815, 35.68892583138897], [-89.86695497702469, 35.68894626021764], [-89.86702803462599, 35.688980789032556], [-89.86712169355553, 35.68901761800925], [-89.8672890420594, 35.68907419396012], [-89.86737364640419, 35.68908591266296], [-89.8674644881373, 35.68908374713922], [-89.86757532002876, 35.689075610798945], [-89.86769683632293, 35.689083702201785], [-89.86775076611491, 35.689085163558424], [-89.8677984597358, 35.68910050994574], [-89.86784605387861, 35.68911310978824], [-89.8680155589152, 35.689144781461344], [-89.8681347914951, 35.68918314580819], [-89.86820940096827, 35.68919784933195], [-89.86832576682083, 35.68921490714187], [-89.86859116407138, 35.689232699074594], [-89.86898727174238, 35.68929193020028], [-89.86935081628141, 35.68938215571749], [-89.86954050809182, 35.68941334365991], [-89.86968606821152, 35.6894345939997], [-89.8697972938299, 35.68943743548149], [-89.86987121499494, 35.689432924730504], [-89.86995829771003, 35.68941985772478], [-89.87003172793251, 35.68940162312501], [-89.8701323669081, 35.68939098053155], [-89.87030366306867, 35.68937865181604], [-89.87051285300379, 35.689390142388305], [-89.87065158595384, 35.689408809187455], [-89.87089586942255, 35.68945213014719], [-89.87108069323645, 35.68945608888516], [-89.87126591699914, 35.68947119830231], [-89.87135877831247, 35.68948572193019], [-89.87147626070762, 35.68951918839368], [-89.8715831908285, 35.689544536499824], [-89.87173494355137, 35.68957997400866], [-89.87186177637118, 35.68958810728184], [-89.87201926297726, 35.68959271725387], [-89.8721765495315, 35.68959175109087], [-89.87239876115058, 35.68958923432663], [-89.87254609761568, 35.68959687634379], [-89.87282448361059, 35.68963486893609], [-89.87321833639378, 35.68974543417038], [-89.87403276179028, 35.68999828346813], [-89.87421970655774, 35.69001167799909], [-89.87440180920525, 35.69003141306212], [-89.87461213669195, 35.69005058867938], [-89.8747733537813, 35.6900790040906], [-89.87485698458303, 35.69009475231329], [-89.87495345485259, 35.690137623024874], [-89.87506172470056, 35.69017859743398], [-89.87515238336009, 35.69022483345893], [-89.87523926407296, 35.69027599957123], [-89.87542605448324, 35.69030057621788], [-89.8756556723272, 35.69036123691002], [-89.87585826429216, 35.69044029214132], [-89.87597350507605, 35.6905101408395], [-89.87603021724192, 35.6906023633716], [-89.87639217533429, 35.69065824493519], [-89.8765886672787, 35.69073260402028], [-89.8768280456112, 35.69084465854801], [-89.87708096826725, 35.69094832129559], [-89.877280132745, 35.69104197738382], [-89.87740450167269, 35.69109063092339], [-89.87764388883825, 35.69114782835269], [-89.87795778699251, 35.691187106985794], [-89.87826168898012, 35.69122339832955], [-89.87859220739821, 35.69128486532512], [-89.87885414915937, 35.69130925128496], [-89.87973389238896, 35.6914091989683], [-89.88010742133278, 35.69145672574608], [-89.88085698051509, 35.69156623540072], [-89.881567983484, 35.69168288100922], [-89.88218226943944, 35.69173616411603], [-89.8823475598165, 35.69176769816228], [-89.88264960431174, 35.69180724846502], [-89.8831265893698, 35.6918716474421], [-89.88369587013536, 35.69191769627419], [-89.8839266618043, 35.69195572592516], [-89.88408003861157, 35.6919859299263], [-89.88446304586341, 35.69202192189544], [-89.88497165016888, 35.69203069831448], [-89.88545479897394, 35.69210139233426], [-89.88595177983892, 35.692171754310614], [-89.88645050476903, 35.692235617439245], [-89.8869671900793, 35.6923038881254], [-89.88732956832847, 35.692371020095266], [-89.88812133698858, 35.69249883181376], [-89.88851312494694, 35.692558801774545], [-89.8886778382622, 35.69257420628703], [-89.8903451362773, 35.69284876897063], [-89.89097778041891, 35.69295134366992], [-89.89123850951746, 35.69299670591291], [-89.89173730478555, 35.69311701520721], [-89.89272246137278, 35.69334179285705], [-89.89335313993615, 35.6934992579868], [-89.89389087978094, 35.693602486786126], [-89.89406193156724, 35.69362902605112], [-89.8942591378404, 35.693667843707864], [-89.89430186065628, 35.693700697114416], [-89.8943086044927, 35.69372312247514], [-89.89430412258174, 35.69375420519145], [-89.89430724750487, 35.69384062222175], [-89.89431135513112, 35.69390859904202], [-89.89428638104589, 35.694209409603864], [-89.8943033808118, 35.69434441370987], [-89.89430246620124, 35.694483189007734], [-89.89421406168962, 35.69530409526072], [-89.89419310338371, 35.69566543308508], [-89.89416706885885, 35.69601744052072], [-89.89414327458262, 35.69669901199647], [-89.89413932864902, 35.69675396366155], [-89.89411137475365, 35.69684184412398], [-89.8940889651422, 35.69688423384472], [-89.89404544665035, 35.69691039129965], [-89.89367552318956, 35.69689096953977], [-89.89289266115796, 35.69684687897401], [-89.89285110359684, 35.69684626526559], [-89.89272422072922, 35.696838023213154], [-89.89263500169629, 35.69683210174333], [-89.89214281458212, 35.69678585483037], [-89.89050629764746, 35.69665417363725], [-89.88803060864572, 35.69645227256077], [-89.88640026308855, 35.6963268408669], [-89.88606902191083, 35.69630090727561], [-89.88605373743238, 35.69648036405855], [-89.88598965775927, 35.6970391403147], [-89.88588405035371, 35.69773459679528], [-89.88581753065476, 35.69821971641829], [-89.88571466436643, 35.69899125272329], [-89.8856338790951, 35.69959854665558], [-89.88556529887127, 35.699897159430535], [-89.88550467451857, 35.70028695585259], [-89.88549726746831, 35.700340434791286], [-89.88543252759746, 35.700357216814105], [-89.88535165212551, 35.70034457002918], [-89.88417653504946, 35.700216016129154], [-89.88324585782865, 35.70009374541399], [-89.88212761700775, 35.699960553260865], [-89.8811246961461, 35.69984752099631], [-89.88110228135318, 35.699838208839665], [-89.88075463712201, 35.69981069805273], [-89.87977517296646, 35.69970089954987], [-89.87752533769222, 35.69943874533986], [-89.8767612227664, 35.6993466132033], [-89.87650322559399, 35.69931090446271], [-89.87643394265905, 35.69946104553885], [-89.87642673687841, 35.69965437630385], [-89.87638106345948, 35.70000143543319], [-89.8761928580837, 35.70123635166785], [-89.8761067531427, 35.70179084238757], [-89.87602507629799, 35.70227826607298], [-89.87594964364176, 35.70265393649595], [-89.87592862554759, 35.70273535189654], [-89.87589001853567, 35.70280323617053], [-89.87582698658173, 35.702857753668226], [-89.87573279500025, 35.70290185753599], [-89.87567891378627, 35.70292546686227], [-89.8752026446677, 35.70299823440624], [-89.87467470801424, 35.7030610764057], [-89.87416054257581, 35.7031263755334], [-89.87384741740627, 35.70317013013691], [-89.8735884742579, 35.7031986375995], [-89.87348292666135, 35.70321231996372], [-89.87341115562828, 35.70321403475685], [-89.87332873114326, 35.703204843549486], [-89.87318919313171, 35.703216048984125], [-89.87303573951904, 35.70322391038958], [-89.87303849169238, 35.7031705423457], [-89.8730749127264, 35.70303398353932], [-89.87310538619468, 35.70287309899705], [-89.87312222422784, 35.70277258492997], [-89.87315420599927, 35.70262333765406], [-89.87318020642765, 35.70254310779182], [-89.87318489101851, 35.702515155494424], [-89.87320434217992, 35.702432152045425], [-89.87322127829238, 35.702340282452184], [-89.87325847158523, 35.70217296625936], [-89.87327381834152, 35.7020395461986], [-89.87327827150342, 35.70193923876493], [-89.87326976074037, 35.70187045219974], [-89.87325133931384, 35.70177808260826], [-89.87322900789022, 35.70171701757577], [-89.87317619310404, 35.701508022682084], [-89.87314702962287, 35.70142494497338], [-89.87310914546966, 35.701295260655336], [-89.8730501729076, 35.70111105184439], [-89.8730140008475, 35.701001038372915], [-89.87297256053392, 35.70091250464662], [-89.8729469472724, 35.700844126583625], [-89.8729273349139, 35.70080270741235], [-89.87290278235469, 35.70076387123315], [-89.87285420647572, 35.700700968931336], [-89.87259383305899, 35.70043204685169], [-89.87250297980721, 35.70034140889306], [-89.87247292014251, 35.70031748686476], [-89.87243860195663, 35.700287096238995], [-89.87240150230123, 35.70026334323129], [-89.87237046645221, 35.70024026645311], [-89.87233235887528, 35.70021653659359], [-89.87228505034899, 35.70018892024843], [-89.87224197316563, 35.700166952969425], [-89.8721915274811, 35.70013612545617], [-89.87213507698236, 35.70010626328361], [-89.87209699901284, 35.70008335460208], [-89.8720517326649, 35.700056511355974], [-89.87198339027896, 35.7000039361421], [-89.87195155508887, 35.699986627574106], [-89.87187800312785, 35.6999571736435], [-89.87180726112415, 35.6999219033337], [-89.87173965523432, 35.699889843247846], [-89.87165968300405, 35.69984986596781], [-89.87155184088974, 35.69979084225292], [-89.87149962096257, 35.69976662799813], [-89.87144216414863, 35.699736789512635], [-89.87138680828768, 35.699709365828475], [-89.87134884848807, 35.699689739227956], [-89.8713179614712, 35.69967076482287], [-89.87129189804536, 35.69964592601531], [-89.8711827737717, 35.699548102901794], [-89.8710754312201, 35.699511605016866], [-89.87093311088823, 35.699453620080185], [-89.87057553113117, 35.69926797348102], [-89.87052730521194, 35.69924284149631], [-89.87040626944994, 35.699180847353944], [-89.8701745469748, 35.69909274657892], [-89.8698490515185, 35.698888613875106], [-89.86962724892263, 35.69876824394774], [-89.86940343563202, 35.698647923366465], [-89.86921772770108, 35.698551331506096], [-89.86904630930796, 35.698460147719224], [-89.86890459616583, 35.698383039649784], [-89.86873613893881, 35.698290141740856], [-89.86867661284323, 35.698258709108956], [-89.8686221480164, 35.69822797679316], [-89.86861288748801, 35.69822244842243], [-89.86857892464482, 35.69820190451671], [-89.86837253924905, 35.69809019976166], [-89.86834280517296, 35.698075303277115], [-89.8681159479975, 35.69795422992337], [-89.86791646002106, 35.6978382536539], [-89.86779930400341, 35.69777205624534], [-89.86777546061641, 35.69775291293969], [-89.86774735704473, 35.69772730180029], [-89.86772863148565, 35.69771050054819], [-89.86771085280478, 35.69769203368864], [-89.86769286943141, 35.697667823363034], [-89.86767828539627, 35.697654208509704], [-89.86765165911581, 35.69764170183836], [-89.86761612421881, 35.69763351468301], [-89.86755126942586, 35.697621919443726], [-89.867457540738, 35.6975913016322], [-89.86742496638304, 35.69758140171008], [-89.86738316102537, 35.69756679276729], [-89.8673273902921, 35.69755580280083], [-89.86726567137735, 35.69754741779979], [-89.86712364606831, 35.697569599659325], [-89.86700605961994, 35.69758925023644], [-89.86632531278472, 35.69771728344671], [-89.8657487978597, 35.69781985489848], [-89.8653681701784, 35.69788712437757], [-89.86511070256313, 35.69793307999877], [-89.86499874293723, 35.6979525954916], [-89.86491845726916, 35.697965228623794], [-89.8648045751316, 35.69795082598911], [-89.86471828311664, 35.69793323801275], [-89.86468336396334, 35.69790190583287], [-89.86467117685322, 35.697876159097966], [-89.86465711300173, 35.69785045616023], [-89.86464652763088, 35.6978170131166], [-89.86463610656484, 35.69778815997025], [-89.86463136937861, 35.6977607045196], [-89.86461338891102, 35.69773050014675], [-89.86454834397817, 35.69769682289794], [-89.86450062216127, 35.69767498500607], [-89.86443155112791, 35.69763374542281], [-89.86437457200925, 35.6975631155679], [-89.86434263868684, 35.69751026987413], [-89.86418566982698, 35.69726895058513], [-89.86408462505375, 35.697121257993864], [-89.86401132538826, 35.697014259770555], [-89.86397553071825, 35.69695844246894], [-89.86398911493251, 35.69691829694096], [-89.86399712600591, 35.69687981539087], [-89.86401970703722, 35.69682873492618], [-89.86398677374714, 35.696800417776615], [-89.86395781186009, 35.69677813383982], [-89.86392107268561, 35.696748376024566], [-89.86387378969012, 35.696738780288484], [-89.86380510309043, 35.69670825186162], [-89.86377195201142, 35.69667381384934], [-89.86373863562069, 35.69663478594943], [-89.86361471286088, 35.69642484198917], [-89.86359292609353, 35.696393196794915], [-89.86354538352731, 35.696323874000356], [-89.86349414355865, 35.696256171384015], [-89.86341130119781, 35.69614480522062], [-89.86336982476877, 35.6960875908068], [-89.86334975063086, 35.69605131007502], [-89.86334319208699, 35.696025429186946], [-89.86332891000811, 35.695993604377215], [-89.86330298912091, 35.69595133683786], [-89.86325836287784, 35.69591104585858], [-89.86317945980763, 35.69583559089987], [-89.86311313300448, 35.695798109294316], [-89.86302981024312, 35.69576791978707], [-89.86292868611963, 35.69572284663535], [-89.86246712722729, 35.695523317878155], [-89.86225369660266, 35.69543411978586], [-89.86196384125064, 35.69530929891882], [-89.86162632190641, 35.695164168132834], [-89.86157656157125, 35.69513778280074], [-89.86151560046518, 35.69511319609828], [-89.86147753341915, 35.6950987854126], [-89.86143190836762, 35.695083023248884], [-89.86138435304974, 35.69506577481427], [-89.86131765486437, 35.69503826104596], [-89.86124720451379, 35.6950108364985], [-89.86122623965245, 35.69500214488318], [-89.86119181663148, 35.694984584873104], [-89.86111662947742, 35.69492970370925], [-89.86108089249335, 35.694875415363875], [-89.86105950794588, 35.694802406727064], [-89.86106615167162, 35.694725668831786], [-89.86106964596178, 35.69466585165464], [-89.86112763026817, 35.694502122300314], [-89.86124307466567, 35.69426503820185], [-89.86131699483035, 35.694126966717604], [-89.8613972547171, 35.694008654522534], [-89.86146597004209, 35.693935033748645], [-89.8615238117596, 35.69387239324121], [-89.86162844309372, 35.69380557607418], [-89.86191019314339, 35.693703912855234], [-89.86214360676887, 35.693615651182974], [-89.8625598919899, 35.69344339372394], [-89.86345386678384, 35.69308362772079], [-89.86392350744754, 35.69288099405233], [-89.86473983238862, 35.69255523237398], [-89.8649749504176, 35.692462330016355], [-89.86514794455759, 35.69236478105542], [-89.86525024178607, 35.69233783759723], [-89.86612451894143, 35.69211024137098], [-89.86652851891287, 35.6920148438869], [-89.86729094636996, 35.69180981495863], [-89.86754966645421, 35.69174697675232], [-89.86832234126229, 35.69156655521116], [-89.868335436368, 35.6915245579568], [-89.86835285873794, 35.691468679682345], [-89.86831823369812, 35.69145143025808], [-89.86826361393003, 35.691446605856], [-89.86822973832246, 35.69144435111216], [-89.86805787035414, 35.69146836034496], [-89.86788649569274, 35.69150614170977], [-89.86741314745123, 35.69160472906885], [-89.86691000192506, 35.69171014988814], [-89.86615762386117, 35.691881242661836], [-89.86554086810995, 35.692012339423705], [-89.86523027707, 35.69209478694316], [-89.86473936094082, 35.69219943069315], [-89.86442598870602, 35.69227959727711], [-89.86426934482412, 35.69232085227511], [-89.86413010106256, 35.69236638299504], [-89.86393985224709, 35.69242476261949], [-89.86355623252355, 35.69255828788751], [-89.86320811275817, 35.69271198291985], [-89.86247918311864, 35.69298965955626], [-89.8619778722306, 35.693200938242974], [-89.86155743113977, 35.69334227775058], [-89.86140220639012, 35.693423363389904], [-89.86108781386781, 35.69358355583695], [-89.86094675466802, 35.69370270023701], [-89.86088895158831, 35.69376126937999], [-89.86080269265968, 35.69383586319231], [-89.86078288628738, 35.693855864994404], [-89.86072157401813, 35.69386290307783], [-89.8606598621256, 35.693858790997474], [-89.8606079050913, 35.69384049598703], [-89.86056921914668, 35.69381072479323], [-89.86054814679359, 35.69369962416474], [-89.86048310809659, 35.693367831943085], [-89.86043541404206, 35.693239975112625], [-89.86018230925231, 35.692673743891206], [-89.86002698781708, 35.69226935773696], [-89.85991093657569, 35.691917978292146], [-89.85988469215071, 35.6918271368496], [-89.85985245093441, 35.691729400789434], [-89.85985247565722, 35.69164966039979], [-89.85987974635637, 35.691447317369374], [-89.85992257611747, 35.69119769909976], [-89.85993509665592, 35.69114580495295], [-89.85993333853386, 35.6910965954337], [-89.85992287995367, 35.691045247651815], [-89.85990700960134, 35.69100341086113], [-89.8598782281226, 35.690922009338394], [-89.85985460521724, 35.69082406925046], [-89.85980387429404, 35.69069159401691], [-89.85975398068688, 35.690582551947635], [-89.85969733824075, 35.6904455269446], [-89.85967650422461, 35.690345174472235], [-89.85964917136383, 35.69022386942834], [-89.85964169521482, 35.69009505691436], [-89.8596203591496, 35.689980644679295], [-89.85958795175215, 35.689878222192434], [-89.8595714980613, 35.689819980596496], [-89.85956332514327, 35.689752162518495], [-89.85953691456123, 35.68965663373923], [-89.85951184219205, 35.68959859792382], [-89.859466999234, 35.68955041171571], [-89.85936336889455, 35.68946609998077], [-89.85931015845163, 35.68942514980973], [-89.8592630294423, 35.689393436477054], [-89.85915811635293, 35.6893537152267], [-89.85906765020194, 35.68931599562497], [-89.85898817073921, 35.689263942233254], [-89.85891064417727, 35.6891860450327], [-89.85887890754695, 35.68910236922181], [-89.85886973221913, 35.689006430628396], [-89.85889460682114, 35.68889795620487], [-89.85895157845303, 35.688802790589186], [-89.85902807261874, 35.68869074321251], [-89.85907879754221, 35.68858165523103], [-89.8591760648779, 35.688487876858126], [-89.85928794606836, 35.688400787325335], [-89.85940903040718, 35.688329894834], [-89.85956728733649, 35.68825342917391], [-89.85968803640336, 35.6881731638591], [-89.85978859323686, 35.688091034262435], [-89.8598498595411, 35.68803563606246], [-89.85990741652196, 35.687956872918534], [-89.8599511138684, 35.68789251095788], [-89.86000563110773, 35.68780912978191], [-89.8600538157884, 35.68770948233727], [-89.86006321257058, 35.687650626149015], [-89.8600610360617, 35.68758970090654], [-89.8600473710343, 35.68752904792071], [-89.8600371630526, 35.68748473045105], [-89.86001758531364, 35.68741952778284], [-89.85999075550384, 35.687312282484754], [-89.85999697174665, 35.68717558716814], [-89.85998724903769, 35.687094906827525], [-89.8599983293858, 35.687022101158], [-89.86002609500277, 35.686937739126236], [-89.86005495599424, 35.68688404143035], [-89.86008079789453, 35.68684157516081], [-89.86013268198113, 35.68676222037215], [-89.860158324606, 35.686714178099656], [-89.8602446776863, 35.68664237386802], [-89.8604053084906, 35.68654369096356], [-89.8604692358199, 35.686514270777465], [-89.86054712910862, 35.68649288772706], [-89.86060511911957, 35.686488718320284]]]]}}]}
Related
How do you post form data using pytest?
I'm trying to write a unit test that posts form data. The actual line in question is: def test_create_request(): with app.test_client() as test_client: app_url = '/requests/' with app.app_context(): new_request = get_new_request() form_data = json.dumps(new_request, default=str) print('FORM DATA: ', form_data) resp = test_client.post(app_url, data=form_data, headers={'Content-Type': 'application/json'}) assert resp.status_code == 200 s = json.loads(resp.data) assert s['success'] == True Where new_request is a dict representation of an object. The print statement yields (I've formatted it a bit): FORM DATA: { "request_id": "6", "state_id": 1, "orig_project_id": "1", "orig_project_code": "QQQ", "orig_allocated_funding": "123.45", "orig_ytd_spend": "123.45", "orig_ytd_commit": "123.45", "orig_ytd_ocnr": "123.45", "new_project_id": 2, "new_funding_amount": 123.45, "new_ytd_spend": 123.45, "new_ytd_commit": 123.45, "new_ytd_ocnr": 123.45, "plan": "this is the plan", "reason": "this is the reason", "sm_director": "sm.dir#example.com", "submitted_by": "xfgbn#vexample.com", "created_on": "2021-09-14 16:32:55", "meets_approval_guidelines": null } In the flask form, most fields are required. When I try to post the data, the form.validate_on_submit() function in the view's route returns False, and the 2nd assert fails. WTForms claims that none of the required orig_allocated_funding, orig_ytd_spend, orig_ytd_commit, orig_ytd_ocnr, new_project_id, new_funding_amount, new_ytd_spend, new_ytd_commit, new_ytd_ocnr, reason, plan, sm_director, or submitted_by fields are supplied. I've read several tutorials, and I can't see what I'm doing wrong. Can anyone help?
What I was able to make work was scraping form_data altogether: def test_create_request(): with app.test_client() as test_client: app_url = '/requests/' with app.app_context(): new_request = get_new_request() resp = test_client.post(app_url, data=new_request) assert resp.status_code == 200 s = json.loads(resp.data) print(s['html']) assert s['success'] == True
Remove some of series' labels in chart
I'm using echarts to display a stacked bar chart. There are 2 series of 360 data points. I'd like to show the series labels, there are 360 labels and they overlap and make it impossible to read the labels. Is there a way to automatically adjust how many labels are displayed? For example for 360 data points, it should only show 10 of those labels. The number of data points changes, so this has to be a dynamic solution based on the number of data points. Currently, the labels look like this: highcharts renders the same data like this: My chart options: chartOptions: { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, yAxis: { type: 'value' }, xAxis: { type: 'category', data: Array.from(Array(360).keys()) }, series: [ { name: 'Direct', type: 'bar', stack: 'total', label: { show: true }, emphasis: { focus: 'series' }, data: [ 180.80271365259728, 181.78206168488214, 182.76671451900847, 183.75670088931975, 184.75204968580374, 185.752789954935, 186.7589509005245, 187.7705618845689, 188.78765242811028, 189.81025221209597, 190.83839107824474, 191.87209902991867, 192.91140623299748, 193.95634301675955, 195.00693987476689, 196.0632274657553, 197.12523661452815, 198.19299831285684, 199.2665437203848, 200.3459041655367, 201.4311111464333, 202.52219633180994, 203.61919156194062, 204.72212884956775, 205.83104038083616, 206.9459585162324, 208.0669157915288, 209.193944918733, 210.32707878704264, 211.46635046380584, 212.61179319548478, 213.76344040862705, 214.9213257108404, 216.08548289177406, 217.25594592410448, 218.4327489645268, 219.6159263547513, 220.80551262250606, 222.00154248254466, 223.20405083765854, 224.41307277969577, 225.62864359058585, 226.85079874336816, 228.07957390322804, 229.3150049285373, 230.5571278719001, 231.80597898120618, 233.0615947006877, 234.32401167198304, 235.59326673520627, 236.86939693002205, 238.15243949672617, 239.44243187733332, 240.739411716669, 242.04341686346766, 243.35448537147818, 244.67265550057357, 245.9979657178685, 247.33045469884019, 248.67016132845902, 250.01712470232144, 251.37138412779234, 252.73297912515113, 254.10194942874568, 255.47833498815135, 256.86217596933716, 258.25351275583773, 259.65238594993195, 261.0588363738275, 262.47290507085233, 263.89463330665274, 265.32406257039713, 266.7612345759868, 268.20619126327347, 269.6589747992829, 271.1196275794456, 272.58819222883426, 274.0647116034071, 275.54922879125877, 277.0417871138782, 278.54243012741165, 280.0512016239352, 281.56814563273144, 283.09330642157545, 284.6267284980256, 286.1684566107233, 287.71853575069804, 289.277011152681, 290.8439282964247, 292.41933290803036, 294.00327096128217, 295.59578867898915, 297.19693253433377, 298.8067492522281, 300.42528581067756, 302.0525894421522, 303.68870763496375, 305.33368813465313, 306.98757894538244, 308.65042833133657, 310.3222848181314, 312.00319719422953, 313.693214512365, 315.3923860909737, 317.10076151563305, 318.8183906405094, 320.54532358981226, 322.2816107592571, 324.02730281753645, 325.78245070779803, 327.54710564913205, 329.32131913806484, 331.1051429500627, 332.8986291410422, 334.7018300488895, 336.5147982949877, 338.33758678575225, 340.17024871417505, 342.01283756137684, 343.8654070981677, 345.7280113866161, 347.600704781627, 349.4835419325274, 351.376577784662, 353.27986758099553, 355.1934668637259, 357.1174314759046, 359.0518175630657, 360.99668157486565, 362.9520802667296, 364.91807070150765, 366.89471025114085, 368.88205659833443, 370.8801677382421, 372.88910198015765, 374.90891794921686, 376.93967458810846, 378.98143115879395, 381.03424724423735, 383.0981827501437, 385.1732979067069, 387.2596532703682, 389.3573097255827, 391.46632848659624, 393.5867710992319, 395.7186994426862, 397.8621757313341, 400.01726251654554, 402.18402268851014, 404.36251947807284, 406.55281645857906, 408.7549775477297, 410.9690670094466, 413.1951494557478, 415.4332898486331, 417.68355350198, 419.9460060834491, 422.2207136164011, 424.50774248182336, 426.80715942026654, 429.1190315337931, 431.44342628793447, 433.78041151366085, 436.1300554093599, 438.4924265428273, 440.8675938532675, 443.2556266533061, 445.65659463101144, 448.07056785192935, 450.49761676112723, 452.93781218525, 455.3912253345868, 457.8579278051492, 460.33799158076044, 462.8314890351563, 465.33849293409673, 467.85907643748976, 470.39331310152613, 472.9412768808261, 475.50304213059724, 478.07868360880457, 480.66827647835214, 483.2718963092766, 485.8896190809519, 488.52152118430706, 491.16767942405534, 493.82817102093566, 496.5030736139656, 499.1924652627081, 501.8964244495478, 504.6150300819828, 507.34836149492685, 510.0964984530243, 512.8595211529782, 515.6375102258902, 518.4305467396138, 521.23871220112, 524.0620885588761, 526.9007582052368, 529.7548039788485, 532.6243091670672, 535.5093575083888, 538.4100331948925, 541.3264208746982, 544.2586056544361, 547.206673101731, 550.1707092476987, 553.150800589457, 556.14703409265, 559.1594971939851, 562.1882778037859, 565.2334643085564, 568.2951455735612, 571.373410945418, 574.4683502547057, 577.5800538185853, 580.708612443436, 583.8541174275047, 587.0166605635703, 590.196334141623, 593.3932309515568, 596.6074442858777, 599.8390679424263, 603.0881962271143, 606.3549239566778, 609.6393464614432, 612.9415595881093, 616.2616597025449, 619.5997436926003, 622.9559089709353, 626.3302534778612, 629.7228756841996, 633.1338745941557, 636.5633497482073, 640.0114012260101, 643.4781296493177, 646.9636361849182, 650.4680225475864, 653.9913910030526, 657.5338443709858, 661.0954860279953, 664.6764199106469, 668.2767505184962, 671.8965829171381, 675.5360227412725, 679.1951761977878, 682.8741500688591, 686.5730517150655, 690.2919890785221, 694.0310706860307, 697.7904056522468, 701.5701036828632, 705.370275077812, 709.1910307344835, 713.032482150962, 716.8947414292796, 720.7779212786883, 724.6821350189477, 728.6074965836337, 732.5541205234617, 736.5221220096305, 740.5116168371826, 744.5227214283841, 748.5555528361211, 752.6102287473168, 756.6868674863647, 760.7855880185825, 764.9065099536832, 769.0497535492657, 773.2154397143241, 777.4036900127767, 781.6146266670127, 785.848372561459, 790.1050512461669, 794.3847869404169, 798.6877045363442, 803.0139296025827, 807.3635883879301, 811.7368078250314, 816.1337155340836, 820.5544398265599, 824.9991097089539, 829.467854886544, 833.9608057671794, 838.4780934650851, 843.0198498046875, 847.586207324463, 852.1772992808037, 856.7932596519081, 861.4342231416894, 866.1003251837069, 870.7917019451186, 875.5084903306547, 880.2508279866124, 885.0188533048732, 889.8127054269413, 894.6325242480038, 899.478450421014, 904.3506253607944, 909.2491912481654, 914.1742910340929, 919.126068443861, 924.1046679812653, 929.1102349328304, 934.1429153720499, 939.2028561636484, 944.2902049678682, 949.4051102447775, 954.5477212586034, 959.7181880820875, 964.9166616008655, 970.1432935178702, 975.3982363577586, 980.6816434713631, 985.9936690401664, 991.3344680808007, 996.7041964495716, 1002.1030108470068, 1007.5310688224281, 1012.9885287785496, 1018.4755499761001, 1023.9922925384706, 1029.5389174563873, 1035.1155865926094, 1040.7224626866528, 1046.3597093595388, 1052.0274911185695, 1057.7259733621286, 1063.4553223845066, 1069.2157053807562, 1075.0072904515685, 1080.8302466081811, 1086.6847437773088, 1092.5709528061025, 1098.4890454671356, 1104.439194463416, 1110.4215734334261, 1116.4363569561906, 1122.48372055637, 1128.5638407093836, 1134.6768948465594, 1140.8230613603116, 1147.0025196093466, 1153.2154499238973, 1159.462033610985, 1165.742452959711, 1172.0568912465762, 1178.4055327408284, 1184.7885627098412, 1191.2061674245197, 1197.6585341647358, 1204.1458512247948, 1210.668307918929, 1217.2260945868234, 1223.8194025991686, 1230.4484243632473, 1237.1133533285483, 1243.8143839924114, 1250.5517119057035, 1257.3255336785262 ] }, { name: 'Direct2', type: 'bar', stack: 'total', label: { show: true }, emphasis: { focus: 'series' }, data: [ 1083.3333333333333, 1082.3539853010484, 1081.369332466922, 1080.3793460966108, 1079.3839973001268, 1078.3832570309955, 1077.377096085406, 1076.3654851013616, 1075.3483945578203, 1074.3257947738346, 1073.2976559076858, 1072.2639479560119, 1071.224640752933, 1070.179703969171, 1069.1291071111636, 1068.0728195201752, 1067.0108103714024, 1065.9430486730737, 1064.8695032655457, 1063.7901428203938, 1062.7049358394972, 1061.6138506541206, 1060.51685542399, 1059.4139181363628, 1058.3050066050944, 1057.1900884696981, 1056.0691311944017, 1054.9421020671975, 1053.808968198888, 1052.6696965221247, 1051.5242537904458, 1050.3726065773035, 1049.2147212750901, 1048.0505640941565, 1046.880101061826, 1045.7032980214037, 1044.5201206311792, 1043.3305343634245, 1042.1345045033859, 1040.931996148272, 1039.7229742062348, 1038.5074033953447, 1037.2852482425624, 1036.0564730827025, 1034.8210420573932, 1033.5789191140304, 1032.3300680047244, 1031.0744522852428, 1029.8120353139475, 1028.5427802507243, 1027.2666500559085, 1025.9836074892044, 1024.6936151085972, 1023.3966352692615, 1022.0926301224629, 1020.7815616144524, 1019.463391485357, 1018.138081268062, 1016.8055922870903, 1015.4658856574715, 1014.1189222836091, 1012.7646628581382, 1011.4030678607794, 1010.0340975571849, 1008.6577119977792, 1007.2738710165934, 1005.8825342300928, 1004.4836610359986, 1003.077210612103, 1001.6631419150782, 1000.2414136792778, 998.8119844155334, 997.3748124099437, 995.9298557226571, 994.4770721866477, 993.0164194064849, 991.5478547570963, 990.0713353825234, 988.5868181946718, 987.0942598720524, 985.5936168585189, 984.0848453619953, 982.5679013531991, 981.0427405643551, 979.5093184879049, 977.9675903752072, 976.4175112352325, 974.8590358332495, 973.2921186895059, 971.7167140779002, 970.1327760246484, 968.5402583069414, 966.9391144515968, 965.3292977337024, 963.710761175253, 962.0834575437783, 960.4473393509668, 958.8023588512774, 957.1484680405481, 955.485618654594, 953.8137621677992, 952.132849791701, 950.4428324735655, 948.7436608949569, 947.0352854702975, 945.3176563454211, 943.5907233961183, 941.8544362266734, 940.1087441683941, 938.3535962781325, 936.5889413367985, 934.8147278478657, 933.0309040358678, 931.2374178448883, 929.434216937041, 927.6212486909428, 925.7984602001783, 923.9657982717555, 922.1232094245537, 920.2706398877629, 918.4080355993144, 916.5353422043036, 914.6525050534032, 912.7594692012685, 910.856179404935, 908.9425801222046, 907.0186155100259, 905.0842294228648, 903.1393654110649, 901.183966719201, 899.2179762844229, 897.2413367347897, 895.2539903875961, 893.2558792476884, 891.2469450057729, 889.2271290367137, 887.1963723978221, 885.1546158271366, 883.1017997416932, 881.0378642357869, 878.9627490792236, 876.8763937155624, 874.7787372603478, 872.6697184993343, 870.5492758866986, 868.4173475432443, 866.2738712545964, 864.118784469385, 861.9520242974204, 859.7735275078577, 857.5832305273515, 855.3810694382008, 853.166979976484, 850.9408975301827, 848.7027571372975, 846.4524934839505, 844.1900409024814, 841.9153333695294, 839.6283045041072, 837.328887565664, 835.0170154521375, 832.6926206979961, 830.3556354722697, 828.0059915765706, 825.6436204431033, 823.268453132663, 820.8804203326245, 818.4794523549191, 816.0654791340012, 813.6384302248033, 811.1982348006806, 808.7448216513437, 806.2781191807813, 803.7980554051701, 801.3045579507742, 798.7975540518338, 796.2769705484408, 793.7427338844044, 791.1947701051045, 788.6330048553333, 786.057363377126, 783.4677705075784, 780.8641506766539, 778.2464279049786, 775.6145258016235, 772.9683675618752, 770.3078759649949, 767.6329733719649, 764.9435817232225, 762.2396225363827, 759.5210169039477, 756.7876854910037, 754.0395485329062, 751.2765258329523, 748.4985367600403, 745.7055002463168, 742.8973347848105, 740.0739584270544, 737.2352887806937, 734.381243007082, 731.5117378188634, 728.6266894775417, 725.726013791038, 722.8096261112323, 719.8774413314944, 716.9293738841995, 713.9653377382318, 710.9852463964735, 707.9890128932806, 704.9765497919454, 701.9477691821446, 698.9025826773741, 695.8409014123694, 692.7626360405126, 689.6676967312249, 686.5559931673453, 683.4274345424946, 680.2819295584259, 677.1193864223602, 673.9397128443076, 670.7428160343737, 667.5286027000528, 664.2969790435043, 661.0478507588163, 657.7811230292527, 654.4967005244873, 651.1944873978213, 647.8743872833857, 644.5363032933302, 641.1801380149952, 637.8057935080693, 634.4131713017309, 631.0021723917748, 627.5726972377232, 624.1246457599204, 620.6579173366129, 617.1724108010123, 613.6680244383441, 610.1446559828779, 606.6022026149448, 603.0405609579352, 599.4596270752836, 595.8592964674343, 592.2394640687925, 588.600024244658, 584.9408707881428, 581.2618969170715, 577.562995270865, 573.8440579074085, 570.1049762998998, 566.3456413336837, 562.5659433030673, 558.7657719081185, 554.945016251447, 551.1035648349686, 547.2413055566509, 543.3581257072423, 539.4539119669828, 535.5285504022968, 531.5819264624688, 527.6139249763, 523.6244301487479, 519.6133255575464, 515.5804941498094, 511.52581823861374, 507.44917949956584, 503.350458967348, 499.2295370322473, 495.08629343666485, 490.9206072716064, 486.73235697315386, 482.5214203189179, 478.28767442447156, 474.0309957397636, 469.7512600455136, 465.44834244958633, 461.1221173833478, 456.7724585980004, 452.3992391608991, 448.0023314518469, 443.5816071593706, 439.1369372769766, 434.6681920993865, 430.1752412187511, 425.65795352084547, 421.116197181243, 416.54983966146756, 411.9587477051268, 407.34278733402243, 402.7018238442412, 398.03572180222363, 393.34434504081196, 388.62755665527584, 383.8852189993181, 379.1171936810573, 374.3233415589892, 369.5035227379267, 364.6575965649165, 359.7854216251361, 354.88685573776513, 349.96175595183763, 345.0099785420696, 340.03137900466527, 335.02581205310014, 329.9931316138807, 324.9331908222821, 319.8458420180623, 314.7309367411531, 309.5883257273272, 304.417858903843, 299.21938538506504, 293.9927534680603, 288.7378106281719, 283.4544035145674, 278.1423779457641, 272.8015789051299, 267.431850536359, 262.03303613892376, 256.60497816350244, 251.14751820738093, 245.66049700983046, 240.14375444745997, 234.59712952954328, 229.02046039332117, 223.41358429927777, 217.77633762639175, 212.10855586736102, 206.41007362380196, 200.6807246014239, 194.92034160517437, 189.12875653436208, 183.3058003777494, 177.45130320862177, 171.56509417982807, 165.64700151879492, 159.69685252251452, 153.7144735525044, 147.69969002973994, 141.65232642956062, 135.57220627654692, 129.4591521393711, 123.31298562561892, 117.13352737658397, 110.92059706203327, 104.67401337494562, 98.39359402621949, 92.07915573935429, 85.73051424510209, 79.34748427608929, 72.92987956141087, 66.47751282119475, 59.99019576113574, 53.4677390670015, 46.90995239910717, 40.316644386761936, 33.68762262268319, 27.022693657382206, 20.321662993519112, 13.584335080226992, 6.810513307404335 ] }, ] }
Here is my solution, not sure if there is a built-in option Modify char option, to use a custom formatter: label: { show: true, formatter: myFormatter }, Implement a custom formatted, this assumes you want a total of 10 labels + a label for the very last data point. size is the size of the series (in my case 360). function myFormatter(params, size) { if (params.dataIndex % Math.floor(size / 10) == 0 || params.dataIndex == size - 1) { // make sure we have a label for the last datapoint return params.data } return "" }
Error with inserting a point into a geometry (point) typed column in Postgress with PostGIS
I need to insert a point into Column(Geometry(geometry_type='POINT', srid=4326)). I can not figure out how to implement the srid=4326 into the point data POINT(58.183594 22.593726). I searched for it. I still cannot solve this! Error: sqlalchemy.exc.DataError: (psycopg2.errors.InvalidParameterValue) Geometry SRID (0) does not match column SRID (4326) [SQL: INSERT INTO addresses (label, coordinates, building_number, flat_number, disabled, created_at, updated_at, user_id) VALUES (%(label)s, ST_GeomFromEWKT(%(coordinates)s), %(building_number)s, %(flat_number)s, %(disabled)s, %(created_at)s, %(updated_at)s, %(user_id)s) RETURNING addresses.id] [parameters: {'label': 'my home', 'coordinates': 'POINT(58.183594 22.593726)', 'building_number': 1, 'flat_number': None, 'disabled': False, 'created_at': datetime.datetime(2020, 9, 28, 11, 11, 3, 913693), 'updated_at': datetime.datetime(2020, 9, 28, 11, 11, 3, 913706), 'user_id': 1}] FastAPI route: #router.post("/{id}/addresses", response_model=schemas.AddressOut) async def create_a_new_address(id:int, address_in: schemas.AddressIn, db: Session = Depends(get_db), token_data: schemas.TokenDecoded = Depends(auth.decode_token)): if id == token_data.id or auth.can_access(token_data.bitrole, "USERS"): address_in_db= schemas.AddressInDB(**address_in.dict(), user_id=id) return crud.create_address(db=db, address=address_in_db) else: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="access denied" ) pydantic (schemas.py): def set_now(time: datetime.datetime)-> datetime.datetime: return time or datetime.datetime.now() def tuple_to_point(coord_tuple: Tuple)->str: return f'POINT({coord_tuple[0]} {coord_tuple[1]})' class AddressIn(BaseModel): label: str = ... coordinates: Tuple[float,float] = ... building_number: int = ... flat_number: Optional[int]=None class AddressInDB(AddressIn): created_at: datetime.datetime = None updated_at: datetime.datetime = None coordinates: str = ... user_id: int = ... _created_at = validator('created_at', allow_reuse=True, pre=True, always=True)(set_now) _updated_at = validator('updated_at', allow_reuse=True, pre=True, always=True)(set_now) _coordinates = validator('coordinates', allow_reuse=True, pre=True, always=True)(tuple_to_point) class AddressOut(AddressInDB): id: int sqlalchemy,geoalchemy2 (tables.py): class Addresses(Base): __tablename__="addresses" id= Column(Integer, primary_key=True, index=True) label= Column(String) coordinates= Column(Geometry(geometry_type='POINT', srid=4326)) building_number= Column(String) flat_number= Column(String, nullable=True) disabled = Column(Boolean, default=False) created_at= Column(DateTime) updated_at= Column(DateTime) user_id = Column(Integer, ForeignKey('users.id')) crud.py def create_address(db: Session, address: schemas.AddressInDB): db_address = tables.Addresses(**address.dict()) db.add(db_address) try: db.commit() except IntegrityError as e: process_db_error(e) db.refresh(db_address) return db_address
Use the EWKT representation: 'SRID=4326;POINT(58.183594 22.593726)'
D3 Multi Line Graph with Dots
I am new to D3.js. I love it but I am having real trouble figuring out the best approach to structuring data. I would ideally like to create a simple multiline graph that has over points over the selected points. Firstly I have the multiple lines created but trying to add the points has stumped me, and I think it has to do with the structure of my data. Here is my working fiddle. I'm not sure if I should be trying to use d3.nest to re-arrange the data I have a json object that I am retrieving from a google form which is all nice and smooth. This is what it looks like: var data = [{ "description": "Global warming is a serious and pressing problem. We should begin taking steps now even if this involves significant costs", "year2013": 40, "year2012": 36, "year2011": 41, "year2010": 46, "year2009": 48, "year2008": 60, "year2006": 68, }, { "description": "The problem of global warming should be addressed, but its effects will be gradual, so we can deal with the problem gradually by taking steps that are low in cost", "year2013": 44, "year2012": 45, "year2011": 40, "year2010": 40, "year2009": 39, "year2008": 32, "year2006": 24, }, { "description": "Until we are sure that global warming is really a problem, we should not take any steps that would have economic costs", "year2013": 16, "year2012": 18, "year2011": 19, "year2010": 13, "year2009": 13, "year2008": 8, "year2006": 7, }, { "description": "Don't know / refused", "year2013": 1, "year2012": 1, "year2011": 1, "year2010": 1, "year2009": 1, "year2008": 0, "year2006": 1, }] Any help would be appreciated, I have been at it for days. Cheers!
First - I would flatten your data data = [ {date:"2011",type: "line0", amount:20} ... ] Then nest your data by type nested = d3.nest() .key( (d) -> return d.type ) .entries(data) Then append your line groups # Line Groups groups = container.selectAll('g.full-line') .data(nested, (d) -> return d.key ) # ENTER groups.enter().append('svg:g') .attr( 'class', (d,i) -> "full-line#{i}" ) # EXIT d3.transition(groups.exit()).remove() # TRANSITION d3.transition(groups) Then append your chart lines # Individual Lines lines = groups.selectAll('.line').data (d)-> [d.values] # ENTER lines.enter().append("svg:path") .attr("class","line") .attr("d", d3.svg.line() .interpolate(interpolate) .defined(defined) .x( (d,i) -> return xScale(d,i) ) .y( (d,i) -> return yScale(d,i) ) ) # EXIT d3.transition( groups.exit().selectAll('.line') ) .attr("d", d3.svg.line() .interpolate(interpolate) .defined(defined) .x( (d,i) -> return xScale(d,i) ) .y( (d,i) -> return yScale(d,i) ) ) # TRANSITION d3.transition(lines) .attr("d", d3.svg.line() .interpolate(interpolate) .defined(defined) .x( (d,i) -> return xScale(d,i) ) .y( (d,i) -> return yScale(d,i) ) )
Thanks I ended up using something similar. /* Transform Data */ data = data.map(function (d) { return { country: d.country, date: new Date(d.year.toString()), value: d.value }; }); /* Nest Data */ data = d3.nest().key(function (d) { return d.country; }).entries(data);`
Sorting and obtaining the top 5 rows from a dataview
I have the below data table DataTable dtEquityHoldings = new DataTable("EquityHoldings"); dtEquityHoldings.Columns.Add("EquityHoldings"); dtEquityHoldings.Columns.Add("PortfolioWeight(%)"); dtEquityHoldings.Columns.Add("MarketValue", typeof(double)); dtEquityHoldings.Columns.Add("Beta", typeof(double)); dtEquityHoldings.Columns.Add("Beta Adj. Delta", typeof(double)); dtEquityHoldings.Columns.Add("Vega", typeof(double)); dtEquityHoldings.Rows.Add("Santarus Inc", "0.81%", 882380.26, -1.56, 114709.43, 24937.23); dtEquityHoldings.Rows.Add("Dell Inc", "1.21%", 1318123.60, 1.3, 324757.27, 47923.72); dtEquityHoldings.Rows.Add("JPMorgan and Chase Co", "2.95%", 3213607.12, 1.12, 258414.50, 38472.28); dtEquityHoldings.Rows.Add("Qualcomm Inc", "1.38%", 1503314.52, 1, 315608.54, 36938.75); dtEquityHoldings.Rows.Add("Nokia", "2.45%", 2668927.95, 0.87, -346960.63, 39283.23); dtEquityHoldings.Rows.Add("Rite Aid Corp", "1.84%", 2004419.36, 0.82, 139526.19, 92374.56); dtEquityHoldings.Rows.Add("General Electric", "3.80%", 4139561.72, -0.78, 538143.02, 23947.83); dtEquityHoldings.Rows.Add("Microsoft Corp", "2.06%", 2244078.20, 0.78, 454383.09, 42938.44); dtEquityHoldings.Rows.Add("Johnson & Johnson", "4.47%", 4869431.81, 0.63, 633026.14, 82374.23); dtEquityHoldings.Rows.Add("Power Inc.", "3.46%", 3769179.88, 0.13, 493374.82, 12930.02); I want to sort the Beta column and then I have to take TOP 5 rows and then I have to bind that to the grid I am using a dataview as under DataView dvData = new DataView(dtEquityHoldings); dvData.ToTable().AsEnumerable().OrderBy(r => r["Beta"]).Take(5); dataGridView1.DataSource = dvData; This is not working Please help One more
You're using LINQ. LINQ methods don't modify original collections. Try this: dataGridView1.DataSource = dvData.ToTable().AsEnumerable().OrderBy(r => r["Beta"]).Take(5).ToList();