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

Plotly standard now fully supported #79

Merged
merged 6 commits into from
May 18, 2018
Merged

Plotly standard now fully supported #79

merged 6 commits into from
May 18, 2018

Conversation

ml7715
Copy link
Collaborator

@ml7715 ml7715 commented May 18, 2018

Check out the python_samples.py file to test 3d plotting! :-)
Closes #67
If a module is missing the user is prompted to install it
Closes #62

@ml7715 ml7715 requested a review from lorenzo2897 May 18, 2018 15:26
@@ -0,0 +1,75 @@
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this to a /test/samples/ folder?

else{
output = data[chosenType];
}
if(typeof output === 'string'){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is not needed

@@ -146,10 +143,39 @@ export class ContentHelpers{
}
}

static interpretRich(data){
let chosenType = this.chooseTypeFromComplexData(data);
let output = '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set the type of output to string

@@ -76,6 +76,7 @@ export class ContentHelpers{
static sourceTmp = '';
static contentTmp: Array<CardOutput> = [];
static id = 0;
static contentId = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will introduce a lot of bugs later on. better to generate a GUID for every new element, which is what plotly does when showing text/html outputs. See https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript for inspiration.

@@ -146,10 +143,39 @@ export class ContentHelpers{
}
}

static interpretRich(data){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function should return a CardOutput object instead of adding it directly to contentTmp.

let traceback = (content['traceback'] as string[]).join('\n');
this.contentTmp.push(new CardOutput('error', traceback));
}
}

static interpretRich(data){
static interpretRich(data: JSONValue){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add return type


if(chosenType === 'application/vnd.plotly.v1+json'){
let plotlyJson = data[chosenType];
if(ContentHelpers.validateData(plotlyJson, 'data')){
let guid = this.generateGuid()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add semicolon

}
}

static installMissingModule(data, module: string){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is data?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the choice of the user. Whether to install or not. That's what it's usually used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not being used in the body of the function. besides, the check should probably be moved to the callback on line 174.

if (module) {
let terminal = vscode.window.createTerminal('pip');
terminal.show();
terminal.sendText('pip install '+module, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be put into userInteraction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The terminal doesn't require any user interaction

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, event?


static getMissingModule(evalue: string){
if(evalue.match(/No module named/i)){
let moduleMatch = /'.+'/i.exec(evalue);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two regexes can be combined into a single one, something like /No module named '(.+)'/i, and the name can be extracted with match[1]

if(moduleMatch && moduleMatch.length){
let module = moduleMatch[0].replace(/\'/g, '');
vscode.window.showInformationMessage('Jupyter requires the module ' + moduleMatch[0] + ' to be installed. Install now?', 'Install')
.then(data => this.installMissingModule(data, module));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be put into userInteraction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a built in function. Wouldn't make any sense calling the same thing in a sibling class. Interpreter should not have access to user interaction

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you want an event? Wouldn't it be overkill?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, fair enough. it's fine

@lorenzo2897 lorenzo2897 merged commit cf84ead into master May 18, 2018
@lorenzo2897 lorenzo2897 deleted the interactives branch May 18, 2018 20:16
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

Successfully merging this pull request may close these issues.

None yet

2 participants