Jump to content
JChartFX Community
  • 0
Sign in to follow this  
David.Harris

Persisting changes made using the new menu

Question

I have a system that generates a chart on a page. The user can then update the chart settings using the new menu that is supplied in the latest release. Is there a way to retrieve the settings that have been set by the user so I can persist them somewhere and restore the page as the user configured next time the user returns to the page?

 

TL;DR - Can I save menu changes?

  • Like 1

Share this post


Link to post
Share on other sites

13 answers to this question

Recommended Posts

  • 0
JuanC    3

Currently there is no way, we have worked on enabling persistence and there is an extra script (jchartfx.persistence.js) that currently has the code so that a chart can read all its settings from a json object, but we do not support saving the current settings yet.

 

We will consider adding support for this for future builds.

 

JuanC

Share this post


Link to post
Share on other sites
  • 0
IGSFX    0

Using this community forum is the preferred way to submit feature requests. If there is any other feature you would like to see added to the product, besides persisting user changes, please submit it on a new post and we will gladly review the possibility to include it in a future build.

---

The jChartFX Team

Share this post


Link to post
Share on other sites
  • 0
JuanC    3

We are almost ready to push this functionality on the unstable build. The way it will work (suggestions are welcome) would be as follows

 

1) Besides coreVector you will need to include the userInterface and persistence scripts

 

2) After you create and customize your chart you would do the following in order to save the current settings as the baseline as well as be notified of any changes on the UI (you could ignore the uiNotify call if you plan to save changes manually)

 

chart1.recordBaseline();

chart1.uiNotify = onChartChange;
 
3) After the recordBaseline call you should incorporate the end-user changes, in this sample we are using localStorage but in order to save these personalizations on the server, you would probably connect to SQL (or any other storage API) on the server to generate a JSON that will be loaded on the client, note that to avoid the chart painting twice, you would not want use XMLHttpRequest but instead make sure the end-user customizations are sent back on the HTML page rendered by the client
 
var userChanges = localStorage.getItem("chart");
if ((userChanges !== undefined) && (userChanges != null)) {
    // alert(userChanges);
    chart1.loadJson(JSON.parse(userChanges));
}
 
4) In the function invoked by our UI (or in the code that saves the user changes manually)
 
function onChartChange()
{
    var json = this.changesFromBaseline();
    var text = JSON.stringify(json);
    localStorage.setItem("chart", text);
    // alert(text);
}
 
In a server approach you would use XMLHttpRequest (or ajax if you are using jQuery) to send the JSON string to the server.
 
These bits should be available soon on the unstable channel. Please let us know if this approach would work on your scenarios.
 
JuanC

post-2107-13939745470425_thumb.png

Share this post


Link to post
Share on other sites
  • 0
krugerm    0

So changesFromBaseline() returns a diff of the settings since the last call to recordBaseline()?  Interesting approach. :)

 

Could you also implement a function which returns the complete settings (as if recordBaseline() hadn't been called?)

 

Thanks,

mike

Share this post


Link to post
Share on other sites
  • 0
JuanC    3

The reason to have a baseline is that 1) your code will make some changes to the chart and 2) if you are using a motif, it might make some changes to the chart. If you include these changes when serializing the user changes, it might make it impossible to change motifs at a later time.

 

There is a method already in chart called saveJson. If you invoke it without parameters it will return a JSON that contains the serialization of the chart but only the values that are different than the default. If you pass an empty object, e.g. chart1.saveJson({}), it will return the complete serialization of the chart (all members will be serialized).

 

There is also a method called loadJson that receives a JSON object and reads the chart settings from it.

 

Both of these (loadJson and saveJson) are implemented in the persistence js

 

JuanC

Share this post


Link to post
Share on other sites
  • 0
krugerm    0

Those two functions are exactly what I've been looking for.  I wish they'd been documented earlier!  Speaking of, where can I find documentation on the events fired when the user makes a change via the UI?  (The documentation at http://support.softwarefx.com/seems to be missing any & all event info.)

 

Thanks! :)

Share this post


Link to post
Share on other sites
  • 0
JuanC    3

The saveJson function was only added in the latest unstable build (5666). We should be publishing documentation for these 2 methods soon.

 

To be notified of UI changes by the user you would set the uiNotify to a function as in my previous post. We might rename this event before pushing the changes to the stable channel (probably changedByUser)

 

Regards,

 

JuanC

Share this post


Link to post
Share on other sites
  • 0
JuanC    3

You can start evaluating it today by downloading the unstable branch (any build marked 7.4.5666 or later)

 

JuanC  a7.4. 7.4.56665666

Share this post


Link to post
Share on other sites
  • 0
FP2006    4

Juan,

 

Wondering if you have an estimated release date for a production release that containes the persisting features.

 

Users are eager to get their hands on that capability.

 

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×