Skip to content

Commit

Permalink
feat: added color customization
Browse files Browse the repository at this point in the history
  • Loading branch information
tsypuk committed Aug 16, 2023
1 parent b1610d6 commit f58c658
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 5 deletions.
86 changes: 86 additions & 0 deletions docs/docs/core-components/colors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
layout: default
title: Customization
parent: CORE Components
nav_order: 3
date: 2023-08-16
---

# Customization
{: .d-inline-block }

New (v0.3.10)
{: .label .label-green }


## Code Snippet:

```python
{% root_include_snippet ../tests/core/test_colors.py color_red%}
```

## Rendering:

![layers](output/jpg/color_red.jpg)

### Full XML dump:

```xml
{% root_include docs/core-components/output/drawio/color_red.drawio%}
```

### drawio file:

Download generated ``color_red.drawio``:

[Download](output/drawio/color_red.drawio){: .btn .btn-purple }


## Code Snippet:

```python
{% root_include_snippet ../tests/core/test_colors.py color_blue%}
```

## Rendering:

![layers](output/jpg/color_blue.jpg)

### Full XML dump:

```xml
{% root_include docs/core-components/output/drawio/color_blue.drawio%}
```

### drawio file:

Download generated ``color_blue.drawio``:

[Download](output/drawio/color_blue.drawio){: .btn .btn-purple }


## Code Snippet:

```python
{% root_include_snippet ../tests/core/test_colors.py color_table%}
```

## Rendering:

![layers](output/jpg/color_table.jpg)

### Full XML dump:

```xml
{% root_include docs/core-components/output/drawio/color_table.drawio%}
```

### drawio file:

Download generated ``color_table.drawio``:

[Download](output/drawio/color_table.drawio){: .btn .btn-purple }




1 change: 1 addition & 0 deletions docs/docs/core-components/output/drawio/color_blue.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="multicloud-diagrams" agent="PIP package multicloud-diagrams. Generate resources in draw.io compatible format for Cloud infrastructure. Copyrights @ Roman Tsypuk 2023. MIT license." type="MultiCloud"><diagram id="diagram_1" name="AWS components"><mxGraphModel dx="1015" dy="661" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="1"><root><mxCell id="0" /><mxCell id="1" parent="0" /><mxCell id="vertex:lambda_function:arn:aws:lambda:eu-west-1:123456789012:function:prod-lambda-name" value="&lt;b&gt;Name&lt;/b&gt;: prod-lambda-name&lt;BR&gt;&lt;b&gt;ARN&lt;/b&gt;: arn:aws:lambda:eu-west-1:123456789012:function:prod-lambda-name" style="verticalLabelPosition=bottom;verticalAlign=top;aspect=fixed;align=left;pointerEvents=1;shape=mxgraph.aws3.lambda_function;prIcon=server;fillColor=#0000FF;gradientColor=none;html=1;" parent="1" vertex="1"><mxGeometry width="69" height="72" as="geometry" /></mxCell></root></mxGraphModel></diagram></mxfile>
1 change: 1 addition & 0 deletions docs/docs/core-components/output/drawio/color_red.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="multicloud-diagrams" agent="PIP package multicloud-diagrams. Generate resources in draw.io compatible format for Cloud infrastructure. Copyrights @ Roman Tsypuk 2023. MIT license." type="MultiCloud"><diagram id="diagram_1" name="AWS components"><mxGraphModel dx="1015" dy="661" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="1"><root><mxCell id="0" /><mxCell id="1" parent="0" /><mxCell id="vertex:lambda_function:arn:aws:lambda:eu-west-1:123456789012:function:prod-lambda-name" value="&lt;b&gt;Name&lt;/b&gt;: prod-lambda-name&lt;BR&gt;&lt;b&gt;ARN&lt;/b&gt;: arn:aws:lambda:eu-west-1:123456789012:function:prod-lambda-name" style="verticalLabelPosition=bottom;verticalAlign=top;aspect=fixed;align=left;pointerEvents=1;shape=mxgraph.aws3.lambda_function;prIcon=server;fillColor=#FF0000;gradientColor=none;html=1;" parent="1" vertex="1"><mxGeometry width="69" height="72" as="geometry" /></mxCell></root></mxGraphModel></diagram></mxfile>
1 change: 1 addition & 0 deletions docs/docs/core-components/output/drawio/color_table.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="multicloud-diagrams" agent="PIP package multicloud-diagrams. Generate resources in draw.io compatible format for Cloud infrastructure. Copyrights @ Roman Tsypuk 2023. MIT license." type="MultiCloud"><diagram id="diagram_1" name="AWS components"><mxGraphModel dx="1015" dy="661" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="1"><root><mxCell id="0" /><mxCell id="1" parent="0" /><mxCell id="vertex:LSI:users_to_model-users-idx:list" value="&lt;b&gt;LSI:users_to_model-users-idx&lt;/b&gt;" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;fillColor=#FF9933;" parent="1" vertex="1"><mxGeometry width="300" height="120" as="geometry" /></mxCell><mxCell id="vertex:LSI:users_to_model-users-idx:row:0" value="IndexName" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="vertex:LSI:users_to_model-users-idx:list" vertex="1"><mxGeometry width="300" height="30" y="30" as="geometry" /></mxCell><mxCell id="vertex:LSI:users_to_model-users-idx:row:1" value="IndexSizeBytes" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="vertex:LSI:users_to_model-users-idx:list" vertex="1"><mxGeometry width="300" height="30" y="60" as="geometry" /></mxCell><mxCell id="vertex:LSI:users_to_model-users-idx:row:2" value="IndexStatus" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="vertex:LSI:users_to_model-users-idx:list" vertex="1"><mxGeometry width="300" height="30" y="90" as="geometry" /></mxCell></root></mxGraphModel></diagram></mxfile>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions tests/core/test_colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from multicloud_diagrams import MultiCloudDiagrams
from utils.templating import TestRendering


