Skip to content
Merged
Show file tree
Hide file tree
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
37 changes: 36 additions & 1 deletion CONTRIBUTING.md

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the liberty to also expand a bit the CONTRIBUTING file

Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
### General guidelines

<a href="https://github.com/ewoks-kit/.github/blob/main/shared/CONTRIBUTING.md" target="_blank">CONTRIBUTING.md</a>

### Pixi

This project is managed by [Pixi](https://pixi.prefix.dev/) with a single environment (`default`).

We reproduce below the most relevant commands. For more, see [Pixi's Getting Started](https://pixi.prefix.dev/latest/getting_started/)

#### Install the project

```bash
pixi install
pixi update
```

#### Run the tests

```bash
pixi run test
pixi run test-lowest
pixi run lint
pixi run typecheck
pixi run full-ci
pixi run graph-to-svg acyclic1
```

#### Run the example

Turn a workflow into a SVG

```
pixi run graph-to-svg <workflow_path>
```

If `workflow_name` is not given, `ewoksdraw` will use a test workflow.


#### Add dependencies

```bash
pixi add <package_name>
```

By default, this will install the conda package (if there is one). To install from PyPI:

```bash
pixi add --pypi <package_name>
```
2 changes: 1 addition & 1 deletion src/ewoksdraw/css_styles/css_background.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.background {
fill: #000000;
fill: var(--bg-color);
}
2 changes: 1 addition & 1 deletion src/ewoksdraw/css_styles/css_link_cubic_bezier.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.link_cubic_bezier {
fill: none;
stroke: #ffffff;
stroke: var(--stroke-color);
stroke-width: 1.5;
stroke-linecap: round;
stroke-linejoin: round;
Expand Down
2 changes: 1 addition & 1 deletion src/ewoksdraw/css_styles/css_task_anchor_link.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.task_anchor_link {
fill: rgb(176, 147, 255);
fill: var(--link-color);
}
7 changes: 3 additions & 4 deletions src/ewoksdraw/css_styles/css_task_box.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.task_box {
fill: #00000000;
stroke: rgb(255, 255, 255);
stroke-width: 0.2%;
fill: var(--transparent);
stroke: var(--stroke-color);
stroke-width: var(--stroke-width);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--stroke-width is now shared between css_task_box and css_task_line.
The values were different prior to the change (1 vs 0.2 %). Should we create a separate variable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes. Well, it depends: do we want the box and the line to have both the same stroke width or not?

I'd think it would be more consistent to have the same but perhaps you had something else in mind when you designed it earlier?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it like that for now.
Anyway, if we want to tone it down an easier way, it is to change the color.
image

rx: 0.5%;
ry: 0.5%;
}

7 changes: 3 additions & 4 deletions src/ewoksdraw/css_styles/css_task_line.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.task_line {
stroke: #ffffff;
stroke-width: 1;
stroke-dasharray: none;
}
stroke: var(--stroke-color);
stroke-width: var(--stroke-width);
}
2 changes: 1 addition & 1 deletion src/ewoksdraw/css_styles/css_task_text_io.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.task_text_io {
font-family: Helvetica, sans-serif;
fill: rgb(255, 255, 255);
fill: var(--text-color);
}
2 changes: 1 addition & 1 deletion src/ewoksdraw/css_styles/css_task_title.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.task_title {
font-family: Helvetica, sans-serif;
fill: rgb(255, 255, 255);
fill: var(--text-color);
}
8 changes: 8 additions & 0 deletions src/ewoksdraw/css_styles/root.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.ewoksdraw {
--bg-color: rgb(0, 0, 0);
--link-color: rgb(176, 147, 255);
--stroke-color: rgb(255, 255, 255);
--stroke-width: 1;
--text-color: rgb(255, 255, 255);
--transparent: rgba(0, 0, 0, 0)
}
7 changes: 6 additions & 1 deletion src/ewoksdraw/svg/svg_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .svg_background import SvgBackground
from .svg_element import SvgElement
from .svg_group import SvgGroup
from .utils import generate_style_element

Number = Union[int, float]

Expand Down Expand Up @@ -96,6 +97,7 @@ def _generate_xml_svg(self) -> Element:
width=str(self.width),
height=str(self.height),
)
xml_svg.set("class", "ewoksdraw")

style_elements = self._gather_all_styles()
seen_styles = set()
Expand Down Expand Up @@ -136,4 +138,7 @@ def _gather_all_styles(self) -> List[Element]:
for element in self.elements:
all_styles.extend(self._yield_styles(element))

return all_styles
root_element = generate_style_element("root.css")
if root_element is None:
return all_styles
return [root_element, *all_styles]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how I add the new root.css file to the other styles.

13 changes: 3 additions & 10 deletions src/ewoksdraw/svg/svg_element.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import warnings
from pathlib import Path
from typing import Literal
from typing import Optional
from typing import get_args
from xml.etree.ElementTree import Element

from .utils import generate_style_element

SvgTag = Literal["rect", "circle", "text", "line", "path"]
SUPPORTED_TAGS: tuple[SvgTag, ...] = get_args(SvgTag)

Expand Down Expand Up @@ -125,12 +126,4 @@ def _load_css_style(self) -> Optional[Element]:
if not self._css_class:
return None

css_file_path = Path(f"src/ewoksdraw/css_styles/css_{self._css_class}.css")
if not css_file_path.exists():
return None

with open(css_file_path, "r") as css_file:
css_content = css_file.read()
style = Element("style")
style.text = f"<![CDATA[\n{css_content}\n]]>"
return style
return generate_style_element(css_file_name=f"css_{self._css_class}.css")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this slightly with the introduction of generate_style_element to be able to reuse the CSS loading for root.css

1 change: 0 additions & 1 deletion src/ewoksdraw/svg/svg_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __init__(
list_io=output_names, io_type="output", vertical_spacing=8
)
self._line_title = SvgTaskLine(x1=0, y1=0, x2=0, y2=0)

self._init_elements()

def _init_elements(self) -> None:
Expand Down
16 changes: 16 additions & 0 deletions src/ewoksdraw/svg/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pathlib import Path
from xml.etree.ElementTree import Element

CSS_DIR = Path(__file__).parent.parent / "css_styles"


def generate_style_element(css_file_name: str) -> None | Element:
css_file_path = CSS_DIR / css_file_name
if not css_file_path.exists():
return None

with open(css_file_path, "r") as css_file:
css_content = css_file.read()
style = Element("style")
style.text = f"<![CDATA[\n{css_content}\n]]>"
return style
Loading