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

finish file I/O implementation #40

Closed
3 tasks
lmccart opened this issue Aug 25, 2013 · 28 comments
Closed
3 tasks

finish file I/O implementation #40

lmccart opened this issue Aug 25, 2013 · 28 comments

Comments

@lmccart
Copy link
Member

lmccart commented Aug 25, 2013

Updated after work by @therewasaguy:

XML is the one thing that could really benefit from some more work. Currently, we can load it, but it's hard to do anything with it because there is not yet an XML object like there is in Processing. An XML object could be really useful in tandem with p5.dom. An XML to JSON converter could also be useful even though that wouldn't always translate. I'd like to work on XML in theory, but in reality I'm not sure when I will get a chance, so if anybody is inspired they should go for it (and maybe open up a new ticket?).

More stuff that isn't supported and might be worth adding:

  • loadBytes() / saveBytes() --> actually spent a decent amount of time trying to figure this one out. Maybe this will help.
  • beginRecord() / endRecord() --> save a PDF of the sketch
  • beginRaw() / endRaw() --> could create a vector?
@lmccart
Copy link
Member Author

lmccart commented Sep 7, 2014

correct me if I'm wrong, but I think we can close this general issue with the great work from @therewasaguy. the last remaining bits to resolve are discussed in these issues:
https://github.com/lmccart/p5.js/issues/326
https://github.com/lmccart/p5.js/issues/280

@lmccart lmccart closed this as completed Sep 7, 2014
@therewasaguy
Copy link
Member

Well, I didn't actually get to all of the file i/o methods listed in the original ticket. I tried to focus on what would be most relevant.

XML is the one thing I think could really benefit from some more work. Currently, we can load it, but it's hard to do anything with it because there is not yet an XML object like there is in Processing. An XML object could be really useful in tandem with p5.dom. An XML to JSON converter could also be useful even though that wouldn't always translate. I'd like to work on XML in theory, but in reality I'm not sure when I will get a chance, so if anybody is inspired they should go for it (and maybe open up a new ticket?).

More stuff I haven't gotten to but might be worth doing:

  • loadBytes() / saveBytes() --> actually spent a decent amount of time trying to figure this one out. Maybe this will help.
  • beginRecord() / endRecord() --> save a PDF of the sketch
  • beginRaw() / endRaw() --> could create a vector?

Stuff I don't think makes sense for p5:

  • createInput()
  • createOutput()
  • selectInput()
  • createReader()
  • selectFolder()
  • open()

@lmccart
Copy link
Member Author

lmccart commented Sep 10, 2014

oops sorry for jumping the gun. I'll update the issue to reflect the current status. if these are things you'd like to tackle at some point feel free to keep your name on this issue. otherwise go ahead and deassign yourself, thanks for all your work on this area!

@lmccart lmccart reopened this Sep 10, 2014
@therewasaguy therewasaguy removed their assignment Sep 10, 2014
@therewasaguy
Copy link
Member

I may dive back in at some point, but I'll deassign myself for now in case somebody else is interested in working on it in the meantime.

@lmccart
Copy link
Member Author

lmccart commented Sep 10, 2014

great, sounds good!

@lmccart lmccart changed the title implement file I/O to the extent it makes sense finish file I/O implementation Sep 10, 2014
@shiffman
Copy link
Member

A small note I think that it might make sense to include something like selectInput() as an easy path to handling some of the JS File API stuff (this tutorial is a nice start). Thanks for all your amazing work @therewasaguy!

@DarkPrince304
Copy link
Contributor

@lmccart : Could you please tell me what's left for the full file I/O implementation to be complete for p5.js? :)

@lmccart
Copy link
Member Author

lmccart commented Nov 10, 2015

I think @therewasaguy has outlined what's left here: #40 (comment).
One key missing item is a p5.XML object that could be used with loadXML() based on the processing spec.

@DarkPrince304
Copy link
Contributor

Cool! @lmccart Also can you give me a little picture of where and when to use loadXML() ? As in, what conditions would require the use of loadXML() ?

I am asking this so that I could get a better picture and then start work on this accordingly! :)

@lmccart
Copy link
Member Author

lmccart commented Nov 10, 2015

loadXML() could be used just like loadJSON() or loadStrings(), either in preload() or setup() or on some event (like a mouse press). here is a test file that you can load with p5.js, but the resulting data object is a little complicated to parse with native JS calls.
https://github.com/processing/p5.js/wiki/Loading-external-files:-AJAX,-XML,-JSON#xml

there are also some external APIs that return XML rather than JSON, for example the NYC MTA subway API:
http://web.mta.info/status/serviceStatus.txt
http://web.mta.info/developers/

does that answer your question, or am I misunderstanding?

@DarkPrince304
Copy link
Contributor

Yeah, thanks a lot! I'd like to start looking into it!

@lmccart
Copy link
Member Author

lmccart commented Nov 10, 2015

wonderful! let me know if you have any questions.

@DarkPrince304
Copy link
Contributor

Sure! Has any progress been made on this? I checked out io/file.js and there was some stuff inside the loadXML() function. Should I carry that forward or start from the scratch on my own?

