I have submitted the code to be able to save the chart data into a .json file. There is a button on the bottom-left of the chart window (now that the + and - buttons are no longer needed.
To this post I add the visual studio solution that I used to develop the web-page part. I added some documentation, that I repeat for clarity.
Quote
These files are intended to make it possible to add a chart of a certain train path (from a .pat file) to a web-page. The only file you really need is the Scripts/drawPathChart.js. The rest of the files are only there to have a working example.
Obviously this readme is not going to tell you how to make a web-site or how to use javascript on such a web-site. This readme is only going to tell you about adding a path chart.
- Use Contrib.TrackViewer to load your route, load a path for your route (Path-Editor menu), show the chart for it (also Path-Editor menu), and save this as a .json file (button in the window). Place this .json file somewhere in your web-site directory structure
- Copy the Scripts/drawPathChart.js to your website directory. Make sure it is loaded from the HTML.
- Call the LoadAndDraw method from another javascript routine, after the loading of the web-site is done
The other example files do the following:
- chartexample.html: This is a very simple example HTML. It loads to scripts and it has two elements: one for the textual header and one for the canvas. The canvas will be used to draw the chart upon.
- Scripts/chartexample.js: An example javascript file that shows how to use the javascript code in drawPathChart.js. It contains configuration options
(many of these are not needed because the defaults are decent as well). It also contains the call to the LoadAndDraw method, with the name of the
.json file that needs to be loaded as well as an optional callback function that is called after the drawing is finished. - Content/examplepathchartdata.json. An example of path data saved from TrackViewer.
All the other files are there for using Microsoft Visual Studio for web-site development. But there is no need at all to use Visual Studio. Use whatever you are comfortable with.
Trackviewer web.zip (43.7K)
Number of downloads: 180
James Ross, on 20 June 2015 - 01:09 AM, said:
If you do want to include it, I think it probably fits best as another folder inside Source\Contrib. If it's not useful to build it with all the other code, you can still put it there but just don't add the project to the ORTS.sln.
Indeed, it is not useful to build the web-part with the rest. For two reasons. First, there is nothing to build. It is HTML and javascript, no compilation at all. Second, the idea is that only one file is really needed (drawPathChart.js) for the user, but it is needed in the sense that it needs to be copied to a web-site. That web-site is not in this code, and it cannot be. For each new route/path a different .json is needed. And hence a different web-site (or for someone with an extensive web-site, of course, it could contain multiple .json files that can be selected via a web-interface). The rest of the files are examples.
Adding it as an extra project in Contrib is possible. But when we do not add it to the main solution, you cannot actually open it (a project needs a solution). Or, rather, if you open it it will create the .sln file itself. And having to add it to the main solution each time you want to work on it and making sure you never commit the main solution is also not nice.
I saw some other posts on ideas for web-interaction with the simulator.. Possibly it makes sense to have a separate directory as a placeholder for that kind of web-content/web examples that can be used together with the game (so different from the openrails.org web-site).
Genma Saotome, on 20 June 2015 - 11:54 AM, said:
Perhaps there is someone on the board who knows .css well enough to create a pair of templates, one suitable for ordinary computer screens and another for phones / tablets. Once provided I suspect more information to present therein will follow rather quickly.
For the moment what I created does not contain any css.I do not recall every writing css myself. Also javascript was completely new for me. I am reading a lot these weeks :) on these subjects. Most likely there are quite some improvements possible related to making the code more flexible to deal with different layouts and screen sizes.But in principle the chart part is only a small part of a web-site anyway.
Best regards. Jeroen