Skip to content

Commit

Permalink
✨ add emphasis to map (pyecharts#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw authored Jun 9, 2019
1 parent ada2b5d commit 0e61605
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pyecharts/charts/basic_charts/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def add(
label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(),
tooltip_opts: Union[opts.TooltipOpts, dict, None] = None,
itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None,
emphasis_label_opts: Union[opts.LabelOpts, dict] = None,
emphasis_itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None,
):
self.js_dependencies.add(maptype)
data = [{"name": n, "value": v} for n, v in data_pair]
Expand All @@ -49,6 +51,10 @@ def add(
"showLegendSymbol": is_map_symbol_show,
"tooltip": tooltip_opts,
"itemStyle": itemstyle_opts,
"emphasis": {
"label": emphasis_label_opts,
"itemStyle": emphasis_itemstyle_opts
}
}
)
return self
18 changes: 18 additions & 0 deletions test/test_map.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from unittest.mock import patch

import json
from nose.tools import eq_

from example.commons import Faker
from pyecharts.charts import Map
from pyecharts import options as opts


@patch("pyecharts.render.engine.write_utf8_html_file")
Expand All @@ -15,3 +17,19 @@ def test_map_base(fake_writer):
_, content = fake_writer.call_args[0]
eq_(c.theme, "white")
eq_(c.renderer, "canvas")


def test_map_emphasis():
c = Map().add(
"商家A",
[list(z) for z in zip(Faker.provinces, Faker.values())],
"china",
emphasis_label_opts=opts.LabelOpts(is_show=False),
emphasis_itemstyle_opts=opts.ItemStyleOpts(border_color="white"),
)
options = json.loads(c.dump_options())
expected = {
"label": {"show": False, "position": "top", "margin": 8},
"itemStyle": {"borderColor": "white"},
}
eq_(expected, options["series"][0]["emphasis"])

0 comments on commit 0e61605

Please sign in to comment.