Coverage for gws-app/gws/plugin/legend/html/__init__.py: 0%

16 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""HTML legend. 

2 

3Renders an HTML template to a PNG image, which is used as the legend. 

4 

5Example:: 

6 

7 legend { 

8 type "html" 

9 template { 

10 type "html" 

11 text "<p>Legend</p>" 

12 } 

13 } 

14""" 

15 

16import gws 

17import gws.base.legend 

18import gws.lib.image 

19import gws.lib.mime 

20 

21 

22@gws.ext.config.legend('html') 

23class Config(gws.base.legend.Config): 

24 """Legend rendered from an HTML template.""" 

25 

26 template: gws.ext.config.template 

27 """Template for the HTML legend.""" 

28 

29 

30@gws.ext.object.legend('html') 

31class Object(gws.base.legend.Object): 

32 """HTML legend.""" 

33 

34 template: gws.Template 

35 """Template for the legend.""" 

36 

37 def configure(self): 

38 self.template = self.create_child(gws.ext.object.template, self.cfg('template')) 

39 

40 def render(self, args=None): 

41 # @TODO return html legends as html 

42 res = self.template.render(gws.TemplateRenderInput( 

43 args=args, 

44 mimeOut=gws.lib.mime.PNG)) 

45 img = gws.lib.image.from_path(res.contentPath) 

46 return gws.LegendRenderOutput(image=img, size=img.size())