diff --git a/datawrapper/__main__.py b/datawrapper/__main__.py index 1f6aaca..c6818ae 100644 --- a/datawrapper/__main__.py +++ b/datawrapper/__main__.py @@ -1180,6 +1180,37 @@ def add_data(self, chart_id: str, data: pd.DataFrame | str) -> bool: dump_data=False, ) + def add_json(self, chart_id: str, data: Any) -> bool: + """Add JSON data to a specified chart. + + Can be used to add point, area and line markers to a locator map or other chart. + + Parameters + ---------- + chart_id : str + ID of chart, table or map to add data to. + data : Any + JSON data to add to the chart. + + Returns + ------- + bool + True if the data was added successfully. + """ + # Set the chart metadata to accept JSON data + self.update_chart( + chart_id=chart_id, + metadata={ + "data": {"json": True}, + }, + ) + + # Dump the provided data as a JSON string + json_data = json.dumps(data) + + # Post it to the chart via the add_data method + return self.add_data(chart_id, json_data) + def refresh_data(self, chart_id: str) -> dict: """Fetch configured external data and add it to the chart. diff --git a/tests/area_markers.json b/tests/area_markers.json new file mode 100644 index 0000000..3c72110 --- /dev/null +++ b/tests/area_markers.json @@ -0,0 +1,1624 @@ +{ + "markers": [ + { + "id": "m1", + "type": "area", + "visible": true, + "exactShape": true, + "fill": true, + "stroke": true, + "properties": { + "fill": "#15607a", + "fill-opacity": 0.2, + "stroke": "#15607a", + "stroke-width": 1, + "stroke-opacity": 1, + "stroke-dasharray": "100000", + "pattern": "solid", + "pattern-line-width": 2, + "pattern-line-gap": 2 + }, + "feature": { + "type": "Feature", + "properties": [], + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [ + -0.010986328125, + 51.68085800512344 + ], + [ + -0.011672973632812, + 51.663824862767655 + ], + [ + -0.008926391601562, + 51.65977855013472 + ], + [ + -0.012359619140625, + 51.646146206896816 + ], + [ + -0.007209777832031, + 51.646146206896816 + ], + [ + -0.00823974609375, + 51.64358968607138 + ], + [ + -0.003776550292969, + 51.642737480428536 + ], + [ + -0.000686645507812, + 51.643802734979374 + ], + [ + 0.001029968261719, + 51.641672200850536 + ], + [ + 0.017509460449219, + 51.64018076739535 + ], + [ + 0.022659301757812, + 51.641033021090635 + ], + [ + 0.025749206542969, + 51.63464072793931 + ], + [ + 0.023613041308899, + 51.631657349449995 + ], + [ + 0.023689270019531, + 51.631657349449995 + ], + [ + 0.021629333496094, + 51.62888689371772 + ], + [ + 0.029182434082031, + 51.625050598752864 + ], + [ + 0.040855407714844, + 51.61567162313841 + ], + [ + 0.053215026855469, + 51.61844288587238 + ], + [ + 0.054244995117188, + 51.61673751344668 + ], + [ + 0.050468444824219, + 51.61652433738763 + ], + [ + 0.048065185546875, + 51.61311338426475 + ], + [ + 0.062828063964844, + 51.60693037835708 + ], + [ + 0.072784423828125, + 51.60458487995277 + ], + [ + 0.078964233398438, + 51.607143599476416 + ], + [ + 0.088920593261719, + 51.60479811208742 + ], + [ + 0.092697143554688, + 51.60629070899074 + ], + [ + 0.091667175292969, + 51.607783256826195 + ], + [ + 0.094757080078125, + 51.610768205295784 + ], + [ + 0.092697143554688, + 51.61375295750099 + ], + [ + 0.098190307617188, + 51.61545844207285 + ], + [ + 0.100250244140625, + 51.61268699710061 + ], + [ + 0.103340148925781, + 51.61353976742359 + ], + [ + 0.103683471679688, + 51.612473802016524 + ], + [ + 0.116729736328125, + 51.61695068850443 + ], + [ + 0.120162963867188, + 51.61567162313841 + ], + [ + 0.12908935546875, + 51.62142713341987 + ], + [ + 0.135612487792969, + 51.62355861865933 + ], + [ + 0.15655517578125, + 51.62334547464101 + ], + [ + 0.168914794921875, + 51.62142713341987 + ], + [ + 0.180244445800781, + 51.6244111847202 + ], + [ + 0.1812744140625, + 51.62590313677916 + ], + [ + 0.185737609863281, + 51.6244111847202 + ], + [ + 0.186080932617188, + 51.62547686976848 + ], + [ + 0.18951416015625, + 51.6244111847202 + ], + [ + 0.194664001464844, + 51.62569000377442 + ], + [ + 0.203590393066406, + 51.625050598752864 + ], + [ + 0.224189758300781, + 51.631657349449995 + ], + [ + 0.237236022949219, + 51.62398490369225 + ], + [ + 0.252685546875, + 51.61759020766988 + ], + [ + 0.264701843261719, + 51.60842290516359 + ], + [ + 0.2581787109375, + 51.606503933114226 + ], + [ + 0.253715515136719, + 51.60181277107466 + ], + [ + 0.269851684570312, + 51.59946700829792 + ], + [ + 0.271224975585938, + 51.588802922988776 + ], + [ + 0.287017822265625, + 51.57322886201342 + ], + [ + 0.290107727050781, + 51.564266024413854 + ], + [ + 0.3131103515625, + 51.565759953388806 + ], + [ + 0.315170288085938, + 51.55786291569686 + ], + [ + 0.322036743164062, + 51.55423408721512 + ], + [ + 0.322036743164062, + 51.55273977957103 + ], + [ + 0.324440002441406, + 51.55316672962127 + ], + [ + 0.327873229980469, + 51.55103193929688 + ], + [ + 0.328903198242188, + 51.545694525178334 + ], + [ + 0.331306457519531, + 51.54590803376547 + ], + [ + 0.333709716796875, + 51.54270529976026 + ], + [ + 0.334015447296679, + 51.54080382194188 + ], + [ + 0.334015447296679, + 51.54056807007491 + ], + [ + 0.301094055175781, + 51.538861721387775 + ], + [ + 0.297317504882812, + 51.53779400311785 + ], + [ + 0.297660827636719, + 51.535231377071256 + ], + [ + 0.265388488769531, + 51.53224146432561 + ], + [ + 0.266761779785156, + 51.52305693293329 + ], + [ + 0.264015197753906, + 51.52156160130252 + ], + [ + 0.263671875, + 51.51792987720293 + ], + [ + 0.253715515136719, + 51.51792987720293 + ], + [ + 0.250968933105469, + 51.52882418070985 + ], + [ + 0.246162414550781, + 51.526474649424785 + ], + [ + 0.245819091796875, + 51.52348416152353 + ], + [ + 0.242729187011719, + 51.52433860667918 + ], + [ + 0.240669250488281, + 51.52220246372815 + ], + [ + 0.245132446289062, + 51.51878442657494 + ], + [ + 0.237236022949219, + 51.519425328081894 + ], + [ + 0.241012573242188, + 51.513870548723986 + ], + [ + 0.242042541503906, + 51.507887721028425 + ], + [ + 0.226593017578125, + 51.506605584300445 + ], + [ + 0.230026245117188, + 51.49933946133652 + ], + [ + 0.224876403808594, + 51.49741588191225 + ], + [ + 0.214920043945312, + 51.4965609316647 + ], + [ + 0.210456848144531, + 51.4901482936383 + ], + [ + 0.210456848144531, + 51.485872700458316 + ], + [ + 0.216293334960938, + 51.48523132690005 + ], + [ + 0.223846435546875, + 51.48223813101211 + ], + [ + 0.216636657714844, + 51.479886196414014 + ], + [ + 0.216636657714844, + 51.47689264968477 + ], + [ + 0.21148681640625, + 51.475181963339594 + ], + [ + 0.211830139160156, + 51.4732573645137 + ], + [ + 0.208740234375, + 51.471118826139474 + ], + [ + 0.21148681640625, + 51.468766318140865 + ], + [ + 0.210456848144531, + 51.462563670141634 + ], + [ + 0.2032470703125, + 51.45892724311224 + ], + [ + 0.2032470703125, + 51.45422084861252 + ], + [ + 0.199127197265625, + 51.45208141796738 + ], + [ + 0.192947387695312, + 51.45165351980677 + ], + [ + 0.190887451171875, + 51.44887208400473 + ], + [ + 0.187454223632812, + 51.448658120386 + ], + [ + 0.184364318847656, + 51.44459262112173 + ], + [ + 0.176124572753906, + 51.44202475087508 + ], + [ + 0.172691345214844, + 51.443308704047126 + ], + [ + 0.166854858398438, + 51.43560444354014 + ], + [ + 0.166511535644531, + 51.4304675478804 + ], + [ + 0.164451599121094, + 51.42854106309201 + ], + [ + 0.155868530273438, + 51.430895644580175 + ], + [ + 0.15380859375, + 51.427470758666345 + ], + [ + 0.153121948242188, + 51.42190477150615 + ], + [ + 0.15106201171875, + 51.42040612067029 + ], + [ + 0.154495239257812, + 51.41826510565903 + ], + [ + 0.15106201171875, + 51.41762278159905 + ], + [ + 0.149002075195312, + 51.41248386417172 + ], + [ + 0.15380859375, + 51.411199044550045 + ], + [ + 0.152778625488281, + 51.40862929698622 + ], + [ + 0.148658752441406, + 51.40820099168391 + ], + [ + 0.155181884765625, + 51.40413189121389 + ], + [ + 0.158615112304688, + 51.396206814317566 + ], + [ + 0.162391662597656, + 51.392565102360834 + ], + [ + 0.147628784179688, + 51.392779328736054 + ], + [ + 0.149688720703125, + 51.39085125524704 + ], + [ + 0.149688720703125, + 51.38013825621951 + ], + [ + 0.153121948242188, + 51.37756676326666 + ], + [ + 0.149688720703125, + 51.373923567619784 + ], + [ + 0.151748657226562, + 51.368351060511316 + ], + [ + 0.149345397949219, + 51.36920841344187 + ], + [ + 0.144882202148438, + 51.3627778751696 + ], + [ + 0.145912170410156, + 51.35827596108899 + ], + [ + 0.142822265625, + 51.3509862096453 + ], + [ + 0.136299133300781, + 51.34583980435289 + ], + [ + 0.136985778808594, + 51.34412420747762 + ], + [ + 0.124626159667969, + 51.34583980435289 + ], + [ + 0.118446350097656, + 51.34412420747762 + ], + [ + 0.116729736328125, + 51.34133622557778 + ], + [ + 0.121536254882812, + 51.333614775203245 + ], + [ + 0.117759704589844, + 51.32975356228201 + ], + [ + 0.114326477050781, + 51.327393772088584 + ], + [ + 0.104713439941406, + 51.327393772088584 + ], + [ + 0.100593566894531, + 51.32567748476333 + ], + [ + 0.097160339355469, + 51.32181560342829 + ], + [ + 0.088233947753906, + 51.31859712057431 + ], + [ + 0.08514404296875, + 51.31602217169265 + ], + [ + 0.083427429199219, + 51.31065723063375 + ], + [ + 0.084800720214844, + 51.30615019533002 + ], + [ + 0.082740783691406, + 51.305720930785526 + ], + [ + 0.086174011230469, + 51.30014012631992 + ], + [ + 0.091323852539062, + 51.296920122756745 + ], + [ + 0.083084106445312, + 51.29219704228905 + ], + [ + 0.058364868164062, + 51.289405902716794 + ], + [ + 0.055961608886719, + 51.292411738305674 + ], + [ + 0.051155090332031, + 51.29391458231311 + ], + [ + 0.046005249023438, + 51.29412927029858 + ], + [ + 0.042228698730469, + 51.29262643331842 + ], + [ + 0.044288635253906, + 51.298422819194144 + ], + [ + 0.042572021484375, + 51.301642717353275 + ], + [ + 0.033302307128906, + 51.30743796487255 + ], + [ + 0.024375915527344, + 51.301857369199894 + ], + [ + 0.02197265625, + 51.29714883228716 + ], + [ + 0.02197265625, + 51.296920122756745 + ], + [ + 0.01922607421875, + 51.29176764724403 + ], + [ + 0.015106201171875, + 51.29176764724403 + ], + [ + 0.00823974609375, + 51.31022800824789 + ], + [ + 0.010299682617188, + 51.31623675628654 + ], + [ + 0.006523132324219, + 51.31559299949379 + ], + [ + 0.002403259277344, + 51.32910999518174 + ], + [ + -0.000686645507812, + 51.328680945430165 + ], + [ + -0.00823974609375, + 51.333829277498126 + ], + [ + -0.012016296386719, + 51.33297126229712 + ], + [ + -0.014419555664062, + 51.32975356228201 + ], + [ + -0.021286010742188, + 51.337904630423196 + ], + [ + -0.033302307128906, + 51.337475662965204 + ], + [ + -0.037765502929688, + 51.33876255329662 + ], + [ + -0.041885375976562, + 51.333829277498126 + ], + [ + -0.051155090332031, + 51.33168420938816 + ], + [ + -0.047721862792969, + 51.326321100037546 + ], + [ + -0.051498413085938, + 51.32245927289978 + ], + [ + -0.063858032226562, + 51.31859712057431 + ], + [ + -0.070037841796875, + 51.318811693123735 + ], + [ + -0.071067810058594, + 51.32117192492373 + ], + [ + -0.078964233398438, + 51.31966997328442 + ], + [ + -0.078964233398438, + 51.31816797246444 + ], + [ + -0.084800720214844, + 51.315807586095076 + ], + [ + -0.082054138183594, + 51.31065723063375 + ], + [ + -0.088577270507812, + 51.307652589616396 + ], + [ + -0.091323852539062, + 51.301428064502886 + ], + [ + -0.097503662109375, + 51.30121341064864 + ], + [ + -0.094413757324219, + 51.29928148078781 + ], + [ + -0.111236572265625, + 51.29219704228905 + ], + [ + -0.115013122558594, + 51.292411738305674 + ], + [ + -0.117759704589844, + 51.28704403671466 + ], + [ + -0.124282836914062, + 51.28682931559993 + ], + [ + -0.1373291015625, + 51.30078409992865 + ], + [ + -0.141105651855469, + 51.299496143676606 + ], + [ + -0.143508911132812, + 51.30121341064864 + ], + [ + -0.14556884765625, + 51.29992546644263 + ], + [ + -0.155525207519531, + 51.301428064502886 + ], + [ + -0.157928466796875, + 51.30443311306081 + ], + [ + -0.154495239257812, + 51.3063648260966 + ], + [ + -0.157241821289062, + 51.30679408461833 + ], + [ + -0.154495239257812, + 51.31022800824789 + ], + [ + -0.158271789550781, + 51.311086449004534 + ], + [ + -0.157241821289062, + 51.313447078275885 + ], + [ + -0.16204833984375, + 51.31966997328442 + ], + [ + -0.15655517578125, + 51.32160104493042 + ], + [ + -0.164108276367188, + 51.326106562616445 + ], + [ + -0.163078308105469, + 51.33018260199751 + ], + [ + -0.17303466796875, + 51.32996808264156 + ], + [ + -0.174064636230469, + 51.33318576760277 + ], + [ + -0.182304382324219, + 51.33811911264689 + ], + [ + -0.197410583496094, + 51.34369529822385 + ], + [ + -0.201187133789062, + 51.33983493430884 + ], + [ + -0.213203430175781, + 51.33554525972849 + ], + [ + -0.211830139160156, + 51.333400271904765 + ], + [ + -0.215950012207031, + 51.32975356228201 + ], + [ + -0.220756530761719, + 51.32975356228201 + ], + [ + -0.229339599609375, + 51.33597424525047 + ], + [ + -0.217323303222656, + 51.343480842091765 + ], + [ + -0.217666625976562, + 51.34562535825569 + ], + [ + -0.226593017578125, + 51.36234914051147 + ], + [ + -0.233116149902344, + 51.3659932571795 + ], + [ + -0.245475769042969, + 51.36685065425564 + ], + [ + -0.245132446289062, + 51.38013825621951 + ], + [ + -0.252342224121094, + 51.37885252780106 + ], + [ + -0.261268615722656, + 51.37949539652476 + ], + [ + -0.265388488769531, + 51.37520943448462 + ], + [ + -0.285301208496094, + 51.364492773668246 + ], + [ + -0.28839111328125, + 51.362134771677404 + ], + [ + -0.284957885742188, + 51.36127728630754 + ], + [ + -0.290794372558594, + 51.35698961864972 + ], + [ + -0.292854309082031, + 51.352272720657794 + ], + [ + -0.304183959960938, + 51.343051926817 + ], + [ + -0.305557250976562, + 51.3353307654622 + ], + [ + -0.319290161132812, + 51.32782283388363 + ], + [ + -0.327529907226562, + 51.326321100037546 + ], + [ + -0.330619812011719, + 51.32825189166411 + ], + [ + -0.327529907226562, + 51.34390975335248 + ], + [ + -0.330619812011719, + 51.3484130792483 + ], + [ + -0.319976806640625, + 51.35934788552862 + ], + [ + -0.317230224609375, + 51.37263766463755 + ], + [ + -0.314483642578125, + 51.37456650556686 + ], + [ + -0.308647155761719, + 51.37542374211739 + ], + [ + -0.307273864746094, + 51.37842394363582 + ], + [ + -0.3131103515625, + 51.388923100504854 + ], + [ + -0.31585693359375, + 51.38763761886881 + ], + [ + -0.316886901855469, + 51.38849461063876 + ], + [ + -0.314140319824219, + 51.390422783437344 + ], + [ + -0.316886901855469, + 51.39320777847715 + ], + [ + -0.324783325195312, + 51.39149395543811 + ], + [ + -0.328559875488281, + 51.3921366466011 + ], + [ + -0.339546203613281, + 51.4024184774274 + ], + [ + -0.358772277832031, + 51.41184145887419 + ], + [ + -0.365982055664062, + 51.41141318366104 + ], + [ + -0.379371643066406, + 51.407772682369625 + ], + [ + -0.383148193359375, + 51.40841514483657 + ], + [ + -0.383834838867188, + 51.41012833395047 + ], + [ + -0.389328002929688, + 51.41034247807633 + ], + [ + -0.390357971191406, + 51.41441102590505 + ], + [ + -0.386238098144531, + 51.41419690083532 + ], + [ + -0.386581420898438, + 51.41997792569123 + ], + [ + -0.391731262207031, + 51.42254703539257 + ], + [ + -0.396881103515625, + 51.42361745514586 + ], + [ + -0.406494140625, + 51.42276112134897 + ], + [ + -0.413703918457031, + 51.43003944716932 + ], + [ + -0.418853759765625, + 51.432393951441185 + ], + [ + -0.427436828613281, + 51.430895644580175 + ], + [ + -0.429496765136719, + 51.428755120968646 + ], + [ + -0.439796447753906, + 51.4304675478804 + ], + [ + -0.439796447753906, + 51.43474833437489 + ], + [ + -0.44769287109375, + 51.43496236317034 + ], + [ + -0.446319580078125, + 51.44009875343349 + ], + [ + -0.456619262695312, + 51.43817267477053 + ], + [ + -0.455245971679688, + 51.44202475087508 + ], + [ + -0.457305908203125, + 51.44309471435855 + ], + [ + -0.457649230957031, + 51.449300008234246 + ], + [ + -0.46142578125, + 51.449086046620806 + ], + [ + -0.459365844726562, + 51.45678803304111 + ], + [ + -0.473442077636719, + 51.45849940911873 + ], + [ + -0.477561950683594, + 51.46149416285701 + ], + [ + -0.489578247070312, + 51.461708066319034 + ], + [ + -0.494041442871094, + 51.462777568590894 + ], + [ + -0.4998779296875, + 51.46705532704274 + ], + [ + -0.507431030273438, + 51.466841448644175 + ], + [ + -0.510375131470255, + 51.4680641509232 + ], + [ + -0.510375131470255, + 51.46826093979469 + ], + [ + -0.505714416503906, + 51.4726158135274 + ], + [ + -0.503654479980469, + 51.480527645151454 + ], + [ + -0.498847961425781, + 51.485658910274594 + ], + [ + -0.499191284179688, + 51.48865188163202 + ], + [ + -0.488548278808594, + 51.49591970845512 + ], + [ + -0.489921569824219, + 51.49891200625808 + ], + [ + -0.48614501953125, + 51.500835522540086 + ], + [ + -0.483055114746094, + 51.506605584300445 + ], + [ + -0.485458374023438, + 51.510024535400305 + ], + [ + -0.489921569824219, + 51.51152024583138 + ], + [ + -0.489578247070312, + 51.51408420661045 + ], + [ + -0.492324829101562, + 51.51686166794059 + ], + [ + -0.4888916015625, + 51.5292513551899 + ], + [ + -0.490608215332031, + 51.53416357363511 + ], + [ + -0.495414733886719, + 51.538861721387775 + ], + [ + -0.49163818359375, + 51.54163767166358 + ], + [ + -0.49163818359375, + 51.54590803376547 + ], + [ + -0.477218627929688, + 51.55530141976371 + ], + [ + -0.476531982421875, + 51.55786291569686 + ], + [ + -0.4779052734375, + 51.560424267373435 + ], + [ + -0.481338500976562, + 51.56085114529478 + ], + [ + -0.482711791992188, + 51.56597336780695 + ], + [ + -0.484771728515625, + 51.566613605050975 + ], + [ + -0.484085083007812, + 51.57536261053028 + ], + [ + -0.4888916015625, + 51.57706953722564 + ], + [ + -0.489578247070312, + 51.58197659439875 + ], + [ + -0.494728088378906, + 51.584536587807094 + ], + [ + -0.499534606933594, + 51.59200241147292 + ], + [ + -0.498504638671875, + 51.594561840016524 + ], + [ + -0.500907897949219, + 51.600320026964084 + ], + [ + -0.496444702148438, + 51.602026016227626 + ], + [ + -0.49736027678824, + 51.60437164681676 + ], + [ + -0.497474670410156, + 51.60437164681676 + ], + [ + -0.499191284179688, + 51.609062544488665 + ], + [ + -0.495414733886719, + 51.61908238401074 + ], + [ + -0.500221252441406, + 51.621853438477814 + ], + [ + -0.497817993164062, + 51.62569000377442 + ], + [ + -0.499534606933594, + 51.63037869859852 + ], + [ + -0.497474670410156, + 51.631657349449995 + ], + [ + -0.49163818359375, + 51.63080491955375 + ], + [ + -0.487174987792969, + 51.626329399784964 + ], + [ + -0.476875305175781, + 51.6220665895049 + ], + [ + -0.469322204589844, + 51.61673751344668 + ], + [ + -0.457305908203125, + 51.61226060593114 + ], + [ + -0.448036193847656, + 51.615884803202675 + ], + [ + -0.445632934570312, + 51.61972187313762 + ], + [ + -0.440826416015625, + 51.62014819421577 + ], + [ + -0.426750183105469, + 51.61695068850443 + ], + [ + -0.416793823242188, + 51.61652433738763 + ], + [ + -0.411300659179688, + 51.61375295750099 + ], + [ + -0.399627685546875, + 51.61332657634483 + ], + [ + -0.371475219726562, + 51.61929554805431 + ], + [ + -0.35980224609375, + 51.62526373476126 + ], + [ + -0.349502563476562, + 51.626755658785896 + ], + [ + -0.339889526367188, + 51.63080491955375 + ], + [ + -0.338172912597656, + 51.6295262446738 + ], + [ + -0.3350830078125, + 51.631657349449995 + ], + [ + -0.335082862645118, + 51.631657349449995 + ], + [ + -0.328903198242188, + 51.63591925865103 + ], + [ + -0.319290161132812, + 51.63847621195151 + ], + [ + -0.316543579101562, + 51.6406068962452 + ], + [ + -0.304527282714844, + 51.63634542754579 + ], + [ + -0.296287536621094, + 51.635493085751705 + ], + [ + -0.273628234863281, + 51.63868928488591 + ], + [ + -0.272941589355469, + 51.64209831568502 + ], + [ + -0.268135070800781, + 51.64231137160061 + ], + [ + -0.268478393554688, + 51.643802734979374 + ], + [ + -0.264358520507812, + 51.64358968607138 + ], + [ + -0.263328552246094, + 51.644867964503305 + ], + [ + -0.257148742675781, + 51.641885258768326 + ], + [ + -0.251655578613281, + 51.647424413252224 + ], + [ + -0.250625610351562, + 51.65615785885859 + ], + [ + -0.247879028320312, + 51.6553058894589 + ], + [ + -0.228996276855469, + 51.659991522965925 + ], + [ + -0.226593017578125, + 51.65722279808634 + ], + [ + -0.219383239746094, + 51.66084340428125 + ], + [ + -0.219039916992188, + 51.659991522965925 + ], + [ + -0.213546752929688, + 51.66233415804706 + ], + [ + -0.212173461914062, + 51.661269338933266 + ], + [ + -0.208053588867188, + 51.66276007868612 + ], + [ + -0.211143493652344, + 51.66701906487643 + ], + [ + -0.208053588867188, + 51.66659318427355 + ], + [ + -0.205650329589844, + 51.668509615458674 + ], + [ + -0.202217102050781, + 51.66787081407156 + ], + [ + -0.2032470703125, + 51.6702130417861 + ], + [ + -0.199813842773438, + 51.6702130417861 + ], + [ + -0.199127197265625, + 51.66829668266385 + ], + [ + -0.19500732421875, + 51.66829668266385 + ], + [ + -0.196723937988281, + 51.66552846525079 + ], + [ + -0.191230773925781, + 51.663824862767655 + ], + [ + -0.187797546386719, + 51.66787081407156 + ], + [ + -0.181961059570312, + 51.668509615458674 + ], + [ + -0.177154541015625, + 51.67276806117448 + ], + [ + -0.172348022460938, + 51.67319388372741 + ], + [ + -0.163764953613281, + 51.68234810033195 + ], + [ + -0.163421630859375, + 51.68809515107952 + ], + [ + -0.148658752441406, + 51.685540996368815 + ], + [ + -0.136985778808594, + 51.68852082952131 + ], + [ + -0.121536254882812, + 51.68852082952131 + ], + [ + -0.104970456942527, + 51.6918740874324 + ], + [ + -0.104242171535543, + 51.6918740874324 + ], + [ + -0.07965087890625, + 51.68915933967864 + ], + [ + -0.067291259765625, + 51.684051006239144 + ], + [ + -0.0604248046875, + 51.68277383281327 + ], + [ + -0.049095153808594, + 51.684263864974156 + ], + [ + -0.02197265625, + 51.68183987462995 + ], + [ + -0.02197265625, + 51.68192236384763 + ], + [ + -0.010986328125, + 51.68085800512344 + ] + ] + ] + ] + } + } + } + ] +} diff --git a/tests/test_maps.py b/tests/test_maps.py new file mode 100644 index 0000000..a98b249 --- /dev/null +++ b/tests/test_maps.py @@ -0,0 +1,144 @@ +import json + +from datawrapper import Datawrapper + + +def test_locator_map_points(): + """Test locator maps with points.""" + # Connect + dw = Datawrapper() + + # Create a map + obj = dw.create_chart( + "My locator map with points", + "locator-map", + ) + + # Set map metadata + metadata = { + "data": {"json": True}, + "visualize": { + "view": { + "center": [-0.106, 51.523], + "zoom": 8, + "fit": { + "top": [0.176, 53.408], + "right": [1.368, 51.779], + "bottom": [0.241, 51.1425], + "left": [-0.920, 51.754], + }, + "height": 120, + "pitch": 0, + "bearing": 0, + }, + "style": "dw-light", + "defaultMapSize": 500, + "visibility": { + "boundary_country": True, + "boundary_state": True, + "building": True, + "green": True, + "mountains": True, + "roads": True, + "urban": True, + "water": True, + "building3d": True, + }, + "mapLabel": True, + "scale": False, + "compass": False, + "miniMap": {"enabled": False, "bounds": []}, + "key": {"enabled": False, "title": "", "items": []}, + }, + } + dw.update_chart(obj["id"], metadata=metadata) + + # Add markers + data = { + "markers": [ + { + "type": "point", + "title": "Buckingham Palace", + "icon": { + "path": "M1000 350a500 500 0 0 0-500-500 500 500 0 0 0-500 500 500 500 0 0 0 500 500 500 500 0 0 0 500-500z", + "height": 700, + "width": 1000, + }, + "scale": 1, + "markerColor": "#cc0000", + "anchor": "bottom-right", + "offsetY": 0, + "offsetX": 0, + "text": {"color": "#333333", "fontSize": 15, "halo": "#f2f3f0"}, + "rotate": 0, + "visible": True, + "visibility": {"mobile": True, "desktop": True}, + "coordinates": [-0.140634, 51.501476], + "tooltip": { + "text": "Some information about Buckingham Palace that shows up when hovering over the marker" + }, + } + ] + } + + # Post it + dw.add_json(obj["id"], data) + + +def test_locator_map_areas(): + """Test locator maps with areas.""" + # Connect + dw = Datawrapper() + + # Create a map + obj = dw.create_chart( + "My locator map with areas", + "locator-map", + ) + + # Open markers + with open("./tests/area_markers.json") as f: + data = json.load(f) + + # Add markers + dw.add_json(obj["id"], data) + + +def test_locator_map_lines(): + """Test locator maps with lines.""" + # Connect + dw = Datawrapper() + + # Create a map + obj = dw.create_chart( + "My locator map with lines", + "locator-map", + ) + + # Add markers + data = { + "markers": [ + { + "id": "m1", + "title": "Line Marker", + "type": "line", + "visible": True, + "properties": { + "stroke": "#fa8c00", + "stroke-width": 3, + "stroke-opacity": 1, + "stroke-dasharray": "100000", + }, + "visibility": {"mobile": True, "desktop": True}, + "feature": { + "type": "Feature", + "properties": [], + "geometry": { + "type": "LineString", + "coordinates": [[-74.006, 40.7128], [-80.2994982, 25.7823907]], + }, + }, + } + ] + } + dw.add_json(obj["id"], data)