Removed unnecessary comments. Added feature to update element either on "change" or on "slide" event.
This commit is contained in:
committed by
Alexander Kryklia
parent
052dc3fa22
commit
77962e3cdb
@@ -25,7 +25,7 @@ define('ElOutput', ['logme'], function (logme) {
|
||||
return;
|
||||
|
||||
function processFuncObj(obj) {
|
||||
var paramNames, funcString, func, special, el, disableAutoReturn;
|
||||
var paramNames, funcString, func, el, disableAutoReturn, updateOnEvent;
|
||||
|
||||
// We are only interested in functions that are meant for output to an
|
||||
// element.
|
||||
@@ -48,6 +48,15 @@ define('ElOutput', ['logme'], function (logme) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateOnEvent = 'slide';
|
||||
if (
|
||||
(obj.hasOwnProperty('@update_on') === true) &&
|
||||
(typeof obj['@update_on'] === 'string') &&
|
||||
((obj['@update_on'].toLowerCase() === 'slide') || (obj['@update_on'].toLowerCase() === 'change'))
|
||||
) {
|
||||
updateOnEvent = obj['@update_on'].toLowerCase();
|
||||
}
|
||||
|
||||
disableAutoReturn = obj['@disable_auto_return'];
|
||||
|
||||
funcString = obj['#text'];
|
||||
@@ -99,25 +108,20 @@ define('ElOutput', ['logme'], function (logme) {
|
||||
|
||||
paramNames.pop();
|
||||
|
||||
special = false;
|
||||
if (obj['@el_id'][0] === '_') {
|
||||
special = true;
|
||||
} else {
|
||||
el = $('#' + obj['@el_id']);
|
||||
el = $('#' + obj['@el_id']);
|
||||
|
||||
if (el.length !== 1) {
|
||||
logme(
|
||||
'ERROR: DOM element with ID "' + obj['@el_id'] + '" ' +
|
||||
'not found. Dynamic element not created.'
|
||||
);
|
||||
if (el.length !== 1) {
|
||||
logme(
|
||||
'ERROR: DOM element with ID "' + obj['@el_id'] + '" ' +
|
||||
'not found. Dynamic element not created.'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
el.html(func.apply(window, state.getAllParameterValues()));
|
||||
return;
|
||||
}
|
||||
|
||||
state.addDynamicEl(el, func, obj['@el_id'], special);
|
||||
el.html(func.apply(window, state.getAllParameterValues()));
|
||||
|
||||
state.addDynamicEl(el, func, obj['@el_id'], updateOnEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,9 +57,6 @@ define('Graph', ['logme'], function (logme) {
|
||||
getBarWidth();
|
||||
getBarAlign();
|
||||
|
||||
logme('graphBarWidth = ' + graphBarWidth);
|
||||
logme('graphBarAlign = ' + graphBarAlign);
|
||||
|
||||
// Get the user defined functions. If there aren't any, don't do
|
||||
// anything else.
|
||||
createFunctions();
|
||||
@@ -1119,7 +1116,7 @@ define('Graph', ['logme'], function (logme) {
|
||||
}
|
||||
|
||||
function generateData() {
|
||||
var c0, c1, functionObj, seriesObj, dataPoints, paramValues, x, y,
|
||||
var c0, c1, c3, functionObj, seriesObj, dataPoints, paramValues, x, y,
|
||||
start, end, step, numNotUndefined;
|
||||
|
||||
paramValues = state.getAllParameterValues();
|
||||
@@ -1289,17 +1286,18 @@ define('Graph', ['logme'], function (logme) {
|
||||
numNotUndefined = 0;
|
||||
|
||||
for (c1 = 0; c1 < dataSeries.length; c1 += 1) {
|
||||
logme('c1 = ' + c1 + ', dataSeries[c1].data[c0][1] = ' + dataSeries[c1].data[c0][1]);
|
||||
|
||||
if (isFinite(parseInt(dataSeries[c1].data[c0][1])) === true) {
|
||||
numNotUndefined += 1;
|
||||
}
|
||||
}
|
||||
|
||||
logme('Point number = ' + c0 + ', numNotUndefined = ' + numNotUndefined);
|
||||
|
||||
c3 = 0;
|
||||
for (c1 = 0; c1 < dataSeries.length; c1 += 1) {
|
||||
dataSeries[c1].data[c0][0] -= graphBarWidth * (0.5 * numNotUndefined - c1);
|
||||
dataSeries[c1].data[c0][0] -= graphBarWidth * (0.5 * numNotUndefined - c3);
|
||||
|
||||
if (isFinite(parseInt(dataSeries[c1].data[c0][1])) === true) {
|
||||
c3 += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ define('Sliders', ['logme'], function (logme) {
|
||||
return Sliders;
|
||||
|
||||
function Sliders(gstId, state) {
|
||||
var c1, paramName, allParamNames, sliderDiv, onEvent;
|
||||
var c1, paramName, allParamNames, sliderDiv;
|
||||
|
||||
allParamNames = state.getAllParameterNames();
|
||||
|
||||
@@ -16,12 +16,7 @@ define('Sliders', ['logme'], function (logme) {
|
||||
sliderDiv = $('#' + gstId + '_slider_' + paramName);
|
||||
|
||||
if (sliderDiv.length === 1) {
|
||||
onEvent = 'slide';
|
||||
if (sliderDiv.attr('data-on_event') === 'change') {
|
||||
onEvent = 'slidechange';
|
||||
}
|
||||
|
||||
createSlider(sliderDiv, paramName, onEvent);
|
||||
createSlider(sliderDiv, paramName);
|
||||
} else if (sliderDiv.length > 1) {
|
||||
logme('ERROR: Found more than one slider for the parameter "' + paramName + '".');
|
||||
logme('sliderDiv.length = ', sliderDiv.length);
|
||||
@@ -30,7 +25,7 @@ define('Sliders', ['logme'], function (logme) {
|
||||
}
|
||||
}
|
||||
|
||||
function createSlider(sliderDiv, paramName, onEvent) {
|
||||
function createSlider(sliderDiv, paramName) {
|
||||
var paramObj;
|
||||
|
||||
paramObj = state.getParamObj(paramName);
|
||||
@@ -57,8 +52,9 @@ define('Sliders', ['logme'], function (logme) {
|
||||
// will also update the value of this slider.
|
||||
paramObj.sliderDiv = sliderDiv;
|
||||
|
||||
// Atach a callback to update the slider's parameter.
|
||||
paramObj.sliderDiv.on(onEvent, sliderOnSlide);
|
||||
// Atach callbacks to update the slider's parameter.
|
||||
paramObj.sliderDiv.on('slide', sliderOnSlide);
|
||||
paramObj.sliderDiv.on('slidechange', sliderOnChange);
|
||||
|
||||
return;
|
||||
|
||||
@@ -72,10 +68,15 @@ define('Sliders', ['logme'], function (logme) {
|
||||
// so that the function knows we are a slider, and it can
|
||||
// change the our value back in the case when the new value is
|
||||
// invalid for some reason.
|
||||
if (state.setParameterValue(paramName, ui.value, sliderDiv, true) === undefined) {
|
||||
if (state.setParameterValue(paramName, ui.value, sliderDiv, true, 'slide') === undefined) {
|
||||
logme('ERROR: Could not update the parameter named "' + paramName + '" with the value "' + ui.value + '".');
|
||||
}
|
||||
}
|
||||
|
||||
function sliderOnChange(event, ui) {
|
||||
if (state.setParameterValue(paramName, ui.value, sliderDiv, true, 'change') === undefined) {
|
||||
logme('ERROR: Could not update the parameter named "' + paramName + '" with the value "' + ui.value + '".');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,8 +98,6 @@ define('State', ['logme'], function (logme) {
|
||||
'bindUpdatePlotEvent': bindUpdatePlotEvent,
|
||||
'addDynamicEl': addDynamicEl,
|
||||
|
||||
'getFuncForSpecialLabel': getFuncForSpecialLabel,
|
||||
|
||||
// plde is an abbreviation for Plot Label Dynamic Elements.
|
||||
plde: []
|
||||
};
|
||||
@@ -128,14 +126,14 @@ define('State', ['logme'], function (logme) {
|
||||
plotDiv.bind('update_plot', callback);
|
||||
}
|
||||
|
||||
function addDynamicEl(el, func, elId, special) {
|
||||
function addDynamicEl(el, func, elId, updateOnEvent) {
|
||||
var newLength;
|
||||
|
||||
newLength = dynamicEl.push({
|
||||
'el': el,
|
||||
'func': func,
|
||||
'elId': elId,
|
||||
'special': special
|
||||
'updateOnEvent': updateOnEvent
|
||||
});
|
||||
|
||||
if (typeof dynamicElByElId[elId] !== 'undefined') {
|
||||
@@ -147,16 +145,6 @@ define('State', ['logme'], function (logme) {
|
||||
}
|
||||
}
|
||||
|
||||
function getFuncForSpecialLabel(elId) {
|
||||
if (typeof dynamicElByElId[elId] === 'undefined') {
|
||||
logme('ERROR: Special label with ID "' + elId + '" does not exist.');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return dynamicElByElId[elId].func;
|
||||
}
|
||||
|
||||
function getParameterValue(paramName) {
|
||||
|
||||
// If the name of the constant is not tracked by state, return an
|
||||
@@ -203,7 +191,7 @@ define('State', ['logme'], function (logme) {
|
||||
// original value.
|
||||
//
|
||||
// ####################################################################
|
||||
function setParameterValue(paramName, paramValue, element, slider) {
|
||||
function setParameterValue(paramName, paramValue, element, slider, updateOnEvent) {
|
||||
var paramValueNum, c1;
|
||||
|
||||
// If a parameter with the name specified by the 'paramName'
|
||||
@@ -249,7 +237,10 @@ define('State', ['logme'], function (logme) {
|
||||
allParameterValues[parameters[paramName].helperArrayIndex] = paramValueNum;
|
||||
|
||||
for (c1 = 0; c1 < dynamicEl.length; c1++) {
|
||||
if (dynamicEl[c1].special !== true) {
|
||||
if (
|
||||
((updateOnEvent !== undefined) && (dynamicEl[c1].updateOnEvent === updateOnEvent)) ||
|
||||
(updateOnEvent === undefined)
|
||||
) {
|
||||
dynamicEl[c1].el.html(dynamicEl[c1].func.apply(window, allParameterValues));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user