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

A few random Data Interactive API issues and questions (both docs and implementation) #221

Open
pjanik opened this issue Apr 10, 2018 · 5 comments
Assignees

Comments

@pjanik
Copy link
Member

pjanik commented Apr 10, 2018

Initial message sent to Data Interactive {message: 'codap-present'} is not documented. It seems pretty useful, though. Other thing is that it doesn't really follow {action: ..., reseource: ..., value: ...} format, but it doesn't seem to matter.

Also, I've noticed that new API docs: https://github.com/concord-consortium/codap/wiki/CODAP-Data-Interactive-Plugin-API mention codap-game identifier instead of data-interactive (just in one spot). I'm assuming that this identifier is used to decide whether API v1 or v2 will be used.

I'm working on Lab upgrade (CODAP API v1 => v2), so I'm looking at these docs now. I can use this thread to add more feedback if I find anything interesting or worth fixing.

@pjanik
Copy link
Member Author

pjanik commented Apr 10, 2018

Another issue (or not). I'm trying to obtain the size of the interactive iframe set by user, but it doesn't seem to work. Dimensions are always null when I try to get interactive frame info. However, I can see in the CODAP UI that iframe size is set correctly.

I wanted to achive something like this:

  • when Lab interactive is added to CODAP, set some default dimensions (as Lab interactives have prefered aspect ratio).
  • when CODAP document is loaded again, do not overwrite existing dimensions. It would be either default dimensions set on the initial load, or user-adjusted values.

The code I was trying to use:

this.doCommand({action: 'get', resource: 'interactiveFrame'}, function (resp) {
        if (resp.success) {
          var existingConfig = resp.values;
          var newIframeConfig = {
            name: this.frameConfig.title,
            title: this.frameConfig.title
          };
          // Update dimensions only if they are not set. So, only when the interactive is added to CODAP
          // for the first time. Then, authors can adjust size of the interactive and it should be respected.
          if (existingConfig.dimensions === null) {
            newIframeConfig.dimensions = {
              width: DEF_CODAP_WIDTH,
              height: DEF_CODAP_WIDTH / this.frameConfig.aspectRatio
            };
          }
          this.doCommand({
            action: 'update',
            resource: 'interactiveFrame',
            values: newIframeConfig
          });
        }
      }.bind(this));

The problem is that existingConfig.dimensions is always equal to null. Not sure if it's done by design, accidental (no one needed it before), or a bug.

Not a big deal, but it would be cool feature for Lab. Using this thread as a notes for you that you may consider or not.

@pjanik pjanik changed the title {message: 'codap-present'} is not documented A few random Data Interactive API issues and questions (both docs and implementation) Apr 10, 2018
@kswenson
Copy link
Member

kswenson commented Apr 10, 2018

@pjanik I haven't looked at the code, but it may a timing issue, e.g. during the document loading process CODAP may not know yet what the saved dimensions were. What I did in concord-consortium/sensor-interactive#22 is use savedState as a proxy to decide whether to override the existing dimensions with default dimensions. This only works, of course, for interactives that have saved state.

const receivedFrame = response.values,
      hasSavedState = receivedFrame && receivedFrame.savedState;
// If we have saved state, then we must have been restored from document,
// which means that our dimensions were restored as well, so we only set
// the default dimensions if we don't have saved state.
if (!hasSavedState) {
  newFrame.dimensions = iConfig.dimensions;
}
this.sendRequest(updateFrameReq);

@jsandoe
Copy link
Member

jsandoe commented Apr 10, 2018

@pjanik , the "codap-present" message is a historical artifact and is, I believe, set regardless of game or data-interactive API. I agree it should be documented. I will do so.

Yes, the 'codap-game' argument in the argument is to establish the API, and is the wrong value for this API. I will fix this, too.

Concerning, setting dimensions, I am not sure why the dimensions are always null, but @kswenson's advise is right on target.

@pjanik
Copy link
Member Author

pjanik commented Apr 11, 2018

Right, I thought about, but it requires developers to implement state handling that they wouldn't need to do otherwise. And this null feels a bit incorrect (actually if I pause things in the debugger, iframe size is already set when I get this message). Not a big deal for me, just some very random QA / testing / feedback from my side. I haven't used this API too much in the past. 😉

@pjanik
Copy link
Member Author

pjanik commented Apr 11, 2018

Docs say:

A data context will be created by default for each data interactive at the time it is first requested. The default data context can be referred to by the name dataContext without brackets.

I might be misinterpreting this, but {action: 'get', resource: 'dataContext'} returns "Error: Unable to resolve dataContext: #default", so it seems I need to create it first.

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

3 participants