Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add String indicator #1590

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions panel/widgets/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,38 @@ def _process_param_change(self, msg):
return msg


class String(ValueIndicator):
"""
The String indicator renders a string with a title.
"""

default_color = param.String(default='black')

font_size = param.String(default='54pt')

title_size = param.String(default='18pt')

value = param.String(default=None)

_rename = {}

_widget_type = HTML

def _process_param_change(self, msg):
msg = super()._process_param_change(msg)
font_size = msg.pop('font_size', self.font_size)
title_font_size = msg.pop('title_size', self.title_size)
name = msg.pop('name', self.name)
value = msg.pop('value', self.value)
color = msg.pop('default_color', self.default_color)
text = f'<div style="font-size: {font_size}; color: {color}">{value}</div>'
if self.name:
title_font_size = msg.pop('title_size', self.title_size)
text = f'<div style="font-size: {title_font_size}; color: {color}">{name}</div>\n{text}'
msg['text'] = escape(text)
return msg


class Gauge(ValueIndicator):
"""
A Gauge represents a value in some range as a position on
Expand Down