class TestCoreVertexInIsolation(TestRendering):

def test_color_red(self):
# docs
self.node_type = 'color_red'

# given
mcd = MultiCloudDiagrams()

# when
mcd.add_vertex(node_id="arn:aws:lambda:eu-west-1:123456789012:function:prod-lambda-name",
node_name='prod-lambda-name',
node_type='lambda_function',
fill_color='#FF0000')

# then
# docs
self.mcd = mcd

def test_color_blue(self):
# docs
self.node_type = 'color_blue'

# given
mcd = MultiCloudDiagrams()

# when
mcd.add_vertex(node_id="arn:aws:lambda:eu-west-1:123456789012:function:prod-lambda-name",
node_name='prod-lambda-name',
node_type='lambda_function',
fill_color='#0000FF')

# then
# docs
self.mcd = mcd

def test_color_table(self):
# docs
self.node_type = 'color_table'

# given
mcd = MultiCloudDiagrams()

# when
rows = [
'IndexName',
'IndexSizeBytes',
'IndexStatus',
]

mcd.add_list(table_name='LSI:users_to_model-users-idx', rows=rows, fill_color='#FF9933;')

# then
# docs
self.mcd = mcd
9 changes: 4 additions & 5 deletions utils/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,22 @@ class TestRendering(TestUtilities):

def set_node_type(self):
self.provider = self.get_provider_by_service_name(self.node_type)
if self.check_nodes_without_rendering():
if self.check_nodes_without_markdown_generation():
if self.node_type not in self.supported_vertex:
self.node_type = 'fallback_vertex'
if 'fallback' == self.provider:
self.provider = 'core'

def check_nodes_without_rendering(self):
no_rendering = ['yaml', 'vertex', 'layer', 'edge']
def check_nodes_without_markdown_generation(self):
result = True
for name in no_rendering:
for name in self.no_rendering:
result = result and name not in self.node_type
return result

def tearDown(self) -> None:
self.set_node_type()
self.mcd.export_to_file(f'docs/docs/{self.provider}-components/output/drawio/{self.node_type}.drawio')
if self.check_nodes_without_rendering():
if self.check_nodes_without_markdown_generation():
self.create_md_from_template()

def create_md_from_template(self):
Expand Down
4 changes: 4 additions & 0 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class TestUtilities(unittest.TestCase):
supported_vertex = {}
provider_services = {}
no_rendering = ['yaml', 'vertex', 'layer', 'edge', 'color']

def setUp(self) -> None:
project_folder = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -21,6 +22,9 @@ def setUp(self) -> None:
self.supported_vertex['yaml'] = {}

def get_provider_by_service_name(self, service_name) -> str:
for substring in self.no_rendering:
if substring in service_name:
return 'core'
for provider, value in self.provider_services.items():
if service_name in value:
return provider
Expand Down

0 comments on commit f58c658

Please sign in to comment.