Skip to content

Commit

Permalink
🩹 fix overlay items on vega charts being cut-off, use markdown in des…
Browse files Browse the repository at this point in the history
…cription
  • Loading branch information
krmax44 committed Nov 4, 2024
1 parent 83c60bc commit f36be6c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
4 changes: 3 additions & 1 deletion fragdenstaat_de/fds_cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ def __str__(self):

class VegaChartCMSPlugin(CMSPlugin):
title = models.CharField(max_length=255, blank=True)
description = models.TextField(blank=True)
description = models.TextField(
blank=True, help_text=_("Formatting with Markdown is supported.")
)

vega_json = models.TextField(
default="",
Expand Down
8 changes: 5 additions & 3 deletions fragdenstaat_de/fds_cms/templates/fds_cms/vega_chart.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{% load static %}
{% load sekizai_tags %}
{% load markup %}
<div class="vega-chart">
{% if instance.title %}<h5>{{ instance.title }}</h5>{% endif %}
{% if instance.description %}<p>{{ instance.description|linebreaksbr }}</p>{% endif %}
<div data-vegachart data-vegachartdata="{{ instance.vega_json }}"></div>
{% if instance.description %}{{ instance.description|markdown }}{% endif %}
<div class="w-100"
data-vegachart
data-vegachartdata="{{ instance.vega_json }}"></div>
</div>
{% include "_frontend.html" with entry_point="vegacharts.js" %}
4 changes: 2 additions & 2 deletions frontend/javascript/vegacharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const bootstrapTooltipHandler = (handler, event, item, value) => {
let tooltip = Tooltip.getInstance(item._svg)
let created = false
if (!tooltip && value) {
let html = `<dl>${Object.keys(value)
const html = `<dl>${Object.keys(value)
.map((key) => `<dt>${key}</dt><dd>${value[key]}</dd>`)
.join('')}</dl>`

Expand All @@ -128,7 +128,7 @@ document.querySelectorAll('[data-vegachart]').forEach((el) => {
} else {
spec = JSON.parse(document.getElementById(el.dataset.vegachart).textContent)
}
let hasData =
const hasData =
(spec.data && (spec.data.url || spec.data.values)) || spec.datasets
if (!hasData) {
const data = JSON.parse(
Expand Down
20 changes: 0 additions & 20 deletions frontend/styles/vega.scss
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";

.vega-chart {
overflow: hidden;
width: 100%;
}
.vega-embed > svg {
width: 100%;
height: 100%;
}
.vega-embed {
width: 100%;
}

#vg-tooltip-element {
background-color: var(--#{$prefix}body-bg);
border: 1px solid var(--#{$prefix}tertiary-bg);
color: var(--#{$prefix}body-color);

td.key {
color: var(--#{$prefix}secondary-color);
}
}

0 comments on commit f36be6c

Please sign in to comment.