updated by GasGit automation
This commit is contained in:
parent
3d7019bd40
commit
8b1371bb2b
1 changed files with 95 additions and 40 deletions
|
@ -47,18 +47,25 @@ var Process = (function (process) {
|
||||||
auth:{}
|
auth:{}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
tabs: {
|
||||||
|
settings:DomUtils.elem("elementer-root")
|
||||||
|
},
|
||||||
|
|
||||||
activeHeadings: {
|
activeHeadings: {
|
||||||
from:{
|
from:{
|
||||||
current:'from',
|
current:'',
|
||||||
elem:elements.controls.fromColumn
|
elem:elements.controls.fromColumn,
|
||||||
|
best:'Source'
|
||||||
},
|
},
|
||||||
to: {
|
to: {
|
||||||
current:'to',
|
current:'',
|
||||||
elem:elements.controls.toColumn
|
elem:elements.controls.toColumn,
|
||||||
|
best:'Target'
|
||||||
},
|
},
|
||||||
value:{
|
value:{
|
||||||
current:'value',
|
current:'',
|
||||||
elem:elements.controls.weightColumn
|
elem:elements.controls.weightColumn,
|
||||||
|
best:'Volume'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -67,6 +74,7 @@ var Process = (function (process) {
|
||||||
data:[[]],
|
data:[[]],
|
||||||
elem:DomUtils.elem("chart"),
|
elem:DomUtils.elem("chart"),
|
||||||
ghost:DomUtils.elem("ghost"),
|
ghost:DomUtils.elem("ghost"),
|
||||||
|
instructions:DomUtils.elem("instructions"),
|
||||||
defOptions:{
|
defOptions:{
|
||||||
height:DomUtils.elem("chart").offsetHeight,
|
height:DomUtils.elem("chart").offsetHeight,
|
||||||
width:DomUtils.elem("chart").offsetWidth
|
width:DomUtils.elem("chart").offsetWidth
|
||||||
|
@ -78,7 +86,7 @@ var Process = (function (process) {
|
||||||
},
|
},
|
||||||
|
|
||||||
buttons: {
|
buttons: {
|
||||||
insert:elements.controls.insertButton,
|
insert:DomUtils.elem("insert-button"),
|
||||||
manage:elements.controls.manageButton,
|
manage:elements.controls.manageButton,
|
||||||
apply:elements.controls.applyButton,
|
apply:elements.controls.applyButton,
|
||||||
selectedRange:elements.controls.selectedRange,
|
selectedRange:elements.controls.selectedRange,
|
||||||
|
@ -94,7 +102,7 @@ var Process = (function (process) {
|
||||||
},
|
},
|
||||||
|
|
||||||
toast: {
|
toast: {
|
||||||
interval:4000
|
interval:3500
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -146,12 +154,14 @@ var Process = (function (process) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* draw a sankey chart from the matrix data
|
* draw a sankey chart from the matrix data
|
||||||
* @param {boolean} clear whether to clear current chart first
|
|
||||||
*/
|
*/
|
||||||
process.drawChart = function (clear) {
|
process.drawChart = function () {
|
||||||
|
|
||||||
//disable inserting
|
//disable inserting.. during construction
|
||||||
process.control.buttons.insert.disabled = false;
|
process.control.buttons.insert.disabled = true;
|
||||||
|
|
||||||
|
// no need to clear the chart first
|
||||||
|
var clear = true;
|
||||||
|
|
||||||
var sc = process.control.chart;
|
var sc = process.control.chart;
|
||||||
var sts = process.control.sankey.settings;
|
var sts = process.control.sankey.settings;
|
||||||
|
@ -174,6 +184,18 @@ var Process = (function (process) {
|
||||||
// need to tweak any gradient code so it works outside context of apps script
|
// need to tweak any gradient code so it works outside context of apps script
|
||||||
process.control.code.svg.value = svg[0].replace (/url\([^#]+/g, "url(");
|
process.control.code.svg.value = svg[0].replace (/url\([^#]+/g, "url(");
|
||||||
}
|
}
|
||||||
|
DomUtils.hide (sc.instructions,true);
|
||||||
|
DomUtils.hide (sc.elem,false);
|
||||||
|
|
||||||
|
// enable inserting
|
||||||
|
process.control.buttons.insert.disabled = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// no viable data so reveal instructions and disable insertion
|
||||||
|
process.control.buttons.insert.disabled = true;
|
||||||
|
DomUtils.hide (sc.elem,true);
|
||||||
|
DomUtils.hide (sc.instructions,false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,46 +228,81 @@ var Process = (function (process) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process.control.buttons.insert.disabled = !svg;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
process.selectFields = function () {
|
process.selectFields = function () {
|
||||||
var sc = process.control;
|
var sc = process.control;
|
||||||
|
|
||||||
// duplicate removal
|
// goodheadings will contain the potential headings
|
||||||
var goodHeadings = sc.headings.filter(function(d,i,a) {
|
var goodHeadings = sc.headings.filter(function(d,i,a) {
|
||||||
return a.indexOf(d) === i && d;
|
return a.indexOf(d) === i && d;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// make active headings/ deleting them if not there, along with the chart headings
|
// make active headings/ deleting them if not there, along with the chart headings
|
||||||
sc.chart.headings = Object.keys(sc.activeHeadings).map (function(k,i) {
|
sc.chart.headings = Object.keys(sc.activeHeadings).map (function(k) {
|
||||||
|
|
||||||
// the object describing each data column
|
// the object describing each data column
|
||||||
var d = sc.activeHeadings[k];
|
var d = sc.activeHeadings[k];
|
||||||
|
var options = DomUtils.getOptions(d.elem);
|
||||||
|
|
||||||
// set to the currently selected value
|
// sliced the first one which is a null option if it exists
|
||||||
d.current = d.elem.value || d.current;
|
if (!options.length || !Utils.isSameAs (goodHeadings, options.slice(1))) {
|
||||||
|
|
||||||
// default to positional if we cant find a match .. this would be first time round
|
// we have a potentially new set of options, rebuild the select
|
||||||
if (goodHeadings.indexOf(d.current) === -1) d.current = goodHeadings.length > i ? goodHeadings[i] : undefined;
|
var selected = d.elem.value;
|
||||||
|
|
||||||
|
d.elem.innerHTML= "";
|
||||||
|
d.current = d.elem.value = "";
|
||||||
|
|
||||||
// redo the select options
|
// add a null option
|
||||||
d.current = View.buildSelectElem (goodHeadings , d.elem , d.current);
|
DomUtils.addElem (d.elem,"option");
|
||||||
|
goodHeadings.forEach(function (e) {
|
||||||
|
var op = DomUtils.addElem (d.elem,"option");
|
||||||
|
op.value = e;
|
||||||
|
op.text = e;
|
||||||
|
});
|
||||||
|
|
||||||
|
// and if currently selected is no longer in the list then we need to cancel it
|
||||||
|
if (goodHeadings.indexOf(selected) === -1) {
|
||||||
|
d.elem.value = d.current = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (selected) {
|
||||||
|
d.current = d.elem.value = selected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
})
|
||||||
|
.map (function (d,i,a) {
|
||||||
|
// now we need to deduce new values
|
||||||
|
if (!d.current && !a.some(function(e) { return e.current === d.best })) {
|
||||||
|
// we dont have a selection for this one, and its not being used by someone else so use the default
|
||||||
|
if (goodHeadings.indexOf(d.best) !== -1) {
|
||||||
|
d.current = d.best;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if that didnt find anything then use the position
|
||||||
|
if (!d.current && goodHeadings.length > i && !a.some(function(e) { return e.current === goodHeadings[i] ; })) {
|
||||||
|
d.current = goodHeadings[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// now set the select value to whatever it now is
|
||||||
|
d.elem.value = d.current;
|
||||||
return d.current;
|
return d.current;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// make the chart data
|
// make the chart data
|
||||||
sc.chart.data = sc.dataObjects.map (function (row) {
|
var sh = sc.chart.headings;
|
||||||
return sc.chart.headings.map(function(d) {
|
|
||||||
|
sc.chart.data = sh.every(function(d) { return d;}) && Utils.unique(sh).length === Object.keys(sc.activeHeadings).length ?
|
||||||
|
sc.dataObjects.map ( function (row) {
|
||||||
|
return sh.map(function(d) {
|
||||||
return row[d];
|
return row[d];
|
||||||
});
|
})
|
||||||
});
|
}) : [];
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* fix up and store data received from server
|
* fix up and store data received from server
|
||||||
|
@ -277,8 +334,6 @@ var Process = (function (process) {
|
||||||
process.selectFields();
|
process.selectFields();
|
||||||
process.drawChart();
|
process.drawChart();
|
||||||
|
|
||||||
// enable inserting
|
|
||||||
process.control.buttons.insert.disabled = false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue