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

Simple Data Grapher: Integration + Research Note + Tests #6113

Merged
merged 48 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4c063aa
New Table for CsvFiles
IshaGupta18 Jul 8, 2019
5f93182
belongs_to for CSV files
IshaGupta18 Jul 8, 2019
fb9baf0
CSV controller code
IshaGupta18 Jul 8, 2019
0584a26
routes for simple-data-grapher
IshaGupta18 Jul 8, 2019
c156ba5
has_many relation for users
IshaGupta18 Jul 8, 2019
bae5211
view files for csvfiles
IshaGupta18 Jul 8, 2019
6d94e09
user data display
IshaGupta18 Jul 8, 2019
45ed76c
Added simple-data-grapher package
IshaGupta18 Jul 8, 2019
340c516
Delete Gemfile
IshaGupta18 Jul 8, 2019
1066318
Gemfile
IshaGupta18 Jul 8, 2019
cd1977c
Gemfile
IshaGupta18 Jul 8, 2019
a3c1ecb
code climate
IshaGupta18 Jul 9, 2019
cf2164d
Climate 2
IshaGupta18 Jul 9, 2019
db59324
climate 3
IshaGupta18 Jul 9, 2019
48bdba5
fix code climate issues
cesswairimu Jul 9, 2019
8a61b1e
Update schema.rb.example
IshaGupta18 Jul 9, 2019
f5bc4b8
Fixing changes
IshaGupta18 Jul 22, 2019
1de79be
Error Handling
IshaGupta18 Jul 22, 2019
8feb24d
Fixed the errors
IshaGupta18 Jul 26, 2019
ef4bfcc
linting
IshaGupta18 Jul 27, 2019
a332358
minor fix in alert
IshaGupta18 Jul 27, 2019
ab48bd4
more linting
IshaGupta18 Jul 27, 2019
11335f0
work on research note
IshaGupta18 Jul 29, 2019
e8d12d9
Publish as a Research Note Ready!
IshaGupta18 Aug 4, 2019
dabe948
updating schema
IshaGupta18 Aug 4, 2019
01a17ca
Tests for Csvfiles controller for Simple Data Grapher
IshaGupta18 Aug 4, 2019
a1075a3
Bug Fixes
IshaGupta18 Aug 7, 2019
30d9b34
Schema's time stamp
IshaGupta18 Aug 8, 2019
f8804d2
climate fixes
IshaGupta18 Aug 11, 2019
98ac452
cc
IshaGupta18 Aug 11, 2019
2483d55
return statement
IshaGupta18 Aug 11, 2019
86172c2
refactor graph details method
cesswairimu Aug 13, 2019
f239ae6
Update node_shared.rb
IshaGupta18 Aug 15, 2019
ed74259
Adding line break
IshaGupta18 Aug 15, 2019
c86bebc
Merge branch 'SDGall' of https://github.com/IshaGupta18/plots2 into S…
IshaGupta18 Aug 15, 2019
a03347c
Refactored and changes Power tag
IshaGupta18 Aug 17, 2019
170702b
removing spacing in rich.html.erb
IshaGupta18 Aug 17, 2019
dc0ade8
trying to fix cyclomatic complexity (code climate)
IshaGupta18 Aug 18, 2019
707b476
Updating SDG version with new UI
IshaGupta18 Aug 18, 2019
a66aeca
refactoring js code
IshaGupta18 Aug 18, 2019
b704356
linting fixes
IshaGupta18 Aug 18, 2019
b4c6dd1
linting errors
IshaGupta18 Aug 18, 2019
1dd468b
more linting fixes
IshaGupta18 Aug 18, 2019
3fb6946
removing log statements
IshaGupta18 Aug 18, 2019
58ffa5b
index
IshaGupta18 Aug 19, 2019
083351a
Changing routes
IshaGupta18 Aug 19, 2019
20df5ac
system test
IshaGupta18 Aug 20, 2019
523762c
fixing test
IshaGupta18 Aug 20, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
//= require leaflet_helper
//= require grids.js
//= require graph.js
//= require simple-data-grapher.js
//= require wikis.js
//= require header_footer.js
//= require keybindings.js
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/csvfiles.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove this file if it's only a stub!

# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
76 changes: 76 additions & 0 deletions app/assets/javascripts/simple-data-grapher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
function determineType2(graphType){
if (graphType==="Horizontal" || graphType==="Vertical"){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this would be better if it was a switch statement?

Copy link
Member

Choose a reason for hiding this comment

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

That might address https://codeclimate.com/github/publiclab/plots2/pull/6113 asking about complexity here...

return "bar";
}
else if (graphType==="Pie" || graphType==="Doughnut" || graphType==="Radar" ){
return "pie";
}
else if (graphType==="Basic" || graphType==="Stepped" || graphType==="Point"){
return "scatter";
}
}
function layoutMaker(graphType){
var layout={};
Copy link
Member

Choose a reason for hiding this comment

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

let instead of var

if (graphType==="Horizontal" || graphType==="Vertical"){
layout["barmode"]="group";
}
return layout;
}
function traceMaker(graphType){
var trace={};
trace["type"]=determineType2(graphType);
if (graphType==="Horizontal"){
trace["orientation"]="h";
}
else if (graphType==="Doughnut"){
trace["hole"]=0.5;
}
else if (graphType==="Basic"){
trace["mode"]="lines";
}
else if(graphType==="Point"){
trace["mode"]="markers";
}
else if(graphType==="Stepped"){
trace["mode"]="lines+markers";
trace["line"]={"shape": 'hv'};
}
return trace;
}
function keyDeterminer(graphType){
var keys=["x","y"];
if (graphType==="Pie" || graphType==="Doughnut"){
keys[1]="values";
keys[0]="labels";
}
else if (graphType==="Horizontal"){
keys[0]="y";
keys[1]="x";
}
return keys;
}
function plotGraph2(dataHash,length,graphType,divId){
Copy link
Member

Choose a reason for hiding this comment

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

whitespace after ,

var layout=layoutMaker(graphType);
var data=[];
Copy link
Member

Choose a reason for hiding this comment

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

let instead of var

var keySet=keyDeterminer(graphType);
for (var i=0;i<length;i++){
var new_trace=traceMaker(graphType);
new_trace[keySet[0]]=dataHash['x_axis_labels'];
new_trace[keySet[1]]=dataHash['y_axis_values'+i];
new_trace["name"]=dataHash['labels'][1][i];
data.push(new_trace);
}
console.log(data);
Plotly.newPlot(divId,data,layout);
Copy link
Member

Choose a reason for hiding this comment

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

whitespace after ,


Copy link
Member

Choose a reason for hiding this comment

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

Please remove this newline

}
function graphMaker(data,divId){
var obj = data["sdgobject"];
Copy link
Member

Choose a reason for hiding this comment

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

for this function, you can use let for the all the variables instead of var.

var string = "hash = " + obj + ";";
var actualHash = eval(string);
Copy link
Member

Choose a reason for hiding this comment

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

Hm, i'm not sure about eval() here. Is it possible to do the hash = ____; instantiation a different way, like by inserting the value into a template? Using eval seems a little convoluted, but were there reasonable alternatives? Perhaps looking at how we do this in other places?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Found an alternative!

var dataHash = actualHash["hash"];
var length = actualHash["length"];
var graphType = actualHash["graphType"];
console.log(data,dataHash,length,graphType);
plotGraph2(dataHash,length,graphType,divId);
Copy link
Member

Choose a reason for hiding this comment

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

whitespace after ,

}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/csvfiles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the csvfiles controller here.
Copy link
Member

Choose a reason for hiding this comment

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

Same here on it being a stub file, shall we remove it?

// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
58 changes: 58 additions & 0 deletions app/controllers/csvfiles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class CsvfilesController < ApplicationController
before_action :require_user, only: %i(delete user_files)

def new
# to render the index page of simple-data-grapher
Copy link
Member

Choose a reason for hiding this comment

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

empty function, please remove if not needed in this PR.

end

def setter
@csvfile = Csvfile.new(
uid: params[:uid],
filetitle: params[:filetitle],
filedescription: params[:filedescription],
filepath: params[:object],
filename: "file" + Time.now.to_i.to_s,
filestring: params[:filestring]
)
render json: @csvfile if @csvfile.save
end

def prev_files
@allfile = Csvfile.where(uid: params[:uid])
render json: @allfile
end

def user_files
@user_files = Csvfile.where(uid: params[:id])
end

def add_graphobject
@newfile = Csvfile.new(
uid: params[:uid],
filetitle: params[:filetitle],
filedescription: params[:filedescription],
filepath: params[:object],
filename: "file" + Time.now.to_i.to_s,
filestring: params[:filestring],
graphobject: params[:graphobject]
)
@newfile.save
render json: { uid: params[:uid], id: @newfile.id }
end

def delete
return unless params[:id] && params[:uid].to_i == current_user.uid
file = Csvfile.where(id: params[:id].to_i)
if file.destroy(params[:id].to_i)
flash[:notice] = "Deleted the file"
else
flash[:error] = "Could not delete the file"
end
redirect_to "simple-data-grapher/data/#{params[:uid]}"
end

def fetch_graphobject
@graphobject = Csvfile.where(id: params[:id].to_i, uid: params[:uid].to_i)
render json: { sdgobject: @graphobject[0].graphobject }
end
end
1 change: 1 addition & 0 deletions app/controllers/editor_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def editor
end

def post
@graphobject = [params[:id], params[:uid]] if params[:id] && params[:uid]
if params[:tags]&.include?('question:')
redirect_to "/questions/new?#{request.env['QUERY_STRING']}"
elsif params[:legacy] || params[:template] == 'event'
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def insert_extras(body)
body = NodeShared.people_grid(body, @current_user || nil) # <= to allow testing of insert_extras
body = NodeShared.graph_grid(body)
body = NodeShared.wikis_grid(body)
body
body = NodeShared.simple_data_grapher(body)
jywarren marked this conversation as resolved.
Show resolved Hide resolved
end

# we should move this to the Node model:
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/csvfiles_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CsvfilesHelper
end
17 changes: 17 additions & 0 deletions app/models/concerns/node_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ def self.graph_grid(body, _page = 1)
end
end

def self.simple_data_grapher(body, _page = 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can extract the similar parts of this method and the previous method and reuse...I will try to refactor a little and let you know.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can try that, but maybe it would be best to keep it separate, you know so that it's easier to change in the future?

body.gsub(/(?<![\>`])(\<p\>)?\[Power\ Tag\:\ simple-data-grapher\:(\S+)\]/) do |_tagname|
ids = Regexp.last_match(2)
a = ActionController::Base.new
randomSeed = rand(1000).to_s
output = a.render_to_string(template: "grids/_simple-data-grapher",
layout: false,
locals: {
ids: ids,
randomSeed: randomSeed,
idName: 'sdg-graph-' + randomSeed,
type: "graph"
})
output
Copy link
Member

@Anupam-dagar Anupam-dagar Aug 18, 2019

Choose a reason for hiding this comment

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

I guess this output is redundant. Please confirm. Remove it in case it is not used for anything. The assigning is happening in the previous statement but this is just the variable name.

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 output is being returned here. Its a return statement like rest of the code in node_shared.rb

end
end

# rubular regex: http://rubular.com/r/hBEThNL4qd
def self.notes_grid(body, _page = 1)
body.gsub(/(?<![\>`])(\<p\>)?\[notes\:(\S+)\]/) do |_tagname|
Expand Down
3 changes: 3 additions & 0 deletions app/models/csvfile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Csvfile < ApplicationRecord
belongs_to :user, foreign_key: :uid
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module Frequency

has_many :images, foreign_key: :uid
has_many :node, foreign_key: 'uid'
has_many :csvfiles, foreign_key: :uid
has_many :node_selections, foreign_key: :user_id
has_many :revision, foreign_key: 'uid'
has_many :user_tags, foreign_key: 'uid', dependent: :destroy
Expand Down
155 changes: 155 additions & 0 deletions app/views/csvfiles/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.6.3/papaparse.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.33.1/plotly-basic.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css">
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.14.3/xlsx.full.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css">
<%= javascript_include_tag('/lib/simple-data-grapher/dist/PublicLab.Grapher.js')%>
<%= stylesheet_link_tag '/lib/simple-data-grapher/examples/upload_file.css'%>
<div id="first"></div>
<script>
var headerContainer = document.getElementsByClassName("body-container")[0];
SimpleDataGrapherObject = new SimpleDataGrapher("first");
var value = '<%= current_user %>';
<% if current_user %>
SimpleDataGrapherObject.view.createButtons("yes");
var saveButton = SimpleDataGrapherObject.view.elementId + "_save_CSV";
var prevFile = SimpleDataGrapherObject.view.elementId + "_prev_file";
var saveFlag = false;
$("#" + saveButton).click(function(){
saveFlag = true;
});
$("#" + SimpleDataGrapherObject.view.plotGraphId).click(function(){
if (saveFlag){
var arr = {};
arr["completeCsvMatrix"] = SimpleDataGrapherObject.view.csvParser.completeCsvMatrix;
arr["csvHeaders"] = SimpleDataGrapherObject.view.csvParser.csvHeaders;
arr["csvSampleData"] = SimpleDataGrapherObject.view.csvParser.csvSampleData;
arr["csvValidForYAxis"] = SimpleDataGrapherObject.view.csvParser.csvValidForYAxis;
arr["completeCsvMatrixTranspose"] = SimpleDataGrapherObject.view.csvParser.completeCsvMatrixTranspose;
let csvStringMatrix = SimpleDataGrapherObject.view.csvParser.completeCsvMatrixTranspose;
let csvStringForDownload = encodeURI("data:text/csv;charset=utf-8," + csvStringMatrix.map(e => e.join(",")).join("\n"));
$.ajax({
url: '/simple-data-grapher/object',
type: 'post',
data: {object: JSON.stringify(arr),
Copy link
Member

Choose a reason for hiding this comment

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

please introduce a white space after { and before }.

uid: <%= current_user.id %>,
filetitle: SimpleDataGrapherObject.view.fileTitle,
filedescription: SimpleDataGrapherObject.view.fileDescription,
filestring: csvStringForDownload},
success: function(data){
let divAlert = document.createElement('div');
divAlert.classList.add("alert");
divAlert.classList.add("alert-success");
divAlert.innerHTML = "File save successfully!";
headerContainer.appendChild(divAlert);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
console.log(errorThrown);
let divAlert = document.createElement('div');
divAlert.classList.add("alert");
divAlert.classList.add("alert-danger");
divAlert.innerHTML = "There was some error in saving the file.";
headerContainer.appendChild(divAlert);
}
});
}
});

$("#" + prevFile).click(function(){
$.ajax({
url: '/simple-data-grapher/prev_file',
type: 'get',
data: {uid: <%= current_user.id %>},
success: function(data){
displayPreviousFiles(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
console.log(errorThrown);
let divAlert = document.createElement('div');
divAlert.classList.add("alert");
divAlert.classList.add("alert-danger");
divAlert.innerHTML = "There was some error in retrieving the file.";
headerContainer.appendChild(divAlert);
}
});
});

function displayPreviousFiles(data){
var table=document.createElement("table");
for (let i = 0;i<data.length;i++){
Copy link
Member

Choose a reason for hiding this comment

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

whitespace around <

let tr = document.createElement('tr');
let td = document.createElement('td');
let radio = document.createElement('input');
radio.type = 'radio';
radio.value = i;
radio.name = data[0]["csvfile"]["uid"] + "user_id";
td.appendChild(radio);
td.appendChild(document.createTextNode(data[i]["csvfile"]["filetitle"]));
tr.appendChild(td);
table.appendChild(tr);
}
let div = document.getElementById(SimpleDataGrapherObject.view.upload_button_container);
div.appendChild(table);
selectFile(data);
}
function selectFile(data){
$("#" + SimpleDataGrapherObject.view.uploadButtonId).click(function(){
let name = data[0]["csvfile"]["uid"] + "user_id";
let index = $('input[name='+ name +']:checked').val();
Copy link
Member

Choose a reason for hiding this comment

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

whitespace around +

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which one?

Copy link
Member

Choose a reason for hiding this comment

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

the one after name= and the one before the closing square bracket

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay!

let allfiles = JSON.parse(data[index]["csvfile"]["filepath"]);
SimpleDataGrapherObject.view.usingPreviouslyUploadedFile();
SimpleDataGrapherObject.view.csvParser.completeCsvMatrix = allfiles["completeCsvMatrix"];
SimpleDataGrapherObject.view.csvParser.csvHeaders = allfiles["csvHeaders"];
SimpleDataGrapherObject.view.csvParser.csvSampleData = allfiles["csvSampleData"];
SimpleDataGrapherObject.view.csvParser.csvValidForYAxis = allfiles["csvValidForYAxis"];
SimpleDataGrapherObject.view.csvParser.completeCsvMatrixTranspose = allfiles["completeCsvMatrixTranspose"];
SimpleDataGrapherObject.view.continueViewManipulation("prevfile");
});
}
$("#" + SimpleDataGrapherObject.view.elementId + "_publish").click(function(){
console.log(SimpleDataGrapherObject.view.plotlyjsPlotter.dataHash);
console.log(SimpleDataGrapherObject.view.plotlyjsPlotter.graphType);
Copy link
Member

Choose a reason for hiding this comment

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

are these required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will remove the log statements in a follow up PR

Copy link
Member

Choose a reason for hiding this comment

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

If the console statements aren't required then they should be removed in this PR itself. A PR should be complete for its purpose along with the most optimality reached till merge point by mentor and peer reviewing.
If it needs to be anyhow removed later and there is no use for it till the follow up PR, then these statements will just bloat the codebase, which isn't good in anycase.
I think these statements aren't required but still I'll wait for other's opinion on this.
CC: @CleverFool77 @jywarren @gauravano

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, lemme take a look at them and remove the ones that aren't required!

var arr = {};
arr["completeCsvMatrix"] = SimpleDataGrapherObject.view.csvParser.completeCsvMatrix;
arr["csvHeaders"] = SimpleDataGrapherObject.view.csvParser.csvHeaders;
arr["csvSampleData"] = SimpleDataGrapherObject.view.csvParser.csvSampleData;
arr["csvValidForYAxis"] = SimpleDataGrapherObject.view.csvParser.csvValidForYAxis;
arr["completeCsvMatrixTranspose"] = SimpleDataGrapherObject.view.csvParser.completeCsvMatrixTranspose;
let csvStringMatrix = SimpleDataGrapherObject.view.csvParser.completeCsvMatrixTranspose;
let csvStringForDownload = encodeURI("data:text/csv;charset=utf-8," + csvStringMatrix.map(e => e.join(",")).join("\n"));
var dataObject = {};
dataObject["hash"] = SimpleDataGrapherObject.view.plotlyjsPlotter.dataHash;
dataObject["graphType"] = SimpleDataGrapherObject.view.plotlyjsPlotter.graphType;
dataObject["length"] = SimpleDataGrapherObject.view.plotlyjsPlotter.length;
$.ajax({
url: '/simple-data-grapher/note/graphobject',
type: 'post',
data: {object: JSON.stringify(arr),
uid: <%= current_user.id %>,
filetitle: SimpleDataGrapherObject.view.fileTitle,
filedescription: SimpleDataGrapherObject.view.fileDescription,
filestring: csvStringForDownload,
graphobject: JSON.stringify(dataObject)},
success: function(data){
console.log("saved",data);
window.location = '/post?uid='+data["uid"]+'&id='+data["id"];
},
error: function(XMLHttpRequest, textStatus, errorThrown){
console.log("error");
}
});
});

<% end %>
setTimeout("$('.alert-success .alert-danger').fadeOut('slow')", 7000)
</script>

Loading