updated by GasGit automation

This commit is contained in:
Bruce McPherson 2016-05-24 15:08:09 +01:00
parent 74b8a67fd6
commit d1ca25f508

View file

@ -1,59 +1,133 @@
// stuff that is common to both Apps Script and Office
// define it
/**
* manages the connection between the data and the chart
* @namespace Process
*/
var Process = (function (process) {
'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 () {
var sankeySetup = Sankey.setup();
// this will create the structure for retrieving settings
var elementer = Sankey.doElementer(sankeySetup);
var elements = elementer.getElements();
process.control = {
result: {
data:undefined,
checksum:undefined
},
sankey:{
setup:sankeySetup,
elementer:elementer,
settings:{},
store:{
useInitial:null,
useStandard:null,
useUser:null,
useDocument:null
},
auth:{}
},
activeHeadings: {
from:{
current:'from',
elem:Utils.el('from-column')
elem:elements.controls.fromColumn
},
to: {
current:'to',
elem:Utils.el('to-column')
elem:elements.controls.toColumn
},
value:{
current:'value',
elem:Utils.el('value-column')
elem:elements.controls.weightColumn
}
},
chart: {
headings:[],
data:[[]],
elem:Utils.el("chart"),
ghost:Utils.el("ghost"),
picker:Utils.el("picker-preview")
elem:DomUtils.elem("chart"),
ghost:DomUtils.elem("ghost"),
defOptions:{
height:DomUtils.elem("chart").offsetHeight,
width:DomUtils.elem("chart").offsetWidth
}
},
code: {
svg:Utils.el("chart-code-svg"),
picker:Utils.el("picker-code-svg"),
pickerHeight:520*.7,
pickerWidth:600*.9
svg:elements.controls.svgCode
},
buttons: {
save: Utils.el("save-button"),
insert:Utils.el("insert-button")
insert:elements.controls.insertButton,
manage:elements.controls.manageButton,
apply:elements.controls.applyButton,
selectedRange:elements.controls.selectedRange,
wholeSheet:elements.controls.wholeSheet
},
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) {
//disable inserting
process.control.buttons.insert.disabled=true;
process.control.buttons.insert.disabled = false;
var sc = process.control.chart;
var sts = process.control.sankey.settings;
var opt = Utils.vanMerge([sc.defOptions, sts.options]);
var svg;
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);
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) {
// scale up the real one
var big = Utils.clone(Sankey.settings);
var big = Utils.clone(sts);
var scale = divScale || big.scale;
big.height = Sankey.settings.height * scale.height;
big.width = Sankey.settings.width * scale.width;
big.sankey.node.label.fontSize = Sankey.settings.sankey.node.label.fontSize * scale.font;
big.sankey.node.labelPadding = Sankey.settings.sankey.node.labelPadding * scale.width;
big.sankey.node.nodePadding = Sankey.settings.sankey.node.nodePadding * scale.height;
big.sankey.node.width = Sankey.settings.sankey.node.width * scale.height;
var big = Utils.vanMerge([opt, {
height: opt.height * scale.height,
width: opt.width * scale.width,
sankey: {
node: {
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);
// 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);
// 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 () {
setTimeout(function(){
Client.getData();
Client.getData(true);
}, process.control.polling.interval);
}