@lmccart
Copy link
Member Author

lmccart commented Nov 11, 2015

I think it makes sense to carry on with this, the todo here is probably to add another object called p5.XML that gets returned from loadXML(), similar to how loadTable() returns a p5.Table object.

@DarkPrince304
Copy link
Contributor

@lmccart How would you like the structure of the XML to be parsed? If I am not wrong is this a place where we would have to use Data Structures like B-Tree or Hash Map to reconstruct a perfect DOM behaviour for the resulting parsed XML?

@DarkPrince304
Copy link
Contributor

@lmccart will the p5.XML object be having all the methods associated with it as in the case of its processing counterpart? Also for methods requiring searching what kind of solution do you think would be apt for searching an XML node inside another ones?

@DarkPrince304
Copy link
Contributor

Hello @lmccart,

I have some queries that I came across while implementing this.

If the XML is like this

 <?xml version="1.0"?>
 <mammals>
   <animal id="0" species="Capra hircus">Goat</animal>
   <animal id="1" species="Panthera pardus">Leopard</animal>
   <animal id="2" species="Equus zebra">Zebra</animal>
 </mammals> 

1.) and the getContent('mammals') method is called should null be returned in such a case or a complete String like " <animal id="0" species="Capra hircus">Goat</animal><animal id="1" species="Panthera pardus">Leopard</animal><animal id="2" species="Equus zebra">Zebra</animal>" ?

2.) Also in case of getParent('mammals') should #document be returned?

3.) If I call getChildren("animal") will it return an array containing id,species,innerText ?

@lmccart
Copy link
Member Author

lmccart commented Feb 12, 2016

1 it should match the behavior of processing wherever it makes sense. so if you run this in processing, you get something like:

 println(xml.getContent("mammals"));
// Goat
// Leopard
// Zebra

so maybe it should return an array of these three items?

2 I think it should return null, matching the behavior of processing.
3 The output from processing is:

<animal id="0" species="Capra hircus">Goat</animal> <animal id="1" species="Panthera pardus">Leopard</animal> <animal id="2" species="Equus zebra">Zebra</animal>

so perhaps it should return the raw elements or maybe an array of p5.XMLNode objects?

@DarkPrince304
Copy link
Contributor

Woops! Sorry, about the 3rd question I meant what if xml = the animal node and then we call xml.getChildern(). What will be the children of animal?

DarkPrince304 added a commit to DarkPrince304/p5.js that referenced this issue Feb 13, 2016
@lmccart
Copy link
Member Author

lmccart commented Feb 16, 2016

hm, what is the output for processing for this? i would try to match that conceptually as best as possible, unless it makes sense to deviate for some reason. maybe it would be useful to write out a spec of this object and methods first, and we could review to make sure it all fits together as expected, before you implement?

@DarkPrince304
Copy link
Contributor

I will try it out on processing soon and let you know. But I think it should be null value if xml = animal node[0].

By the way I have done this in my PR #1255 using the class p5.XML and defined its methods and attributes too. So the loadXML() works fine except for just one thing on which I would like some help, which I have mentioned in the PR. You can check it out whenever you want :)

@lmccart
Copy link
Member Author

lmccart commented Feb 16, 2016

oops sorry missed that! will take a look next chance i get.

@DarkPrince304
Copy link
Contributor

@lmccart Is this finished? Or is there anythiing left with file I/O ?

@lmccart
Copy link
Member Author

lmccart commented Dec 19, 2016

@DarkPrince304 the three checkboxes in the first post still need looking into.

@DarkPrince304
Copy link
Contributor

DarkPrince304 commented Dec 19, 2016

@lmccart What do you think should be a good approach to saving the sketch as a PDF? If memory serves me I guess someone did a similar GSoC project to save data as PDF? I guess this is it: https://github.com/zenozeng/p5.js-pdf

I am not really sure what the 3rd point is? Creating a vector of what?

Also about the XML functionality, the saveXML() hasn't been implemented yet right? Is that also planned? Is there also anything else remaining for JSON and XML or other files?

Thanks

@lmccart
Copy link
Member Author

lmccart commented May 10, 2017

since we haven't heard much demand for the three remaining unimplemented pieces, I suggest we close this issue and focus on issues that are higher priority.

@bmoren
Copy link
Contributor

bmoren commented May 10, 2017

I agree with the bytes and pdf being pushed to the back, I've had a lot of student desire for svg/vector output to be native so they can more easily traverse p5js & css tasks & get vector information out for going to print & laser/plotter/cnc fabrication. I do think likely the svg should be an external library. But from our previous conversation, It seems a question of how possible it is given the current render setup. I also do believe that in order to get svg/vector implemented it would be super helpful to have someone with experience in this area.

@lmccart
Copy link
Member Author

lmccart commented May 10, 2017

yes, definitely. the svg issue is still open: #458.
though realistically, I just don't have the bandwidth to take it on anytime soon, but would welcome anyone interested in tackling it.

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

No branches or pull requests

7 participants