Skip to content

Commit

Permalink
fixes popup regression
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Jan 19, 2024
1 parent b6c1824 commit cb9aed1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions dcm/dcm_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def generate_svg_from_segments(
str: The SVG markup.
"""
if config is None:
config = SVGConfig() # Use default configuration if none provided
config = SVGConfig(with_popup=True) # Use default configuration if none provided
svg = self.prepare_and_add_inner_circle(config, competence_tree=competence_tree)
# Pre-calculate segments for the competence tree
segments_by_path = self.precalculate_segments(competence_tree)
Expand Down Expand Up @@ -163,7 +163,7 @@ def generate_svg(
str: The SVG markup.
"""
if config is None:
config = SVGConfig() # Use default configuration if none provided
config = SVGConfig(with_popup=True) # Use default configuration if none provided
svg_markup = self.generate_svg_markup(
self.dcm.competence_tree,
learner=learner,
Expand Down
10 changes: 6 additions & 4 deletions dcm/dcm_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,15 @@ def render_dcm(
self.dcm = dcm
self.assessment_button.enable()
dcm_chart = DcmChart(dcm)
svg = dcm_chart.generate_svg_markup(
svg_markup = dcm_chart.generate_svg_markup(
learner=learner,
selected_paths=selected_paths,
config=self.svg.config,
with_java_script=False,
text_mode=self.text_mode,
)
# Use the new get_java_script method to get the JavaScript
self.svg_view.content = svg
self.svg_view.content = svg_markup,
self.svg_view.update()
except Exception as ex:
self.handle_exception(ex, self.do_trace)
Expand All @@ -276,8 +277,9 @@ async def home(self, _client: Client):
"""Generates the home page with a selection of examples and
svg display
"""
svg = SVG()
java_script = svg.get_java_script()
config=SVGConfig(with_popup=True)
self.svg = SVG(config=config)
java_script = self.svg.get_java_script()

# Add the script using ui.add_head_html()
ui.add_head_html(java_script)
Expand Down
14 changes: 6 additions & 8 deletions dcm/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ class SVGConfig:
font_size (int): Font size in points for text elements.
indent (str): Indentation string, default is two spaces.
default_color (str): Default color code for SVG elements.
with_pop(bool): if True support popup javascript functionality
"""

width: int = 600
height: int = 600
legend_height: int = 150
font: str = "Arial"
font_size: int = 12
indent: str = " "
default_color: str = "#C0C0C0"
with_popup: bool=False

@property
def total_height(self) -> int:
Expand Down Expand Up @@ -229,13 +230,10 @@ def get_indent(self, level) -> str:
indentation = f"{self.indent * level}"
return indentation

def get_svg_style(self, with_java_script: bool) -> str:
def get_svg_style(self) -> str:
"""
Define styles for SVG elements.
Args:
with_java_script (bool): Flag to indicate whether JavaScript-related styles should be included.
Returns:
str: String containing style definitions for SVG.
"""
Expand All @@ -247,7 +245,7 @@ def get_svg_style(self, with_java_script: bool) -> str:
f"{self.indent * 2}.noclick {{ pointer-events: none; }}\n" # style for non-clickable text
)

if with_java_script:
if self.config.with_popup:
style += (
f"{self.indent * 2}.popup {{\n"
f"{self.indent * 3}border: 2px solid black;\n"
Expand Down Expand Up @@ -732,10 +730,10 @@ def get_svg_markup(self, with_java_script: bool = False) -> str:
</body>
</foreignObject>
"""
if with_java_script
if self.config.with_popup
else ""
)
styles = self.get_svg_style(with_java_script)
styles = self.get_svg_style()
body = "".join(self.elements)
footer = "</svg>"
java_script = self.get_java_script() if with_java_script else ""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_svg_render(self):
test the rendering
"""
path = "/svg"
svg_config = SVGConfig(width=666, height=666)
svg_config = SVGConfig(width=666, height=666,with_popup=True)
for markup, examples in self.example_definitions.items():
for name, definition in examples.items():
data = {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_competence_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def testCompetenceMap(self):
for example_name, dcm in examples.items():
# Now you can perform assertions to verify that the data was loaded correctly
self.assertIsNotNone(dcm.competence_tree)
svg_config = SVGConfig()
svg_config = SVGConfig(with_popup=True)
svg_config.legend_height = 40 * len(dcm.competence_tree.levels)
svg_path = "/tmp/dcm-test"
os.makedirs(svg_path, exist_ok=True)
Expand All @@ -159,7 +159,7 @@ def test_generate_svg_from_segments(self):
dcm_chart = DcmChart(dcm)

# Generate SVG markup
svg_config = SVGConfig()
svg_config = SVGConfig(with_popup=True)
svg_markup = dcm_chart.generate_svg_from_segments(
dcm.competence_tree, config=svg_config
)
Expand Down

0 comments on commit cb9aed1

Please sign in to comment.