Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Update nodes doc from PR: 93 #67

Closed
wants to merge 1 commit into from
Closed
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
188 changes: 188 additions & 0 deletions docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/app.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
{
"rfInstance": {
"nodes": [
{
"width": 190,
"height": 115,
"id": "END-06a4da40-a0ae-44ad-873b-9b65d096880a",
"type": "TERMINATOR",
"data": {
"id": "END-06a4da40-a0ae-44ad-873b-9b65d096880a",
"label": "END",
"func": "END",
"type": "TERMINATOR",
"ctrls": {},
"selected": true
},
"position": {
"x": 1481.1276538172046,
"y": 301.7443219065692
},
"selected": true,
"positionAbsolute": {
"x": 1481.1276538172046,
"y": 301.7443219065692
},
"dragging": true
},
{
"width": 150,
"height": 135,
"id": "LINSPACE-b70dcbec-87fc-47bd-98dc-26c01de91881",
"type": "default",
"data": {
"id": "LINSPACE-b70dcbec-87fc-47bd-98dc-26c01de91881",
"label": "LINSPACE",
"func": "LINSPACE",
"type": "SIMULATION",
"ctrls": {
"start": {
"functionName": "LINSPACE",
"param": "start",
"value": "10"
},
"end": {
"functionName": "LINSPACE",
"param": "end",
"value": "0"
},
"step": {
"functionName": "LINSPACE",
"param": "step",
"value": "1000"
}
},
"selected": false
},
"position": {
"x": 335.60460405758,
"y": 414.5947652926823
},
"selected": false,
"positionAbsolute": {
"x": 335.60460405758,
"y": 414.5947652926823
},
"dragging": true
},
{
"width": 150,
"height": 135,
"id": "LINSPACE-0c193475-a070-4357-b9f6-1cc8320c8a65",
"type": "default",
"data": {
"id": "LINSPACE-0c193475-a070-4357-b9f6-1cc8320c8a65",
"label": "LINSPACE_1",
"func": "LINSPACE",
"type": "SIMULATION",
"ctrls": {
"start": {
"functionName": "LINSPACE",
"param": "start",
"value": "10"
},
"end": {
"functionName": "LINSPACE",
"param": "end",
"value": "0"
},
"step": {
"functionName": "LINSPACE",
"param": "step",
"value": "1000"
}
},
"selected": false
},
"position": {
"x": 337.2242660007536,
"y": 164.02507602827643
},
"selected": false,
"positionAbsolute": {
"x": 337.2242660007536,
"y": 164.02507602827643
},
"dragging": true
},
{
"width": 99,
"height": 115,
"id": "SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0",
"type": "ARITHMETIC",
"data": {
"id": "SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0",
"label": "SUBTRACT",
"func": "SUBTRACT",
"type": "ARITHMETIC",
"ctrls": {},
"inputs": [
{
"name": "y",
"id": "sub_y",
"type": "target"
}
],
"selected": false
},
"position": {
"x": 984.775645730269,
"y": 300.51837909623805
},
"selected": false,
"positionAbsolute": {
"x": 984.775645730269,
"y": 300.51837909623805
},
"dragging": true
}
],
"edges": [
{
"source": "SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0",
"sourceHandle": "main",
"target": "END-06a4da40-a0ae-44ad-873b-9b65d096880a",
"targetHandle": "END",
"id": "reactflow__edge-SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0main-END-06a4da40-a0ae-44ad-873b-9b65d096880aEND"
},
{
"source": "LINSPACE-0c193475-a070-4357-b9f6-1cc8320c8a65",
"sourceHandle": "main",
"target": "SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0",
"targetHandle": "SUBTRACT",
"id": "reactflow__edge-LINSPACE-0c193475-a070-4357-b9f6-1cc8320c8a65main-SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0SUBTRACT"
},
{
"source": "LINSPACE-b70dcbec-87fc-47bd-98dc-26c01de91881",
"sourceHandle": "main",
"target": "SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0",
"targetHandle": "sub_y",
"id": "reactflow__edge-LINSPACE-b70dcbec-87fc-47bd-98dc-26c01de91881main-SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0sub_y"
}
],
"viewport": {
"x": 296.7009684013002,
"y": 78.64846027544155,
"zoom": 0.8997754917401063
}
},
"ctrlsManifest": [
{
"type": "input",
"name": "Slider",
"id": "INPUT_PLACEHOLDER",
"hidden": false,
"minHeight": 1,
"minWidth": 2,
"layout": {
"x": 0,
"y": 0,
"h": 2,
"w": 2,
"minH": 1,
"minW": 2,
"i": "INPUT_PLACEHOLDER"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
In this example, we `SUBTRACT` the outputs of two identical `LINSPACE` nodes.

As expected, when we check the output of the app, we see 0 everywhere, as expected!
57 changes: 57 additions & 0 deletions docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/ARRAY_VIEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

[//]: # (Custom component imports)

import DocString from '@site/src/components/DocString';
import PythonCode from '@site/src/components/PythonCode';
import Parameters from '@site/src/components/Parameters';
import AppDisplay from '@site/src/components/AppDisplay';
import SectionBreak from '@site/src/components/SectionBreak';
import AppendixSection from '@site/src/components/AppendixSection';

[//]: # (Docstring)

import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt';
import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt';
import ParametersSource from '!!raw-loader!./a1-[autogen]/parameters.yaml';

<DocString>{DocstringSource}</DocString>
<PythonCode GLink='bin/flojoy-io/docs/docs/./VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/ARRAY_VIEW.py'>{PythonSource}</PythonCode>
<Parameters>{ParametersSource}</Parameters>

<SectionBreak />



[//]: # (Examples)

## Examples

import Example1 from './examples/EX1/example.md';
import App1 from '!!raw-loader!./examples/EX1/app.txt';
import Data1 from '!!raw-loader!./examples/EX1/output.txt';

<AppDisplay
data={Data1}
nodeLabel='ARRAY_VIEW'>
{App1}
</AppDisplay>

<Example1 />

<SectionBreak />



[//]: # (Appendix)

import Notes from '!!raw-loader!./appendix/notes.md';
import Hardware from '!!raw-loader!./appendix/hardware.md';
import Media from '!!raw-loader!./appendix/media.md';

## Appendix

<AppendixSection index={0} folderPath='nodes/nodes/bin/flojoy-io/docs/docs/nodes/./VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/'>{Notes}</AppendixSection>
<AppendixSection index={1} folderPath='nodes/nodes/bin/flojoy-io/docs/docs/nodes/./VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/'>{Hardware}</AppendixSection>
<AppendixSection index={2} folderPath='nodes/nodes/bin/flojoy-io/docs/docs/nodes/./VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/'>{Media}</AppendixSection>


Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

The ARRAY_VIEW node takes "ordered_pair", "dataframe", "matrix", and "image" as input type
and displays its visualization in array format.

Parameters
----------
None

Returns
-------
plotly
Visualization of the input data in array format

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from flojoy import flojoy, DataContainer
import plotly.graph_objects as go
import numpy as np
import pandas as pd

CELL_SIZE = 50
FONT_SIZE = 10
MAX_ALLOWED_SHAPE = 10
l_dot = "$\\ldots$"


def numpy_array_as_table(arr: np.ndarray, placeholder: str):
if arr.size > MAX_ALLOWED_SHAPE:
converted_type = arr.astype(object)
new_arr = converted_type[:MAX_ALLOWED_SHAPE]
new_arr[MAX_ALLOWED_SHAPE - 2] = l_dot
else:
new_arr = arr
return new_arr.reshape(-1, 1)


@flojoy
def ARRAY_VIEW(dc_inputs: list[DataContainer], params: dict) -> DataContainer:


dc_input = dc_inputs[0]
match dc_input.type:
case "ordered_pair":
data = dc_input.y
cell_values = numpy_array_as_table(data, l_dot)
case "dataframe":
data = pd.DataFrame(dc_input.m).to_numpy(dtype=object)
data = data[:, :-1]
cell_values = numpy_array_as_table(data, l_dot)
case "matrix":
data = dc_input.m
cell_values = numpy_array_as_table(data, l_dot)
case "image":
red = dc_input.r
green = dc_input.g
blue = dc_input.b

if dc_input.a == None:
merge = np.stack((red, green, blue), axis=2)
else:
alpha = dc_inputs[0].a
merge = np.stack((red, green, blue, alpha), axis=2)

merge = merge.reshape(-1, merge.shape[-1])
cell_values = numpy_array_as_table(merge, l_dot)
case _:
raise ValueError(
f"unsupported DataContainer type passed for ARRAY_VIEW: {dc_input.type}"
)

fig = go.Figure(
data=[
go.Table(
header=dict(line={"width": 0}, values=[]),
cells=dict(
values=cell_values,
line={"width": 3},
font={"size": FONT_SIZE},
height=CELL_SIZE,
align="center",
format=[".3"],
),
)
]
)
if dc_input.type == "image" or dc_input.type == "dataframe":
width = MAX_ALLOWED_SHAPE * CELL_SIZE + 800

else:
width = MAX_ALLOWED_SHAPE * CELL_SIZE + 80
height = width + 80
fig.layout = go.Layout(
autosize=False,
width=width,
height=height,
margin=dict(l=0, r=0, t=0, b=0),
xaxis=dict(visible=False),
yaxis=dict(visible=False),
hovermode="closest",
font=dict(size=FONT_SIZE),
)

return DataContainer(type="plotly", fig=fig)
Loading