Skip to content
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

Support for Japanese Chart Symbols #48

Open
kenzie-rasmussen opened this issue Aug 29, 2022 · 5 comments
Open

Support for Japanese Chart Symbols #48

kenzie-rasmussen opened this issue Aug 29, 2022 · 5 comments

Comments

@kenzie-rasmussen
Copy link
Contributor

I am delighted to find this open-source project! Python is not a language I often code in, but I will attempt to provide support for this issue myself. Any help on it or if someone can easily add this feature - that would be greatly appreciated.

I enjoy the charting feature as demonstrated by the Cabled Cowl demo and I noticed thanks to another issue listed that the chart symbols were pulled from this site by the Craft Yarn Council - Site Link.

That site does show the Japanese symbol alongside an 'other' set, but this project currently supports only the 'other' set of symbols. I'd love the stitch legend import to support both types of symbols, perhaps creating a toggle on which ones to use. I was thinking that the 'other' symbols could remain the default, and a command could be used such as
stitch legend = setStitchLegend(Japanese)
(Forgive my Java accent :) )

An alternative method would be to create a duplicate that could be imported instead of stitch_legend, called stitch_legend_japanese. I'm not sure which would be an easier or cleaner implementation yet, as I haven't dived into the code.

I am very fond of Japanese Knitting Charts and use them almost exclusively. I would heavily use pyknit to convert verbal instructions I found into a Japanese chart given the opportunity! I think this software has amazing potential for a code savvy knitter, and I'm looking foward to using it more.

@kenzie-rasmussen
Copy link
Contributor Author

I've noticed that in Chart.py, there is a comment here:

class Stitch:
    """A class to represent a stitch. Optionally, a preferred legend can be passed in."""

I'd love more information on how to optionally pass in a custom legend. I'm still going to create the japanese symbol legend, but I'd like to know more about that

@terriko
Copy link
Owner

terriko commented Sep 8, 2022

This sounds like a great idea!

The legend is currently pretty basic. You can see how it's set up in Chart.py. Here's a snippet:

stitch_legend = {  # Default legend. Incomplete for now.
    "ssk": Stitch(
        instruction="slip slip knit",  # left-leaning decrease
        symbol="\\",
        width=1,
    ),
    "C1-1L": Stitch(
        instruction="sl 1st onto cn, with cn in front, k1, k1 from cn",
        symbol=os.path.join(symbol_dir, "C1-1L.png"),
        width=2,
    }
}

So basically you'd just want to replace the symbols you don't like with the ones you like. You can over-ride them or make a whole new default legend with the symbols that you wanted.

I think it would be pretty cool to have both the craft yarn council symbols we're currently using and the Japanese ones set up in the code. There's two options for how we'd store those off the top of my head:

  1. Make our big default legend store multiple symbol options and set symbol to the one in current use.

e.g.

    "C1-1L": Stitch(
        instruction="sl 1st onto cn, with cn in front, k1, k1 from cn",
        symbol_cyc1=os.path.join(symbol_dir, "C1-1L.png"),
        symbol_japanese=os.path.join(japanese_symbol_dir, "C1-1L.png"),
        symbol=symbol_cyc1,
        width=2,
    }

Or something with some more syntactic elegance so you could have symbol['japanese'] and maybe something so you wouldn't have to typing out the os.path.join() stuff, but the general idea is that you'd easily be able to switch between a few common symbols as part of the default library.

  1. Store the symbols in separate libraries

Same deal only the symbols would each be their own thing, so you'd refer to those directly:

    "C1-1L": Stitch(
        instruction="sl 1st onto cn, with cn in front, k1, k1 from cn",
        symbol=japanese_symbols['C1-1L'],
        width=2,
    }

Same deal, only here we'd have to be a bit careful about making sure multiple symbol libraries have the same keys so that we could switch between them easily, which might be a pain.

I sort of feel like "one big default with multiple stitch options" is easier to maintain and might be easier for people to pick and choose symbols if we had more of a UI for it so I'd lean towards option 1.

In both these cases, though, changing the current symbol means iterating through the whole table and updating each entry. We could probably re-design to avoid this, but the current structure makes it pretty easy for people to override individual symbols and I think we want to keep that property. So probably just make a function that does the iterating to set the defaults and leave it at that?

Sorry, this got kind of long. But yes I would absolutely love to support Japanese symbols, and I guess don't be afraid to change how our legend works right now if it's going to make this easier to do?

@kenzie-rasmussen
Copy link
Contributor Author

Hey! So I totally forgot to update that I did it!
Let me find a way to tag my pull request

@kenzie-rasmussen
Copy link
Contributor Author

kenzie-rasmussen commented Sep 8, 2022

#49 So here is my pull request!

I created two separate stitch legends that can be fed into the chart creator - you choose which one to import and use in your notebook. That way both stitch types are able to be used in the code! I only put a few of the stitches I was using at the time, but there is alot more I will eventually update it with as I use the chart feature.

For consistency, I named the photos the same as the other stitches, just in a folder called /japanese - so they share the same directory, but the japanese symbols use + /japanese. This could possibly be leveraged to combine the stitch legends and include different types of symbols as a more advanced implementation!

I also heavily relied on the tutorial notebooks to understand how to use the program, and I really liked them, so I created one for the japanese charts. Please let me know if you have any questions or clarifications that I could make to the tutorial page to better help people use the feature!

@kenzie-rasmussen
Copy link
Contributor Author

Also, python is not a language that I typically use, and I'm well aware that my implementation could use some 'sprucing' or 'organizing' (sorry java user here). Please pleeease feel free to do that to the code I wrote, just fill me in on what changes you made :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants