Skip to content

Commit

Permalink
fix #72
Browse files Browse the repository at this point in the history
  • Loading branch information
laowantong committed Dec 24, 2022
1 parent d599daf commit e39508d
Show file tree
Hide file tree
Showing 12 changed files with 3,181 additions and 2,532 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
**24 décembre 2022.** Mocodo 3.1.1 corrige la [gestion des collisions des SVG interactifs](https://rawgit.com/laowantong/mocodo/master/doc/fr_refman.html#Éviter-qu'une-interaction-sur-un-SVG-ne-s'applique-à-un-autre).

**14 décembre 2022.** Mocodo 3.1 améliore le passage au relationnel : prise en charge de [gabarits personnels dérivés des gabarits existants](https://rawgit.com/laowantong/mocodo/master/doc/fr_refman.html#Dérivation-de-gabarits), traitement des [tables indépendantes réduites à leur clé primaire](https://rawgit.com/laowantong/mocodo/master/doc/fr_refman.html#Suppression-des-tables-indépendantes-réduites-à-leur-clé-primaire), génération d'un [graphe des dépendances](https://rawgit.com/laowantong/mocodo/master/doc/fr_refman.html#Graphe-des-dépendances) pour le tri topologique des tables, [etc](https://github.com/laowantong/mocodo/releases/tag/3.1.0).

**11 septembre 2022.** Mocodo 3.0 introduit l'[héritage](https://rawgit.com/laowantong/mocodo/master/doc/fr_refman.html#Héritage-(ou-spécialisation)), l'[agrégation](https://rawgit.com/laowantong/mocodo/master/doc/fr_refman.html#Agrégation-(ou-pseudo-entité)), les [calques](https://rawgit.com/laowantong/mocodo/master/doc/fr_refman.html#Héritage-(ou-spécialisation)), les [sorties PDF et PNG](https://rawgit.com/laowantong/mocodo/master/doc/fr_refman.html#Héritage-(ou-spécialisation)), [etc](https://github.com/laowantong/mocodo/releases/tag/3.0).
Expand Down
2,739 changes: 1,482 additions & 1,257 deletions doc/fr_refman.html

Large diffs are not rendered by default.

2,694 changes: 1,433 additions & 1,261 deletions doc/fr_refman.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h2>Manipuler les schémas</h2>
</form>
</div>
<div id="navigation">
<a target="_blank" href="https://github.com/laowantong/mocodo">Mocodo 3.1.0</a>
<a target="_blank" href="https://github.com/laowantong/mocodo">Mocodo 3.1.1</a>
&nbsp;∙&nbsp;
<a target="_blank" href="https://rawgit.com/laowantong/mocodo/master/doc/fr_refman.html">Documentation</a>
&nbsp;∙&nbsp;
Expand Down
7 changes: 7 additions & 0 deletions mocodo/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@ def add_key(key, value):
action="store_true",
help="reuse the geometry file of the previous execution",
)
io_group.add_argument(
"--uid_suffix",
metavar="INT",
type=non_negative_integer,
default=0,
help="discriminate between multiple SVG of the same interactive diagram",
)

source_group.add_argument(
"--arrange",
Expand Down
9 changes: 9 additions & 0 deletions mocodo/mcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import itertools
import re
from collections import defaultdict
from hashlib import md5

from .association import Association
from .diagram_link import DiagramLink
Expand All @@ -19,6 +20,13 @@ class Mcd:

def __init__(self, clauses, get_font_metrics=None, **params):

def calculate_uid():
h = md5("".join(clauses).encode("utf-8")).hexdigest()
if params.get("uid_suffix"):
return f"{h[:8]}_{params['uid_suffix']}"
else:
return h[:8]

def parse_clauses():
self.entities = {}
self.associations = {}
Expand Down Expand Up @@ -180,6 +188,7 @@ def substitute_forbidden_symbols_between_brackets(text):

self.get_font_metrics = get_font_metrics
phantom_counter = itertools.count()
self.uid = calculate_uid()
parse_clauses()
add_legs()
add_attributes()
Expand Down
20 changes: 10 additions & 10 deletions mocodo/mcd_to_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ def svg2png(**kargs):

from .common import safe_print_for_PHP

ID_CHARACTERS = string.ascii_letters + string.digits

def main(mcd, common):
style = common.load_style()
mcd_uid = ''.join(random.choice(ID_CHARACTERS) for _ in range(8))
mcd.calculate_size(style)
geo = common.calculate_or_retrieve_geo(mcd, reuse_geo=common.params["reuse_geo"])
description = [
Expand All @@ -45,7 +42,7 @@ def main(mcd, common):
categories = {"": [], "Association": [], "Entity": [], "Link": [], "Notes": [], "Pager": []}
category = ""
for (key, mapping) in description:
mapping["mcd_uid"] = mcd_uid
mapping["mcd_uid"] = mcd.uid
has_note_card |= key.endswith("with_note")
if key == "comment":
category = mapping["text"].partition(" ")[0]
Expand All @@ -63,10 +60,13 @@ def main(mcd, common):
if common.params["hide_notes"] or not has_note_card:
del categories["Notes"]
text = "\n".join(sum(categories.values(), [])) + "\n</svg>"
is_interactive = categories.get("Notes") or categories.get("Pager")
if not is_interactive:
text = re.sub(r'<g class="page_0_\w{8}(_\d+)? diagram_page" visibility="visible">', "<g>", text)
path = Path(f"{common.params['output_name']}.svg")
path.write_text(text, encoding="utf8")
safe_print_for_PHP(common.output_success_message(path))
if categories.pop("Notes", []) + categories.pop("Pager"): # don't use or to avoid short-circuit
if categories.pop("Notes", []) + categories.pop("Pager"): # don't use `or` to avoid short-circuit
text = "\n".join(sum(categories.values(), [])) + "\n</svg>"
text = re.sub(
r"(?m)^<\?xml .+\n<svg .+",
Expand Down Expand Up @@ -106,15 +106,15 @@ def html_escape(
"begin_group": """<g>""",
"end": """</g>""",
"text": """<text x="{x}" y="{y}" fill="{text_color}" font-family="{family}" font-size="{size}">{text}</text>""",
"text_with_note": """<text x="{x}" y="{y}" fill="{text_color}" font-family="{family}" font-size="{size}" onmouseover="show(evt,'{note}')" onmouseout="hide(evt)" style="cursor: pointer;">{text}</text>""",
"text_with_note": """<text x="{x}" y="{y}" fill="{text_color}" font-family="{family}" font-size="{size}" onmouseover="show_{mcd_uid}(evt,'{note}')" onmouseout="hide_{mcd_uid}(evt)" style="cursor: pointer;">{text}</text>""",
"line": """<line x1="{x0}" y1="{y0}" x2="{x1}" y2="{y1}" stroke="{stroke_color}" stroke-width="{stroke_depth}"/>""",
"dash_line": """<line x1="{x0}" y1="{y0}" x2="{x1}" y2="{y1}" stroke="{stroke_color}" stroke-width="{stroke_depth}" stroke-dasharray="{dash_width}"/>""",
"rect": """<rect x="{x}" y="{y}" width="{w}" height="{h}" fill="{color}" stroke="{stroke_color}" stroke-width="{stroke_depth}" opacity="{opacity}"/>""",
"dash_rect": """<rect x="{x}" y="{y}" width="{w}" height="{h}" fill="{color}" stroke="{stroke_color}" stroke-width="{stroke_depth}" stroke-dasharray="{dash_width}"/>""",
"polygon": """<polygon points="{points}" fill="{color}" stroke="{stroke_color}" stroke-width="{stroke_depth}" opacity="{opacity}"/>""",
"dot_polygon": """<polygon points="{points}" fill="{color}" stroke="{stroke_color}" stroke-width="{stroke_depth}" stroke-dasharray="0,{dash_gap}" stroke-linecap="round"/>""",
"circle": """<circle cx="{cx}" cy="{cy}" r="{r}" stroke="{stroke_color}" stroke-width="{stroke_depth}" fill="{color}"/>""",
"pager_dot": """<circle cx="{cx}" cy="{cy}" r="{r}" fill="{color}" id="pager_dot_{page}_{mcd_uid}" class="pager_dot" stroke-width="0" onclick="switch_page_visibility(evt,{page})" style="cursor: pointer;"/>""",
"pager_dot": """<circle cx="{cx}" cy="{cy}" r="{r}" fill="{color}" id="pager_dot_{page}_{mcd_uid}" class="pager_dot" stroke-width="0" onclick="switch_page_visibility_{mcd_uid}(evt,{page})" style="cursor: pointer;"/>""",
"triangle": """<polygon points="{x1} {y1} {x2} {y2} {x3} {y3}" stroke="{stroke_color}" stroke-width="{stroke_depth}" fill="{color}"/>""",
"arrow": """<polygon points="{x0} {y0} {x1} {y1} {x2} {y2} {x3} {y3}" fill="{stroke_color}" stroke-width="0"/>""",
"curve": """<path d="M{x0} {y0} C{x1} {y1} {x2} {y2} {x3} {y3}" fill="none" stroke="{stroke_color}" stroke-width="{stroke_depth}"/>""",
Expand All @@ -123,14 +123,14 @@ def html_escape(
"lower_round_rect": """<path d="M{x0} {y0} v{y1} a{r} {r} 90 0 1 -{r} {r} H{x1} a{r} {r} 90 0 1 -{r} -{r} V{y0} H{w}" fill="{color}" stroke="{stroke_color}" stroke-width="{stroke_depth}"/>""",
"notes": """<script type="text/ecmascript">
<![CDATA[
function show(evt, text) {{
function show_{mcd_uid}(evt, text) {{
var pos = (evt.target.getAttribute("y") < {height_threshold}) ? "bottom" : "top";
var note = document.getElementById(pos + "_note_{mcd_uid}");
note.textContent = text;
note.setAttributeNS(null, "visibility", "visible");
document.getElementById(pos + "_overlay_{mcd_uid}").setAttributeNS(null, "visibility", "visible");
}}
function hide(evt) {{
function hide_{mcd_uid}(evt) {{
document.getElementById("top_note_{mcd_uid}").setAttributeNS(null, "visibility", "hidden");
document.getElementById("top_overlay_{mcd_uid}").setAttributeNS(null, "visibility", "hidden");
document.getElementById("bottom_note_{mcd_uid}").setAttributeNS(null, "visibility", "hidden");
Expand All @@ -144,7 +144,7 @@ def html_escape(
<text id="bottom_note_{mcd_uid}" text-anchor="middle" x="{x}" y="{y_bottom}" fill="{text_color}" font-family="{font_family}" font-size="{font_size}" visibility="hidden"></text>""".replace(" ", ""),
"pager": """<script type="text/ecmascript">
<![CDATA[
function switch_page_visibility(evt, page) {{
function switch_page_visibility_{mcd_uid}(evt, page) {{
for (var i = 0; i < {page_count}; i++) {{
components = document.getElementsByClassName(`page_${{i}}_{mcd_uid}`);
for (var j = 0; j < components.length; j++) {{
Expand Down
2 changes: 1 addition & 1 deletion mocodo/version_number.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "3.1.0"
version = "3.1.1"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mocodo"
version = "3.1.0"
version = "3.1.1"
description = "Modélisation Conceptuelle de Données. Nickel. Ni souris."
authors = ["Aristide Grange"]
license = "MIT"
Expand Down
6 changes: 6 additions & 0 deletions test/snapshots/snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ ENCLOS: num. enclos

## SVG output

### Static

![](snapshot_static.svg)

### Dynamic

![](snapshot.svg)

## Relational output

### `debug.json`
Expand Down
Loading

0 comments on commit e39508d

Please sign in to comment.