-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor site to react #8
Conversation
Signed-off-by: Jay Clark <[email protected]>
Signed-off-by: Jay Clark <[email protected]>
Signed-off-by: Jay Clark <[email protected]>
Signed-off-by: Jay Clark <[email protected]>
Signed-off-by: Jay Clark <[email protected]>
Signed-off-by: Jay Clark <[email protected]>
Signed-off-by: Jay Clark <[email protected]>
Thank you so much for the effort put into this project! It seems already much better! I agree that having the build step nowadays is inevitable, and it was my original idea: having the code more modularized and perhaps written in React and Typescript. I created at my job a webpack file that creates a Regarding the best way to migrate to React, I can't say. Maybe a top-down approach may help? Before I explain some of my ideas, let'me explain what I mean by Diagram: the venn diagram graphic. So, a component Diagram, would be responsible to have an input and outputs an SVG. For example, would render . I think the names of what we are calling diagram and "setsImage" is confusing. For example, rather the user selects "lists" or "tree", this is only relevant for the Website, not for the diagram. Venn diagrams will always look the same. They can be 2-way, 3-way, ... 6-way. Tree vs. Slide is only a matter of how the user writes the union operations that happens when they click the "slider" buttons < >. So, what I see that could be done next, if you would like to, is something like this:
Current bugs that I found:
I created a Many thanks for all the work you put into this project already! It has already reshaped it so much! Thank you! |
A new tab |
Thanks so much for the feedback. I think I am already on the same page about a lot of things, but I understand much better what you mean about diagram being separated out as a module from the site. I’ll think more about the best way to implement that as I’m finishing up the last handful of PRs in my challenge. Most likely I’ll start from scratch and focus on modularizing the diagram svg first. That should be a relatively small PR to start as opposed to this one! Creating a dev branch to open PRs against would be great as well. I can probably also help a bit with the GitHub actions (as well as setting up preview deploys for PRs) |
I tried to change the default branch to |
OK, I've thought about this some more and it definitely makes sense to work only on the Diagram component first. But, the way I'm envisioning it, that would include:
The Diagram component would accept three props: data, config, and output. Data could be either a string (in the .ivenn format) or a json object that contains the same information. Config would be an object containing options like global font size, opacity, colors, etc. that modify the defaults. Output would be passed as an object with four properties: type* (svg, png, htmlElement), svgOptions, pngOptions, and htmlElementOptions. Each output type would have optional configuration options that can override the defaults. For example, the output object might look something like this:
or this:
In terms of actually implementing this, I think it makes sense to add a new folder, at the same level as I can also implement an extremely basic index page in that new folder for testing (it's certainly possible to write 'blind' tests as well, but sometimes visual tests are so much faster to determine that something has gotten messed up.) The index page would only take 3 inputs - a file with the data, plain text config code, and plain text output code - and have one area to display the output. Let me know what you think of this approach! |
How about something like this? <App>
...
<Interactivenn>
<Slider/>
<Diagram/> (pure SVG)
<BottomMenu/>
</Interactivenn>
<Input/>
...
</App> If in the future I export Interactivenn as a package for Python, Cases:
Users could still setup things using the parameters of the Python object that creates and controls the diagram. So maybe they want only to show the diagram. Or an interactive diagram (diagram + slider), and so on. Actually, something like this could work too because Input could be by default hidden in the Python version... and displayed only if the user wants, although in Python users would tend to upload data using the arguments of a function. <App>
...
<Interactivenn>
<Slider/>
<Diagram/> (pure SVG)
<BottomMenu/>
<Input/> ***
</Interactivenn>
...
</App> For the python/R libraries, I would port only the |
Sure, that makes sense for how the React wrapper would work, but it would be much more versatile to have the output of the diagram module be framework-agnostic so that it can be used in React, Vue, Angular, any framework or even vanilla HTML/JS. Similar to the distinction between Bootstrap and react-bootstrap. (Or D3 and Britecharts.) |
So, I was thinking about having DiagramService that has functions that do: create and return svg element, create and append svg to div, etc. Then this can be called in the component, so it would still be a component that calls this other "pure" js/ts class/function. The entire React components with menus, as well as a simple createSVG function, can be later exported in a module/package, that I can use to build Jupyter and R plugins, for example. Actually, once an npm package is created, it is in plain JavaScript, right?, and can be used anywhere. So the "pure" js may not be required. For example: var interactivenn = require('interactivenn');
import interactivenn from 'interactivenn';
var div = document.getElementById("diagram-container");
interactivenn.appendDiagram(div, sets, options);
var svg = interactivenn.createSvgDiagram(sets, options);
var canvas = interactivenn.createCanvasDiagram(sets, options);
interactivenn.appendInteractiveDiagram(div, sets, options); This would make it very flexible. We could think about having specific packages, like for React, but maybe just making functions more flexible can solve the problem? Not sure how a "const reactElement = createInteractiVennReactElement()" would work. |
Yes, that's right - npm packages are pure, transpiled JS. I think we're on the same page now - DiagramService will accept two inputs - an object of data sets and an object with configuration options. It will output an svg. The various ways to manipulate the appearance and content of the diagram will be controlled through other functions/components. |
Closing this out in favor of a step-based approach as discussed in #17 |
Partially fixes #5
This is turning out to be quite an undertaking! Creating a Diagram component that executes most updates through state management required quite a bit of refactoring. As it stands, this is a massive PR (though, it's not as large as it looks - most of the additions/deletions are from functions being copy/pasted from one large file into their individual components.)
I've gotten pretty far along on implementing a pure-javascript React component for the Diagram. This means it can be served on a regular server with no build step. I wondered what you thought about converting fully to React (i.e. using create-react-app or manually setting up a similar configuration.) That would make the code easier to read & simpler, but would require and extra build step in order to serve the site.
I have a prototype running here. There are still some bugs I need to work out with the merge scripts for Unions by Tree, but most everything else seems to be working.
I'll likely open a separate PR to take care of some bugs & styling issues that I found & was able to resolve in the current code (issue #3 ). I have ~1 week left of work on my 100 PR challenge so I need to focus on that for a bit, but I did want to open a draft PR for now for feedback on: