updated by GasGit automation
This commit is contained in:
parent
74b8a67fd6
commit
d1ca25f508
1 changed files with 257 additions and 174 deletions
|
@ -1,59 +1,133 @@
|
||||||
// stuff that is common to both Apps Script and Office
|
/**
|
||||||
|
* manages the connection between the data and the chart
|
||||||
|
* @namespace Process
|
||||||
|
*/
|
||||||
// define it
|
|
||||||
var Process = (function (process) {
|
var Process = (function (process) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
process.globals = {
|
||||||
|
resetProperty:"ssnipSettings",
|
||||||
|
purchaseLevel:'ssnipLevel',
|
||||||
|
fullAccess:10,
|
||||||
|
openAccess:true
|
||||||
|
};
|
||||||
|
|
||||||
|
process.applyElementer = function () {
|
||||||
|
var before = Utils.clone (process.control.sankey.settings);
|
||||||
|
process.control.sankey.settings = Sankey.mapSettings (process.control.sankey.elementer);
|
||||||
|
return JSON.stringify(before) !== JSON.stringify(process.control.sankey.settings);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
process.initialize = function () {
|
process.initialize = function () {
|
||||||
|
|
||||||
|
var sankeySetup = Sankey.setup();
|
||||||
|
|
||||||
|
// this will create the structure for retrieving settings
|
||||||
|
var elementer = Sankey.doElementer(sankeySetup);
|
||||||
|
var elements = elementer.getElements();
|
||||||
|
|
||||||
|
|
||||||
process.control = {
|
process.control = {
|
||||||
result: {
|
result: {
|
||||||
data:undefined,
|
data:undefined,
|
||||||
checksum:undefined
|
checksum:undefined
|
||||||
},
|
},
|
||||||
|
sankey:{
|
||||||
|
setup:sankeySetup,
|
||||||
|
elementer:elementer,
|
||||||
|
settings:{},
|
||||||
|
store:{
|
||||||
|
useInitial:null,
|
||||||
|
useStandard:null,
|
||||||
|
useUser:null,
|
||||||
|
useDocument:null
|
||||||
|
},
|
||||||
|
auth:{}
|
||||||
|
},
|
||||||
|
|
||||||
activeHeadings: {
|
activeHeadings: {
|
||||||
from:{
|
from:{
|
||||||
current:'from',
|
current:'from',
|
||||||
elem:Utils.el('from-column')
|
elem:elements.controls.fromColumn
|
||||||
},
|
},
|
||||||
to: {
|
to: {
|
||||||
current:'to',
|
current:'to',
|
||||||
elem:Utils.el('to-column')
|
elem:elements.controls.toColumn
|
||||||
},
|
},
|
||||||
value:{
|
value:{
|
||||||
current:'value',
|
current:'value',
|
||||||
elem:Utils.el('value-column')
|
elem:elements.controls.weightColumn
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
chart: {
|
chart: {
|
||||||
headings:[],
|
headings:[],
|
||||||
data:[[]],
|
data:[[]],
|
||||||
elem:Utils.el("chart"),
|
elem:DomUtils.elem("chart"),
|
||||||
ghost:Utils.el("ghost"),
|
ghost:DomUtils.elem("ghost"),
|
||||||
picker:Utils.el("picker-preview")
|
defOptions:{
|
||||||
|
height:DomUtils.elem("chart").offsetHeight,
|
||||||
|
width:DomUtils.elem("chart").offsetWidth
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
code: {
|
code: {
|
||||||
svg:Utils.el("chart-code-svg"),
|
svg:elements.controls.svgCode
|
||||||
picker:Utils.el("picker-code-svg"),
|
|
||||||
pickerHeight:520*.7,
|
|
||||||
pickerWidth:600*.9
|
|
||||||
},
|
},
|
||||||
|
|
||||||
buttons: {
|
buttons: {
|
||||||
save: Utils.el("save-button"),
|
insert:elements.controls.insertButton,
|
||||||
insert:Utils.el("insert-button")
|
manage:elements.controls.manageButton,
|
||||||
|
apply:elements.controls.applyButton,
|
||||||
|
selectedRange:elements.controls.selectedRange,
|
||||||
|
wholeSheet:elements.controls.wholeSheet
|
||||||
},
|
},
|
||||||
|
|
||||||
polling: {
|
polling: {
|
||||||
interval:2000,
|
interval:2500,
|
||||||
|
},
|
||||||
|
|
||||||
|
toast: {
|
||||||
|
interval:4000
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// get and apply any stored properties
|
||||||
|
return new Promise (function (resolve, reject) {
|
||||||
|
|
||||||
|
Provoke.run ('Props','getAll')
|
||||||
|
.then( function (result) {
|
||||||
|
var pc = Process.control.sankey.store;
|
||||||
|
|
||||||
|
// the factory settings
|
||||||
|
pc.useStandard = elementer.getStandard();
|
||||||
|
pc.auth = result.auth;
|
||||||
|
|
||||||
|
// any data found in property stores
|
||||||
|
result.saved.forEach(function(d) {
|
||||||
|
pc[d.source] = d.settings;
|
||||||
|
elements.controls[d.source].disabled = d.settings ? false : true;
|
||||||
|
if (d.settings) {
|
||||||
|
elementer.setInitial (d.settings);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// the finally decided upon initial values
|
||||||
|
pc.useInitial = elementer.getInitial();
|
||||||
|
|
||||||
|
// map the values
|
||||||
|
process.applyElementer();
|
||||||
|
resolve (elementer);
|
||||||
|
})
|
||||||
|
['catch'](function (err) {
|
||||||
|
App.showNotification ("failed while getting saved properties ", err);
|
||||||
|
reject (err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,42 +137,51 @@ var Process = (function (process) {
|
||||||
process.drawChart = function (clear) {
|
process.drawChart = function (clear) {
|
||||||
|
|
||||||
//disable inserting
|
//disable inserting
|
||||||
process.control.buttons.insert.disabled=true;
|
process.control.buttons.insert.disabled = false;
|
||||||
|
|
||||||
var sc = process.control.chart;
|
var sc = process.control.chart;
|
||||||
|
var sts = process.control.sankey.settings;
|
||||||
|
var opt = Utils.vanMerge([sc.defOptions, sts.options]);
|
||||||
|
|
||||||
var svg;
|
var svg;
|
||||||
|
|
||||||
if (sc.data.length) {
|
if (sc.data.length) {
|
||||||
// the preview
|
|
||||||
Sankey.drawChart (Sankey.settings , sc.headings, sc.data, sc.elem, clear);
|
|
||||||
|
|
||||||
// the full sized
|
opt.height = opt.height || sc.defOptions.height;
|
||||||
|
opt.width = opt.width || sc.defOptions.width;
|
||||||
|
|
||||||
|
// the preview
|
||||||
|
Sankey.drawChart (opt , sc.headings, sc.data, sc.elem, clear);
|
||||||
|
|
||||||
|
// the full sized chart
|
||||||
svg = scaleChart(clear);
|
svg = scaleChart(clear);
|
||||||
process.control.code.svg.value = (svg && svg.length ? svg[0] : '');
|
process.control.code.svg.value = (svg && svg.length ? svg[0] : '');
|
||||||
|
|
||||||
// the picker sized
|
|
||||||
svg = scaleChart(clear, {
|
|
||||||
width: process.control.code.pickerWidth / sc.elem.offsetWidth ,
|
|
||||||
height: process.control.code.pickerHeight / sc.elem.offsetHeight,
|
|
||||||
font: process.control.code.pickerHeight / sc.elem.offsetHeight
|
|
||||||
} );
|
|
||||||
|
|
||||||
process.control.code.picker.value = (svg && svg.length ? svg[0] : '');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function scaleChart(clear, divScale) {
|
function scaleChart(clear, divScale) {
|
||||||
|
|
||||||
// scale up the real one
|
// scale up the real one
|
||||||
var big = Utils.clone(Sankey.settings);
|
var big = Utils.clone(sts);
|
||||||
var scale = divScale || big.scale;
|
var scale = divScale || big.scale;
|
||||||
|
|
||||||
big.height = Sankey.settings.height * scale.height;
|
var big = Utils.vanMerge([opt, {
|
||||||
big.width = Sankey.settings.width * scale.width;
|
height: opt.height * scale.height,
|
||||||
big.sankey.node.label.fontSize = Sankey.settings.sankey.node.label.fontSize * scale.font;
|
width: opt.width * scale.width,
|
||||||
big.sankey.node.labelPadding = Sankey.settings.sankey.node.labelPadding * scale.width;
|
sankey: {
|
||||||
big.sankey.node.nodePadding = Sankey.settings.sankey.node.nodePadding * scale.height;
|
node: {
|
||||||
big.sankey.node.width = Sankey.settings.sankey.node.width * scale.height;
|
label: {
|
||||||
|
fontSize: opt.sankey.node.label.fontSize * scale.font
|
||||||
|
},
|
||||||
|
labelPadding: opt.sankey.node.labelPadding * scale.width,
|
||||||
|
nodePadding: opt.sankey.node.nodePadding * scale.height,
|
||||||
|
width: opt.sankey.node.width * scale.width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Sankey.drawChart (big , sc.headings, sc.data, sc.ghost, clear);
|
Sankey.drawChart (big , sc.headings, sc.data, sc.ghost, clear);
|
||||||
// set up svg code for copying
|
// set up svg code for copying
|
||||||
|
@ -106,7 +189,7 @@ var Process = (function (process) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process.control.buttons.insert.disabled = process.control.buttons.save.disabled = !svg;
|
process.control.buttons.insert.disabled = !svg;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -179,7 +262,7 @@ var Process = (function (process) {
|
||||||
process.drawChart(result.clear);
|
process.drawChart(result.clear);
|
||||||
|
|
||||||
// enable inserting
|
// enable inserting
|
||||||
Utils.el("insert-button").disabled = false;
|
process.control.buttons.insert.disabled = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +274,7 @@ var Process = (function (process) {
|
||||||
*/
|
*/
|
||||||
process.startPolling = function () {
|
process.startPolling = function () {
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
Client.getData();
|
Client.getData(true);
|
||||||
}, process.control.polling.interval);
|
}, process.control.polling.interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue