_id
stringlengths 2
6
| title
stringlengths 0
58
| partition
stringclasses 3
values | text
stringlengths 52
373k
| language
stringclasses 1
value | meta_information
dict |
|---|---|---|---|---|---|
q21000
|
bgTextRuleString
|
train
|
function bgTextRuleString(className, options) {
return classRule(className)
.bg(options.background)
.text(options.text)
.build();
}
|
javascript
|
{
"resource": ""
}
|
q21001
|
bgBorderRuleString
|
train
|
function bgBorderRuleString(className, options) {
return classRule(className)
.bg(options.background)
.border(options.border)
.build();
}
|
javascript
|
{
"resource": ""
}
|
q21002
|
train
|
function(options) {
var borderTopRule = classRule(classNameConst.BORDER_TOP).bg(options.border);
var borderBottomRule = classComposeRule(' .', [
classNameConst.NO_SCROLL_X,
classNameConst.BORDER_BOTTOM
]).bg(options.border);
var rules = [
borderTopRule,
borderBottomRule
];
var borderLeftRule, borderRightRule;
if (options.showVerticalBorder) {
borderLeftRule = classRule(classNameConst.BORDER_LEFT).bg(options.border);
borderRightRule = classComposeRule(' .', [
classNameConst.NO_SCROLL_Y,
classNameConst.BORDER_RIGHT
]).bg(options.border);
rules = rules.concat([borderLeftRule, borderRightRule]);
}
return builder.buildAll(rules);
}
|
javascript
|
{
"resource": ""
}
|
|
q21003
|
train
|
function(options) {
var webkitScrollbarRules = builder.createWebkitScrollbarRules('.' + classNameConst.CONTAINER, options);
var ieScrollbarRule = builder.createIEScrollbarRule('.' + classNameConst.CONTAINER, options);
var xInnerBorderRule = classRule(classNameConst.BORDER_BOTTOM).bg(options.border);
var xOuterBorderRule = classRule(classNameConst.CONTENT_AREA).border(options.border);
var yInnerBorderRule = classRule(classNameConst.SCROLLBAR_Y_INNER_BORDER).bg(options.border);
var yOuterBorderRule = classRule(classNameConst.SCROLLBAR_Y_OUTER_BORDER).bg(options.border);
var spaceRightTopRule = classRule(classNameConst.SCROLLBAR_RIGHT_TOP)
.bg(options.emptySpace)
.border(options.border);
var spaceRightBottomRule = classRule(classNameConst.SCROLLBAR_RIGHT_BOTTOM)
.bg(options.emptySpace)
.border(options.border);
var spaceLeftBottomRule = classRule(classNameConst.SCROLLBAR_LEFT_BOTTOM)
.bg(options.emptySpace)
.border(options.border);
var frozenBorderRule = classRule(classNameConst.SCROLLBAR_FROZEN_BORDER)
.bg(options.emptySpace)
.border(options.border);
return builder.buildAll(webkitScrollbarRules.concat([
ieScrollbarRule,
xInnerBorderRule,
xOuterBorderRule,
yInnerBorderRule,
yOuterBorderRule,
spaceRightTopRule,
spaceRightBottomRule,
spaceLeftBottomRule,
frozenBorderRule
]));
}
|
javascript
|
{
"resource": ""
}
|
|
q21004
|
train
|
function(options) {
return classRule(classNameConst.HEAD_AREA)
.bg(options.background)
.border(options.border)
.build();
}
|
javascript
|
{
"resource": ""
}
|
|
q21005
|
train
|
function(options) {
var contentAreaRule = classRule(classNameConst.SUMMARY_AREA)
.bg(options.background)
.border(options.border);
var bodyAreaRule = classComposeRule(' .', [
classNameConst.HAS_SUMMARY_TOP,
classNameConst.BODY_AREA
]).border(options.border);
return builder.buildAll([
contentAreaRule,
bodyAreaRule
]);
}
|
javascript
|
{
"resource": ""
}
|
|
q21006
|
train
|
function(options) {
return classRule(classNameConst.CELL)
.bg(options.background)
.border(options.border)
.borderWidth(options)
.text(options.text)
.build();
}
|
javascript
|
{
"resource": ""
}
|
|
q21007
|
train
|
function(options) {
return classComposeRule('.', [
classNameConst.CELL_HEAD,
classNameConst.CELL_SELECTED
]).bg(options.background)
.text(options.text)
.build();
}
|
javascript
|
{
"resource": ""
}
|
|
q21008
|
train
|
function(options) {
var focusLayerRule = classRule(classNameConst.LAYER_FOCUS_BORDER).bg(options.border);
var editingLayerRule = classRule(classNameConst.LAYER_EDITING).border(options.border);
return builder.buildAll([focusLayerRule, editingLayerRule]);
}
|
javascript
|
{
"resource": ""
}
|
|
q21009
|
train
|
function(options) {
return classComposeRule(' .', [
classNameConst.LAYER_FOCUS_DEACTIVE,
classNameConst.LAYER_FOCUS_BORDER
]).bg(options.border).build();
}
|
javascript
|
{
"resource": ""
}
|
|
q21010
|
setDataInSpanRange
|
train
|
function setDataInSpanRange(value, data, colspanRange, rowspanRange) {
var startColspan = colspanRange[0];
var endColspan = colspanRange[1];
var startRowspan = rowspanRange[0];
var endRowspan = rowspanRange[1];
var cIndex, rIndex;
for (rIndex = startRowspan; rIndex < endRowspan; rIndex += 1) {
for (cIndex = startColspan; cIndex < endColspan; cIndex += 1) {
data[rIndex][cIndex] = ((startRowspan === rIndex) &&
(startColspan === cIndex)) ? value : ' ';
}
}
}
|
javascript
|
{
"resource": ""
}
|
q21011
|
train
|
function(table) {
var data = [];
var rows = table.rows;
var index = 0;
var length = rows.length;
var columnIndex, colspanRange, rowspanRange;
// Step 1: Init the data matrix
for (; index < length; index += 1) {
data[index] = [];
}
// Step 2: Traverse the table
_.each(rows, function(tr, rowIndex) {
columnIndex = 0;
_.each(tr.cells, function(td) {
var text = td.textContent || td.innerText;
while (data[rowIndex][columnIndex]) {
columnIndex += 1;
}
colspanRange = [columnIndex, columnIndex + (td.colSpan || 1)];
rowspanRange = [rowIndex, rowIndex + (td.rowSpan || 1)];
// Step 3: Set the value of td element to the data matrix as colspan and rowspan ranges
setDataInSpanRange(text, data, colspanRange, rowspanRange);
columnIndex = colspanRange[1];
});
});
return data;
}
|
javascript
|
{
"resource": ""
}
|
|
q21012
|
train
|
function(text) {
// Each newline cell data is wrapping double quotes in the text and
// newline characters should be replaced with substitution characters temporarily
// before spliting the text by newline characters.
text = clipboardUtil.replaceNewlineToSubchar(text);
return _.map(text.split(/\r?\n/), function(row) {
return _.map(row.split('\t'), function(column) {
column = clipboardUtil.removeDoubleQuotes(column);
return column.replace(CUSTOM_LF_REGEXP, LF)
.replace(CUSTOM_CR_REGEXP, CR);
});
});
}
|
javascript
|
{
"resource": ""
}
|
|
q21013
|
train
|
function(text) {
if (text.match(CUSTOM_LF_REGEXP)) {
text = text.substring(1, text.length - 1)
.replace(/""/g, '"');
}
return text;
}
|
javascript
|
{
"resource": ""
}
|
|
q21014
|
train
|
function(text) {
return text.replace(/"([^"]|"")*"/g, function(value) {
return value.replace(LF, CUSTOM_LF_SUBCHAR)
.replace(CR, CUSTOM_CR_SUBCHAR);
});
}
|
javascript
|
{
"resource": ""
}
|
|
q21015
|
train
|
function() {
var dimensionModel, height;
if (this.$scrollBorder) {
dimensionModel = this.dimensionModel;
height = dimensionModel.get('bodyHeight') - dimensionModel.getScrollXHeight();
this.$scrollBorder.height(height);
}
}
|
javascript
|
{
"resource": ""
}
|
|
q21016
|
train
|
function() {
var dimensionModel = this.dimensionModel;
var scrollX = dimensionModel.get('scrollX');
var scrollY = dimensionModel.get('scrollY');
var spaceHeights = this._getSpaceHeights(scrollX, scrollY);
this._setScrollbar(scrollX, scrollY, spaceHeights);
if (dimensionModel.get('frozenBorderWidth')) {
this._setFrozenBorder(scrollX);
}
this._resetScrollBorderHeight();
}
|
javascript
|
{
"resource": ""
}
|
|
q21017
|
train
|
function(scrollX, scrollY) {
var dimensionModel = this.dimensionModel;
var summaryHeight = dimensionModel.get('summaryHeight');
var summaryPosition = dimensionModel.get('summaryPosition');
var topHeight = dimensionModel.get('headerHeight');
var bottomHeight = scrollX ? dimensionConst.SCROLLBAR_WIDTH : 0;
if (scrollY && summaryHeight) {
if (summaryPosition === summaryPositionConst.TOP) {
topHeight += summaryHeight + dimensionConst.TABLE_BORDER_WIDTH;
} else {
bottomHeight += summaryHeight;
}
}
return {
top: topHeight,
bottom: bottomHeight
};
}
|
javascript
|
{
"resource": ""
}
|
|
q21018
|
train
|
function(scrollX, scrollY, spaceHeights) {
var $yInnerBorder, $yOuterBorder, $spaceRightTop, $spaceRightBottom, $frozenBorder;
if (scrollX) {
$frozenBorder = createDiv(classNameConst.SCROLLBAR_FROZEN_BORDER, {
height: dimensionConst.SCROLLBAR_WIDTH
});
}
if (scrollY) {
// subtract 2px for border-width (top and bottom)
$spaceRightTop = createDiv(classNameConst.SCROLLBAR_RIGHT_TOP, {
height: spaceHeights.top - 2
});
$yInnerBorder = createDiv(classNameConst.SCROLLBAR_Y_INNER_BORDER, {
top: spaceHeights.top
});
$yOuterBorder = createDiv(classNameConst.SCROLLBAR_Y_OUTER_BORDER);
}
if (scrollX || scrollY) {
$spaceRightBottom = createDiv(classNameConst.SCROLLBAR_RIGHT_BOTTOM, {
height: spaceHeights.bottom
});
}
this.$el.append(
$yInnerBorder,
$yOuterBorder,
$spaceRightTop,
$spaceRightBottom,
$frozenBorder
);
this.$scrollBorder = $yInnerBorder;
}
|
javascript
|
{
"resource": ""
}
|
|
q21019
|
train
|
function() {
var dimensionModel = this.dimensionModel;
var headerHeight = dimensionModel.get('headerHeight');
var frozenBorderWidth = dimensionModel.get('frozenBorderWidth');
var resizeHandleView = this.viewFactory.createHeaderResizeHandle(frameConst.L, [headerHeight], true);
var $resizeHanlder = resizeHandleView.render().$el;
var $frozenBorder = createDiv(classNameConst.FROZEN_BORDER, {
marginLeft: -frozenBorderWidth,
width: frozenBorderWidth
});
this.$el.append($resizeHanlder, $frozenBorder)
.find('.' + classNameConst.SCROLLBAR_FROZEN_BORDER)
.css({
marginLeft: -(frozenBorderWidth + CELL_BORDER_WIDTH),
width: frozenBorderWidth
});
}
|
javascript
|
{
"resource": ""
}
|
|
q21020
|
getKeyStrokeString
|
train
|
function getKeyStrokeString(ev) {
var keys = [];
if (ev.ctrlKey || ev.metaKey) {
keys.push('ctrl');
}
if (ev.shiftKey) {
keys.push('shift');
}
keys.push(keyNameMap[ev.keyCode]);
return keys.join('-');
}
|
javascript
|
{
"resource": ""
}
|
q21021
|
buildCssString
|
train
|
function buildCssString(options) {
var styles = [
styleGen.outline(options.outline),
styleGen.frozenBorder(options.frozenBorder),
styleGen.scrollbar(options.scrollbar),
styleGen.heightResizeHandle(options.heightResizeHandle),
styleGen.pagination(options.pagination),
styleGen.selection(options.selection)
];
var area = options.area;
var cell = options.cell;
styles = styles.concat([
styleGen.headArea(area.header),
styleGen.bodyArea(area.body),
styleGen.summaryArea(area.summary)
]);
if (cell) {
styles = styles.concat([
styleGen.cell(cell.normal),
styleGen.cellDummy(cell.dummy),
styleGen.cellEditable(cell.editable),
styleGen.cellHead(cell.head),
styleGen.cellRowHead(cell.rowHead),
styleGen.cellSummary(cell.summary),
styleGen.cellOddRow(cell.oddRow),
styleGen.cellEvenRow(cell.evenRow),
styleGen.cellRequired(cell.required),
styleGen.cellDisabled(cell.disabled),
styleGen.cellInvalid(cell.invalid),
styleGen.cellCurrentRow(cell.currentRow),
styleGen.cellSelectedHead(cell.selectedHead),
styleGen.cellSelectedRowHead(cell.selectedRowHead),
styleGen.cellFocused(cell.focused),
styleGen.cellFocusedInactive(cell.focusedInactive)
]);
}
return styles.join('');
}
|
javascript
|
{
"resource": ""
}
|
q21022
|
setDocumentStyle
|
train
|
function setDocumentStyle(options) {
var cssString = buildCssString(options);
$('#' + STYLE_ELEMENT_ID).remove();
util.appendStyleElement(STYLE_ELEMENT_ID, cssString);
}
|
javascript
|
{
"resource": ""
}
|
q21023
|
train
|
function(themeName, extOptions) {
var options = presetOptions[themeName];
if (!options) {
options = presetOptions[themeNameConst.DEFAULT];
}
options = $.extend(true, {}, options, extOptions);
setDocumentStyle(options);
}
|
javascript
|
{
"resource": ""
}
|
|
q21024
|
getSameColumnCount
|
train
|
function getSameColumnCount(currentColumn, prevColumn) {
var index = 0;
var len = Math.min(currentColumn.length, prevColumn.length);
for (; index < len; index += 1) {
if (currentColumn[index].name !== prevColumn[index].name) {
break;
}
}
return index;
}
|
javascript
|
{
"resource": ""
}
|
q21025
|
train
|
function() {
var columnRange = this.selectionModel.get('range').column;
var visibleColumns = this.columnModel.getVisibleColumns();
var selectedColumns = visibleColumns.slice(columnRange[0], columnRange[1] + 1);
return _.pluck(selectedColumns, 'name');
}
|
javascript
|
{
"resource": ""
}
|
|
q21026
|
train
|
function(columnNames) {
var columnModel = this.columnModel;
var mergedColumnNames = _.pluck(columnModel.get('complexHeaderColumns'), 'name');
return _.filter(mergedColumnNames, function(mergedColumnName) {
var unitColumnNames = columnModel.getUnitColumnNamesIfMerged(mergedColumnName);
return _.every(unitColumnNames, function(name) {
return _.contains(columnNames, name);
});
});
}
|
javascript
|
{
"resource": ""
}
|
|
q21027
|
train
|
function(ev) {
var $target = $(ev.target);
var columnName;
if (!this._triggerPublicMousedown(ev)) {
return;
}
if ($target.hasClass(classNameConst.BTN_SORT)) {
return;
}
columnName = $target.closest('th').attr(ATTR_COLUMN_NAME);
if (columnName) {
this.dragEmitter.start(ev, {
columnName: columnName
});
}
}
|
javascript
|
{
"resource": ""
}
|
|
q21028
|
train
|
function(ev) {
var $target = $(ev.target);
var columnName = $target.closest('th').attr(ATTR_COLUMN_NAME);
var eventData = new GridEvent(ev);
if (columnName === '_button' && $target.is('input')) {
eventData.setData({
checked: $target.prop('checked')
});
this.domEventBus.trigger('click:headerCheck', eventData);
} else if ($target.is('a.' + classNameConst.BTN_SORT)) {
eventData.setData({
columnName: columnName
});
this.domEventBus.trigger('click:headerSort', eventData);
}
}
|
javascript
|
{
"resource": ""
}
|
|
q21029
|
train
|
function() {
var hierarchyList = this._getColumnHierarchyList();
var maxRowCount = this._getHierarchyMaxRowCount(hierarchyList);
var rowHeight = util.getRowHeight(maxRowCount, this.headerHeight) - 1;
var handleHeights = [];
var index = 1;
var coulmnLen = hierarchyList.length;
var sameColumnCount, handleHeight;
for (; index < coulmnLen; index += 1) {
sameColumnCount = getSameColumnCount(hierarchyList[index], hierarchyList[index - 1]);
handleHeight = rowHeight * (maxRowCount - sameColumnCount);
handleHeights.push(handleHeight);
}
handleHeights.push(rowHeight * maxRowCount); // last resize handle
return handleHeights;
}
|
javascript
|
{
"resource": ""
}
|
|
q21030
|
setConfig
|
train
|
function setConfig(defaultConfig, server) {
if (server === 'ne') {
defaultConfig.captureTimeout = 100000;
defaultConfig.customLaunchers = {
'IE8': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '8'
},
'IE9': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '9'
},
'IE10': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '10'
},
'IE11': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'internet explorer',
version: '11'
},
'Edge': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'MicrosoftEdge'
},
'Chrome-WebDriver': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'chrome'
},
'Firefox-WebDriver': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'firefox'
},
'Safari-WebDriver': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'safari'
}
};
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
defaultConfig.browsers = [
'IE8',
'IE9',
'IE10',
'IE11',
'Edge',
'Chrome-WebDriver',
'Firefox-WebDriver'
// 'Safari-WebDriver' // active only when safari test is needed
];
defaultConfig.webpack.module.preLoaders = [{
test: /\.js$/,
include: path.resolve('./src/js'),
loader: 'istanbul-instrumenter'
}];
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
defaultConfig.reporters = [
'dots',
'coverage',
'junit'
];
// optionally, configure the reporter
defaultConfig.coverageReporter = {
dir: 'report/coverage/',
reporters: [
{
type: 'html',
subdir: function(browser) {
return 'report-html/' + browser;
}
},
{
type: 'cobertura',
subdir: function(browser) {
return 'report-cobertura/' + browser;
},
file: 'cobertura.txt'
}
]
};
defaultConfig.junitReporter = {
outputDir: 'report/junit',
suite: ''
};
} else {
defaultConfig.captureTimeout = 60000;
defaultConfig.reporters = [
'karmaSimpleReporter'
];
defaultConfig.specReporter = {
suppressPassed: true,
suppressSkipped: true,
suppressErrorSummary: true
};
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
defaultConfig.browsers = [
'ChromeHeadless'
];
}
}
|
javascript
|
{
"resource": ""
}
|
q21031
|
train
|
function(arr) {
return {
min: Math.min.apply(null, arr),
max: Math.max.apply(null, arr)
};
}
|
javascript
|
{
"resource": ""
}
|
|
q21032
|
train
|
function(obj) {
var pruned = {};
_.each(obj, function(value, key) {
if (!_.isUndefined(value) && !_.isNull(value)) {
pruned[key] = value;
}
});
return pruned;
}
|
javascript
|
{
"resource": ""
}
|
|
q21033
|
train
|
function(targetObj, distObj) {
var result = false;
snippet.forEach(targetObj, function(item, key) {
result = (item === distObj[key]);
return result;
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q21034
|
train
|
function(target) {
if (_.isString(target)) {
return !target.length;
}
return _.isUndefined(target) || _.isNull(target);
}
|
javascript
|
{
"resource": ""
}
|
|
q21035
|
train
|
function(id, cssString) {
var style = document.createElement('style');
style.type = 'text/css';
style.id = id;
if (style.styleSheet) {
style.styleSheet.cssText = cssString;
} else {
style.appendChild(document.createTextNode(cssString));
}
document.getElementsByTagName('head')[0].appendChild(style);
}
|
javascript
|
{
"resource": ""
}
|
|
q21036
|
train
|
function(ev) {
var rightClick;
ev = ev || window.event;
if (ev.which) {
rightClick = ev.which === 3;
} else if (ev.button) {
rightClick = ev.button === 2;
}
return rightClick;
}
|
javascript
|
{
"resource": ""
}
|
|
q21037
|
train
|
function() {
var factory = this.viewFactory;
this._addChildren([
factory.createFrame(frameConst.L),
factory.createFrame(frameConst.R)
]);
}
|
javascript
|
{
"resource": ""
}
|
|
q21038
|
train
|
function() {
var datePickerMap = {};
var columnModelMap = this.columnModel.get('columnModelMap');
_.each(columnModelMap, function(columnModel) {
var name = columnModel.name;
var component = columnModel.component;
var options;
if (component && component.name === 'datePicker') {
options = component.options || {};
datePickerMap[name] = new DatePicker(this.$el, options);
this._bindEventOnDatePicker(datePickerMap[name]);
}
}, this);
return datePickerMap;
}
|
javascript
|
{
"resource": ""
}
|
|
q21039
|
train
|
function(datePicker) {
var self = this;
datePicker.on('open', function() {
self.textPainter.blockFocusingOut();
});
datePicker.on('close', function() {
var focusModel = self.focusModel;
var address = focusModel.which();
var rowKey = address.rowKey;
var columnName = address.columnName;
var changedValue = self.$focusedInput.val();
self.textPainter.unblockFocusingOut();
// when the datePicker layer is closed, selected date must set on input element.
if (focusModel.isEditingCell(rowKey, columnName)) {
focusModel.dataModel.setValue(rowKey, columnName, changedValue);
}
focusModel.finishEditing();
});
}
|
javascript
|
{
"resource": ""
}
|
|
q21040
|
train
|
function(options, $input, columnName) {
var datePicker = this.datePickerMap[columnName];
var format = options.format || DEFAULT_DATE_FORMAT;
var date = options.date || (new Date());
var selectableRanges = options.selectableRanges;
datePicker.setInput($input, {
format: format,
syncFromInput: true
});
if (selectableRanges) {
datePicker.setRanges(selectableRanges);
} else {
datePicker.setRanges(FULL_RANGES);
}
if ($input.val() === '') {
datePicker.setDate(date);
$input.val('');
}
}
|
javascript
|
{
"resource": ""
}
|
|
q21041
|
train
|
function($input) {
var inputOffset = $input.offset();
var inputHeight = $input.outerHeight();
var wrapperOffset = this.domState.getOffset();
return {
top: inputOffset.top - wrapperOffset.top + inputHeight,
left: inputOffset.left - wrapperOffset.left
};
}
|
javascript
|
{
"resource": ""
}
|
|
q21042
|
train
|
function() {
var name = this.focusModel.which().columnName;
var datePicker = this.datePickerMap[name];
if (datePicker && datePicker.isOpened()) {
datePicker.close();
}
}
|
javascript
|
{
"resource": ""
}
|
|
q21043
|
train
|
function(address, force) {
var result;
if (force) {
this.focusModel.finishEditing();
}
result = this.focusModel.startEditing(address.rowKey, address.columnName);
if (result) {
this.selectionModel.end();
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q21044
|
train
|
function(columnName, value) {
var column = this.columnModel.getColumnModel(columnName);
var maxLength = snippet.pick(column, 'editOptions', 'maxLength');
if (maxLength > 0 && value.length > maxLength) {
return value.substring(0, maxLength);
}
return value;
}
|
javascript
|
{
"resource": ""
}
|
|
q21045
|
train
|
function(address, shouldBlur, value) {
var focusModel = this.focusModel;
var row, currentValue;
if (!focusModel.isEditingCell(address.rowKey, address.columnName)) {
return false;
}
this.selectionModel.enable();
if (!_.isUndefined(value)) {
row = this.dataModel.get(address.rowKey);
currentValue = row.get(address.columnName);
if (!(util.isBlank(value) && util.isBlank(currentValue))) {
this.setValue(address, this._checkMaxLength(address.columnName, value));
}
}
focusModel.finishEditing();
if (shouldBlur) {
focusModel.focusClipboard();
} else {
_.defer(function() {
focusModel.refreshState();
});
}
return true;
}
|
javascript
|
{
"resource": ""
}
|
|
q21046
|
train
|
function(reverse) {
var focusModel = this.focusModel;
var address = reverse ? focusModel.prevAddress() : focusModel.nextAddress();
focusModel.focusIn(address.rowKey, address.columnName, true);
}
|
javascript
|
{
"resource": ""
}
|
|
q21047
|
train
|
function(address, value) {
var columnModel = this.columnModel.getColumnModel(address.columnName);
if (_.isString(value)) {
value = $.trim(value);
}
if (columnModel.validation && columnModel.validation.dataType === 'number') {
value = convertToNumber(value);
}
if (columnModel.name === '_button') {
if (value) {
this.dataModel.check(address.rowKey);
} else {
this.dataModel.uncheck(address.rowKey);
}
} else {
this.dataModel.setValue(address.rowKey, address.columnName, value);
}
}
|
javascript
|
{
"resource": ""
}
|
|
q21048
|
train
|
function(address, value) {
var columnModel = this.columnModel.getColumnModel(address.columnName);
if (!snippet.pick(columnModel, 'editOptions', 'useViewMode')) {
this.setValue(address, value);
}
}
|
javascript
|
{
"resource": ""
}
|
|
q21049
|
convertToNumber
|
train
|
function convertToNumber(value) {
if (_.isString(value)) {
value = value.replace(/,/g, '');
}
if (_.isNumber(value) || isNaN(value) || util.isBlank(value)) {
return value;
}
return Number(value);
}
|
javascript
|
{
"resource": ""
}
|
q21050
|
getScreenshotName
|
train
|
function getScreenshotName(basePath) {
return function(context) {
var testName = context.test.title.replace(/\s+/g, '-');
var browserName = context.browser.name;
var browserVersion = parseInt(context.browser.version, 10);
var subDir = browserName + '_v' + browserVersion;
var fileName = testName + '.png';
return path.join(basePath, subDir, fileName);
};
}
|
javascript
|
{
"resource": ""
}
|
q21051
|
train
|
function(a1, a2) {
var o,
i,
l,
k;
if (arguments.length === 1 && typeof a1 === 'string') {
if (data[a1] !== undefined)
return data[a1];
for (i = 0, l = datas.length; i < l; i++)
if (datas[i][a1] !== undefined)
return datas[i][a1];
return undefined;
} else if (typeof a1 === 'object' && typeof a2 === 'string') {
return (a1 || {})[a2] !== undefined ? a1[a2] : settings(a2);
} else {
o = (typeof a1 === 'object' && a2 === undefined) ? a1 : {};
if (typeof a1 === 'string')
o[a1] = a2;
for (i = 0, k = Object.keys(o), l = k.length; i < l; i++)
data[k[i]] = o[k[i]];
return this;
}
}
|
javascript
|
{
"resource": ""
}
|
|
q21052
|
train
|
function(n) {
return {
x1: n.x - n.size,
y1: n.y - n.size,
x2: n.x + n.size,
y2: n.y - n.size,
height: n.size * 2
};
}
|
javascript
|
{
"resource": ""
}
|
|
q21053
|
train
|
function(e) {
if (e.y1 < e.y2) {
// (e.x1, e.y1) on top
if (e.x1 < e.x2) {
// (e.x1, e.y1) on left
return {
x1: e.x1 - e.size,
y1: e.y1 - e.size,
x2: e.x2 + e.size,
y2: e.y1 - e.size,
height: e.y2 - e.y1 + e.size * 2
};
}
// (e.x1, e.y1) on right
return {
x1: e.x2 - e.size,
y1: e.y1 - e.size,
x2: e.x1 + e.size,
y2: e.y1 - e.size,
height: e.y2 - e.y1 + e.size * 2
};
}
// (e.x2, e.y2) on top
if (e.x1 < e.x2) {
// (e.x1, e.y1) on left
return {
x1: e.x1 - e.size,
y1: e.y2 - e.size,
x2: e.x2 + e.size,
y2: e.y2 - e.size,
height: e.y1 - e.y2 + e.size * 2
};
}
// (e.x2, e.y2) on right
return {
x1: e.x2 - e.size,
y1: e.y2 - e.size,
x2: e.x1 + e.size,
y2: e.y2 - e.size,
height: e.y1 - e.y2 + e.size * 2
};
}
|
javascript
|
{
"resource": ""
}
|
|
q21054
|
train
|
function(e, cp) {
var pt = sigma.utils.getPointOnQuadraticCurve(
0.5,
e.x1,
e.y1,
e.x2,
e.y2,
cp.x,
cp.y
);
// Bounding box of the two points and the point at the middle of the
// curve:
var minX = Math.min(e.x1, e.x2, pt.x),
maxX = Math.max(e.x1, e.x2, pt.x),
minY = Math.min(e.y1, e.y2, pt.y),
maxY = Math.max(e.y1, e.y2, pt.y);
return {
x1: minX - e.size,
y1: minY - e.size,
x2: maxX + e.size,
y2: minY - e.size,
height: maxY - minY + e.size * 2
};
}
|
javascript
|
{
"resource": ""
}
|
|
q21055
|
train
|
function(n) {
// Fitting to the curve is too costly, we compute a larger bounding box
// using the control points:
var cp = sigma.utils.getSelfLoopControlPoints(n.x, n.y, n.size);
// Bounding box of the point and the two control points:
var minX = Math.min(n.x, cp.x1, cp.x2),
maxX = Math.max(n.x, cp.x1, cp.x2),
minY = Math.min(n.y, cp.y1, cp.y2),
maxY = Math.max(n.y, cp.y1, cp.y2);
return {
x1: minX - n.size,
y1: minY - n.size,
x2: maxX + n.size,
y2: minY - n.size,
height: maxY - minY + n.size * 2
};
}
|
javascript
|
{
"resource": ""
}
|
|
q21056
|
train
|
function(r) {
var width = (
Math.sqrt(
Math.pow(r.x2 - r.x1, 2) +
Math.pow(r.y2 - r.y1, 2)
)
);
return {
x: r.x1 - (r.y2 - r.y1) * r.height / width,
y: r.y1 + (r.x2 - r.x1) * r.height / width
};
}
|
javascript
|
{
"resource": ""
}
|
|
q21057
|
train
|
function(r, llc) {
return {
x: llc.x - r.x1 + r.x2,
y: llc.y - r.y1 + r.y2
};
}
|
javascript
|
{
"resource": ""
}
|
|
q21058
|
train
|
function(r) {
var llc = this.lowerLeftCoor(r),
lrc = this.lowerRightCoor(r, llc);
return [
{x: r.x1, y: r.y1},
{x: r.x2, y: r.y2},
{x: llc.x, y: llc.y},
{x: lrc.x, y: lrc.y}
];
}
|
javascript
|
{
"resource": ""
}
|
|
q21059
|
train
|
function(b) {
return [
[
{x: b.x, y: b.y},
{x: b.x + b.width / 2, y: b.y},
{x: b.x, y: b.y + b.height / 2},
{x: b.x + b.width / 2, y: b.y + b.height / 2}
],
[
{x: b.x + b.width / 2, y: b.y},
{x: b.x + b.width, y: b.y},
{x: b.x + b.width / 2, y: b.y + b.height / 2},
{x: b.x + b.width, y: b.y + b.height / 2}
],
[
{x: b.x, y: b.y + b.height / 2},
{x: b.x + b.width / 2, y: b.y + b.height / 2},
{x: b.x, y: b.y + b.height},
{x: b.x + b.width / 2, y: b.y + b.height}
],
[
{x: b.x + b.width / 2, y: b.y + b.height / 2},
{x: b.x + b.width, y: b.y + b.height / 2},
{x: b.x + b.width / 2, y: b.y + b.height},
{x: b.x + b.width, y: b.y + b.height}
]
];
}
|
javascript
|
{
"resource": ""
}
|
|
q21060
|
train
|
function(c1, c2) {
return [
{x: c1[1].x - c1[0].x, y: c1[1].y - c1[0].y},
{x: c1[1].x - c1[3].x, y: c1[1].y - c1[3].y},
{x: c2[0].x - c2[2].x, y: c2[0].y - c2[2].y},
{x: c2[0].x - c2[1].x, y: c2[0].y - c2[1].y}
];
}
|
javascript
|
{
"resource": ""
}
|
|
q21061
|
train
|
function(c, a) {
var l = (
(c.x * a.x + c.y * a.y) /
(Math.pow(a.x, 2) + Math.pow(a.y, 2))
);
return {
x: l * a.x,
y: l * a.y
};
}
|
javascript
|
{
"resource": ""
}
|
|
q21062
|
train
|
function(a, c1, c2) {
var sc1 = [],
sc2 = [];
for (var ci = 0; ci < 4; ci++) {
var p1 = this.projection(c1[ci], a),
p2 = this.projection(c2[ci], a);
sc1.push(p1.x * a.x + p1.y * a.y);
sc2.push(p2.x * a.x + p2.y * a.y);
}
var maxc1 = Math.max.apply(Math, sc1),
maxc2 = Math.max.apply(Math, sc2),
minc1 = Math.min.apply(Math, sc1),
minc2 = Math.min.apply(Math, sc2);
return (minc2 <= maxc1 && maxc2 >= minc1);
}
|
javascript
|
{
"resource": ""
}
|
|
q21063
|
train
|
function(c1, c2) {
var axis = this.axis(c1, c2),
col = true;
for (var i = 0; i < 4; i++)
col = col && this.axisCollision(axis[i], c1, c2);
return col;
}
|
javascript
|
{
"resource": ""
}
|
|
q21064
|
_quadIndexes
|
train
|
function _quadIndexes(rectangle, quadCorners) {
var indexes = [];
// Iterating through quads
for (var i = 0; i < 4; i++)
if ((rectangle.x2 >= quadCorners[i][0].x) &&
(rectangle.x1 <= quadCorners[i][1].x) &&
(rectangle.y1 + rectangle.height >= quadCorners[i][0].y) &&
(rectangle.y1 <= quadCorners[i][2].y))
indexes.push(i);
return indexes;
}
|
javascript
|
{
"resource": ""
}
|
q21065
|
_quadCollision
|
train
|
function _quadCollision(corners, quadCorners) {
var indexes = [];
// Iterating through quads
for (var i = 0; i < 4; i++)
if (_geom.collision(corners, quadCorners[i]))
indexes.push(i);
return indexes;
}
|
javascript
|
{
"resource": ""
}
|
q21066
|
_quadSubdivide
|
train
|
function _quadSubdivide(index, quad) {
var next = quad.level + 1,
subw = Math.round(quad.bounds.width / 2),
subh = Math.round(quad.bounds.height / 2),
qx = Math.round(quad.bounds.x),
qy = Math.round(quad.bounds.y),
x,
y;
switch (index) {
case 0:
x = qx;
y = qy;
break;
case 1:
x = qx + subw;
y = qy;
break;
case 2:
x = qx;
y = qy + subh;
break;
case 3:
x = qx + subw;
y = qy + subh;
break;
}
return _quadTree(
{x: x, y: y, width: subw, height: subh},
next,
quad.maxElements,
quad.maxLevel
);
}
|
javascript
|
{
"resource": ""
}
|
q21067
|
_quadInsert
|
train
|
function _quadInsert(el, sizedPoint, quad) {
if (quad.level < quad.maxLevel) {
// Searching appropriate quads
var indexes = _quadIndexes(sizedPoint, quad.corners);
// Iterating
for (var i = 0, l = indexes.length; i < l; i++) {
// Subdividing if necessary
if (quad.nodes[indexes[i]] === undefined)
quad.nodes[indexes[i]] = _quadSubdivide(indexes[i], quad);
// Recursion
_quadInsert(el, sizedPoint, quad.nodes[indexes[i]]);
}
}
else {
// Pushing the element in a leaf node
quad.elements.push(el);
}
}
|
javascript
|
{
"resource": ""
}
|
q21068
|
_quadRetrievePoint
|
train
|
function _quadRetrievePoint(point, quad) {
if (quad.level < quad.maxLevel) {
var index = _quadIndex(point, quad.bounds);
// If node does not exist we return an empty list
if (quad.nodes[index] !== undefined) {
return _quadRetrievePoint(point, quad.nodes[index]);
}
else {
return [];
}
}
else {
return quad.elements;
}
}
|
javascript
|
{
"resource": ""
}
|
q21069
|
_quadRetrieveArea
|
train
|
function _quadRetrieveArea(rectData, quad, collisionFunc, els) {
els = els || {};
if (quad.level < quad.maxLevel) {
var indexes = collisionFunc(rectData, quad.corners);
for (var i = 0, l = indexes.length; i < l; i++)
if (quad.nodes[indexes[i]] !== undefined)
_quadRetrieveArea(
rectData,
quad.nodes[indexes[i]],
collisionFunc,
els
);
} else
for (var j = 0, m = quad.elements.length; j < m; j++)
if (els[quad.elements[j].id] === undefined)
els[quad.elements[j].id] = quad.elements[j];
return els;
}
|
javascript
|
{
"resource": ""
}
|
q21070
|
register
|
train
|
function register(fn, p, key) {
if (key != undefined && typeof key !== 'string')
throw 'The filter key "'+ key.toString() +'" must be a string.';
if (key != undefined && !key.length)
throw 'The filter key must be a non-empty string.';
if (typeof fn !== 'function')
throw 'The predicate of key "'+ key +'" must be a function.';
if ('undo' === key)
throw '"undo" is a reserved key.';
if (_keysIndex[key])
throw 'The filter "' + key + '" already exists.';
if (key)
_keysIndex[key] = true;
_chain.push({
'key': key,
'processor': fn,
'predicate': p
});
}
|
javascript
|
{
"resource": ""
}
|
q21071
|
unregister
|
train
|
function unregister (o) {
_chain = _chain.filter(function(a) {
return !(a.key in o);
});
for(var key in o)
delete _keysIndex[key];
}
|
javascript
|
{
"resource": ""
}
|
q21072
|
deepCopy
|
train
|
function deepCopy(o) {
var copy = Object.create(null);
for (var i in o) {
if (typeof o[i] === "object" && o[i] !== null) {
copy[i] = deepCopy(o[i]);
}
else if (typeof o[i] === "function" && o[i] !== null) {
// clone function:
eval(" copy[i] = " + o[i].toString());
//copy[i] = o[i].bind(_g);
}
else
copy[i] = o[i];
}
return copy;
}
|
javascript
|
{
"resource": ""
}
|
q21073
|
_upHandler
|
train
|
function _upHandler(e) {
if (_settings('mouseEnabled') && _isMouseDown) {
_isMouseDown = false;
if (_movingTimeoutId)
clearTimeout(_movingTimeoutId);
_camera.isMoving = false;
var x = sigma.utils.getX(e),
y = sigma.utils.getY(e);
if (_isMoving) {
sigma.misc.animation.killAll(_camera);
sigma.misc.animation.camera(
_camera,
{
x: _camera.x +
_settings('mouseInertiaRatio') * (_camera.x - _lastCameraX),
y: _camera.y +
_settings('mouseInertiaRatio') * (_camera.y - _lastCameraY)
},
{
easing: 'quadraticOut',
duration: _settings('mouseInertiaDuration')
}
);
} else if (
_startMouseX !== x ||
_startMouseY !== y
)
_camera.goTo({
x: _camera.x,
y: _camera.y
});
_self.dispatchEvent('mouseup',
sigma.utils.mouseCoords(e));
// Update _isMoving flag:
_isMoving = false;
}
}
|
javascript
|
{
"resource": ""
}
|
q21074
|
_downHandler
|
train
|
function _downHandler(e) {
if (_settings('mouseEnabled')) {
_startCameraX = _camera.x;
_startCameraY = _camera.y;
_lastCameraX = _camera.x;
_lastCameraY = _camera.y;
_startMouseX = sigma.utils.getX(e);
_startMouseY = sigma.utils.getY(e);
_hasDragged = false;
_downStartTime = (new Date()).getTime();
switch (e.which) {
case 2:
// Middle mouse button pressed
// Do nothing.
break;
case 3:
// Right mouse button pressed
_self.dispatchEvent('rightclick',
sigma.utils.mouseCoords(e, _startMouseX, _startMouseY));
break;
// case 1:
default:
// Left mouse button pressed
_isMouseDown = true;
_self.dispatchEvent('mousedown',
sigma.utils.mouseCoords(e, _startMouseX, _startMouseY));
}
}
}
|
javascript
|
{
"resource": ""
}
|
q21075
|
_clickHandler
|
train
|
function _clickHandler(e) {
if (_settings('mouseEnabled')) {
var event = sigma.utils.mouseCoords(e);
event.isDragging =
(((new Date()).getTime() - _downStartTime) > 100) && _hasDragged;
_self.dispatchEvent('click', event);
}
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
e.stopPropagation();
return false;
}
|
javascript
|
{
"resource": ""
}
|
q21076
|
_doubleClickHandler
|
train
|
function _doubleClickHandler(e) {
var pos,
ratio,
animation;
if (_settings('mouseEnabled')) {
ratio = 1 / _settings('doubleClickZoomingRatio');
_self.dispatchEvent('doubleclick',
sigma.utils.mouseCoords(e, _startMouseX, _startMouseY));
if (_settings('doubleClickEnabled')) {
pos = _camera.cameraPosition(
sigma.utils.getX(e) - sigma.utils.getCenter(e).x,
sigma.utils.getY(e) - sigma.utils.getCenter(e).y,
true
);
animation = {
duration: _settings('doubleClickZoomDuration')
};
sigma.utils.zoomTo(_camera, pos.x, pos.y, ratio, animation);
}
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
e.stopPropagation();
return false;
}
}
|
javascript
|
{
"resource": ""
}
|
q21077
|
_wheelHandler
|
train
|
function _wheelHandler(e) {
var pos,
ratio,
animation,
wheelDelta = sigma.utils.getDelta(e);
if (_settings('mouseEnabled') && _settings('mouseWheelEnabled') && wheelDelta !== 0) {
ratio = wheelDelta > 0 ?
1 / _settings('zoomingRatio') :
_settings('zoomingRatio');
pos = _camera.cameraPosition(
sigma.utils.getX(e) - sigma.utils.getCenter(e).x,
sigma.utils.getY(e) - sigma.utils.getCenter(e).y,
true
);
animation = {
duration: _settings('mouseZoomDuration')
};
sigma.utils.zoomTo(_camera, pos.x, pos.y, ratio, animation);
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
e.stopPropagation();
return false;
}
}
|
javascript
|
{
"resource": ""
}
|
q21078
|
train
|
function(settings) {
var k,
fn,
data;
/**
* DATA:
* *****
* Every data that is callable from graph methods are stored in this "data"
* object. This object will be served as context for all these methods,
* and it is possible to add other type of data in it.
*/
data = {
/**
* SETTINGS FUNCTION:
* ******************
*/
settings: settings || _defaultSettingsFunction,
/**
* MAIN DATA:
* **********
*/
nodesArray: [],
edgesArray: [],
/**
* GLOBAL INDEXES:
* ***************
* These indexes just index data by ids.
*/
nodesIndex: Object.create(null),
edgesIndex: Object.create(null),
/**
* LOCAL INDEXES:
* **************
* These indexes refer from node to nodes. Each key is an id, and each
* value is the array of the ids of related nodes.
*/
inNeighborsIndex: Object.create(null),
outNeighborsIndex: Object.create(null),
allNeighborsIndex: Object.create(null),
inNeighborsCount: Object.create(null),
outNeighborsCount: Object.create(null),
allNeighborsCount: Object.create(null)
};
// Execute bindings:
for (k in _initBindings)
_initBindings[k].call(data);
// Add methods to both the scope and the data objects:
for (k in _methods) {
fn = __bindGraphMethod(k, data, _methods[k]);
this[k] = fn;
data[k] = fn;
}
}
|
javascript
|
{
"resource": ""
}
|
|
q21079
|
__bindGraphMethod
|
train
|
function __bindGraphMethod(methodName, scope, fn) {
var result = function() {
var k,
res;
// Execute "before" bound functions:
for (k in _methodBeforeBindings[methodName])
_methodBeforeBindings[methodName][k].apply(scope, arguments);
// Apply the method:
res = fn.apply(scope, arguments);
// Execute bound functions:
for (k in _methodBindings[methodName])
_methodBindings[methodName][k].apply(scope, arguments);
// Return res:
return res;
};
return result;
}
|
javascript
|
{
"resource": ""
}
|
q21080
|
_quadTree
|
train
|
function _quadTree(bounds, level, maxElements, maxLevel) {
return {
level: level || 0,
bounds: bounds,
corners: _geom.splitSquare(bounds),
maxElements: maxElements || 20,
maxLevel: maxLevel || 4,
elements: [],
nodes: []
};
}
|
javascript
|
{
"resource": ""
}
|
q21081
|
_handleLeave
|
train
|
function _handleLeave(e) {
if (_settings('touchEnabled')) {
_downTouches = e.touches;
var inertiaRatio = _settings('touchInertiaRatio');
if (_movingTimeoutId) {
_isMoving = false;
clearTimeout(_movingTimeoutId);
}
switch (_touchMode) {
case 2:
if (e.touches.length === 1) {
_handleStart(e);
e.preventDefault();
break;
}
/* falls through */
case 1:
_camera.isMoving = false;
_self.dispatchEvent('stopDrag');
if (_isMoving) {
_doubleTap = false;
sigma.misc.animation.camera(
_camera,
{
x: _camera.x +
inertiaRatio * (_camera.x - _lastCameraX),
y: _camera.y +
inertiaRatio * (_camera.y - _lastCameraY)
},
{
easing: 'quadraticOut',
duration: _settings('touchInertiaDuration')
}
);
}
_isMoving = false;
_touchMode = 0;
break;
}
}
}
|
javascript
|
{
"resource": ""
}
|
q21082
|
_doubleTapHandler
|
train
|
function _doubleTapHandler(e) {
var pos,
ratio,
animation;
if (e.touches && e.touches.length === 1 && _settings('touchEnabled')) {
_doubleTap = true;
ratio = 1 / _settings('doubleClickZoomingRatio');
pos = position(e.touches[0]);
_self.dispatchEvent('doubleclick',
sigma.utils.mouseCoords(e, pos.x, pos.y));
if (_settings('doubleClickEnabled')) {
pos = _camera.cameraPosition(
pos.x - sigma.utils.getCenter(e).x,
pos.y - sigma.utils.getCenter(e).y,
true
);
animation = {
duration: _settings('doubleClickZoomDuration'),
onComplete: function() {
_doubleTap = false;
}
};
sigma.utils.zoomTo(_camera, pos.x, pos.y, ratio, animation);
}
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
e.stopPropagation();
return false;
}
}
|
javascript
|
{
"resource": ""
}
|
q21083
|
Edge
|
train
|
function Edge(properties) {
// Possible Properties
var edge = {
id: properties.id,
type: properties.type || 'undirected',
label: properties.label || '',
source: properties.source,
target: properties.target,
weight: +properties.weight || 1.0
};
if (properties.viz)
edge.viz = properties.viz;
if (properties.attributes)
edge.attributes = properties.attributes;
return edge;
}
|
javascript
|
{
"resource": ""
}
|
q21084
|
_data
|
train
|
function _data(model, node_or_edge) {
var data = {};
var attvalues_els = node_or_edge.getElementsByTagName('attvalue');
// Getting Node Indicated Attributes
var ah = _helpers.nodeListToHash(attvalues_els, function(el) {
var attributes = _helpers.namedNodeMapToObject(el.attributes);
var key = attributes.id || attributes['for'];
// Returning object
return {key: key, value: attributes.value};
});
// Iterating through model
model.map(function(a) {
// Default value?
data[a.id] = !(a.id in ah) && 'defaultValue' in a ?
_helpers.enforceType(a.type, a.defaultValue) :
_helpers.enforceType(a.type, ah[a.id]);
});
return data;
}
|
javascript
|
{
"resource": ""
}
|
q21085
|
_nodeViz
|
train
|
function _nodeViz(node) {
var viz = {};
// Color
var color_el = _helpers.getFirstElementByTagNS(node, 'viz', 'color');
if (color_el) {
var color = ['r', 'g', 'b', 'a'].map(function(c) {
return color_el.getAttribute(c);
});
viz.color = _helpers.getRGB(color);
}
// Position
var pos_el = _helpers.getFirstElementByTagNS(node, 'viz', 'position');
if (pos_el) {
viz.position = {};
['x', 'y', 'z'].map(function(p) {
viz.position[p] = +pos_el.getAttribute(p);
});
}
// Size
var size_el = _helpers.getFirstElementByTagNS(node, 'viz', 'size');
if (size_el)
viz.size = +size_el.getAttribute('value');
// Shape
var shape_el = _helpers.getFirstElementByTagNS(node, 'viz', 'shape');
if (shape_el)
viz.shape = shape_el.getAttribute('value');
return viz;
}
|
javascript
|
{
"resource": ""
}
|
q21086
|
_edgeViz
|
train
|
function _edgeViz(edge) {
var viz = {};
// Color
var color_el = _helpers.getFirstElementByTagNS(edge, 'viz', 'color');
if (color_el) {
var color = ['r', 'g', 'b', 'a'].map(function(c) {
return color_el.getAttribute(c);
});
viz.color = _helpers.getRGB(color);
}
// Shape
var shape_el = _helpers.getFirstElementByTagNS(edge, 'viz', 'shape');
if (shape_el)
viz.shape = shape_el.getAttribute('value');
// Thickness
var thick_el = _helpers.getFirstElementByTagNS(edge, 'viz', 'thickness');
if (thick_el)
viz.thickness = +thick_el.getAttribute('value');
return viz;
}
|
javascript
|
{
"resource": ""
}
|
q21087
|
fetchAndParse
|
train
|
function fetchAndParse(gexf_url, callback) {
if (typeof callback === 'function') {
return fetch(gexf_url, function(gexf) {
callback(Graph(gexf));
});
} else
return Graph(fetch(gexf_url));
}
|
javascript
|
{
"resource": ""
}
|
q21088
|
calculateOffset
|
train
|
function calculateOffset(element) {
var style = window.getComputedStyle(element);
var getCssProperty = function(prop) {
return parseInt(style.getPropertyValue(prop).replace('px', '')) || 0;
};
return {
left: element.getBoundingClientRect().left + getCssProperty('padding-left'),
top: element.getBoundingClientRect().top + getCssProperty('padding-top')
};
}
|
javascript
|
{
"resource": ""
}
|
q21089
|
train
|
function(e) {
switch (e.data.action) {
case 'start':
init(
new Float32Array(e.data.nodes),
new Float32Array(e.data.edges),
e.data.config
);
// First iteration(s)
run(W.settings.startingIterations);
break;
case 'loop':
NodeMatrix = new Float32Array(e.data.nodes);
run(W.settings.iterationsPerRender);
break;
case 'config':
// Merging new settings
configure(e.data.config);
break;
case 'kill':
// Deleting context for garbage collection
__emptyObject(W);
NodeMatrix = null;
EdgeMatrix = null;
RegionMatrix = null;
self.removeEventListener('message', listener);
break;
default:
}
}
|
javascript
|
{
"resource": ""
}
|
|
q21090
|
_dispatch
|
train
|
function _dispatch(events, data) {
var i,
j,
i_end,
j_end,
event,
eventName,
eArray = Array.isArray(events) ?
events :
events.split(/ /);
data = data === undefined ? {} : data;
for (i = 0, i_end = eArray.length; i !== i_end; i += 1) {
eventName = eArray[i];
if (_handlers[eventName]) {
event = {
type: eventName,
data: data || {}
};
for (j = 0, j_end = _handlers[eventName].length; j !== j_end; j += 1)
try {
_handlers[eventName][j].handler(event);
} catch (e) {}
}
}
}
|
javascript
|
{
"resource": ""
}
|
q21091
|
_activateJob
|
train
|
function _activateJob(job) {
var l = _sortedByPriorityJobs.length;
// Add the job to the running jobs:
_runningJobs[job.id] = job;
job.status = 'running';
// Add the job to the priorities:
if (l) {
job.weightTime = _sortedByPriorityJobs[l - 1].weightTime;
job.currentTime = job.weightTime * (job.weight || 1);
}
// Initialize the job and dispatch:
job.startTime = __dateNow();
_dispatch('jobStarted', __clone(job));
_sortedByPriorityJobs.push(job);
}
|
javascript
|
{
"resource": ""
}
|
q21092
|
_addJob
|
train
|
function _addJob(v1, v2) {
var i,
l,
o;
// Array of jobs:
if (Array.isArray(v1)) {
// Keep conrad to start until the last job is added:
_noStart = true;
for (i = 0, l = v1.length; i < l; i++)
_addJob(v1[i].id, __extend(v1[i], v2));
_noStart = false;
if (!_isRunning) {
// Update the _lastFrameTime:
_lastFrameTime = __dateNow();
_dispatch('start');
_loop();
}
} else if (typeof v1 === 'object') {
// One job (object):
if (typeof v1.id === 'string')
_addJob(v1.id, v1);
// Hash of jobs:
else {
// Keep conrad to start until the last job is added:
_noStart = true;
for (i in v1)
if (typeof v1[i] === 'function')
_addJob(i, __extend({
job: v1[i]
}, v2));
else
_addJob(i, __extend(v1[i], v2));
_noStart = false;
if (!_isRunning) {
// Update the _lastFrameTime:
_lastFrameTime = __dateNow();
_dispatch('start');
_loop();
}
}
// One job (string, *):
} else if (typeof v1 === 'string') {
if (_hasJob(v1))
throw new Error(
'[conrad.addJob] Job with id "' + v1 + '" already exists.'
);
// One job (string, function):
if (typeof v2 === 'function') {
o = {
id: v1,
done: 0,
time: 0,
status: 'waiting',
currentTime: 0,
averageTime: 0,
weightTime: 0,
job: v2
};
// One job (string, object):
} else if (typeof v2 === 'object') {
o = __extend(
{
id: v1,
done: 0,
time: 0,
status: 'waiting',
currentTime: 0,
averageTime: 0,
weightTime: 0
},
v2
);
// If none of those cases, throw an error:
} else
throw new Error('[conrad.addJob] Wrong arguments.');
// Effectively add the job:
_jobs[v1] = o;
_dispatch('jobAdded', __clone(o));
// Check if the loop has to be started:
if (!_isRunning && !_noStart) {
// Update the _lastFrameTime:
_lastFrameTime = __dateNow();
_dispatch('start');
_loop();
}
// If none of those cases, throw an error:
} else
throw new Error('[conrad.addJob] Wrong arguments.');
return this;
}
|
javascript
|
{
"resource": ""
}
|
q21093
|
_killJob
|
train
|
function _killJob(v1) {
var i,
l,
k,
a,
job,
found = false;
// Array of job ids:
if (Array.isArray(v1))
for (i = 0, l = v1.length; i < l; i++)
_killJob(v1[i]);
// One job's id:
else if (typeof v1 === 'string') {
a = [_runningJobs, _waitingJobs, _jobs];
// Remove the job from the hashes:
for (i = 0, l = a.length; i < l; i++)
if (v1 in a[i]) {
job = a[i][v1];
if (_parameters.history) {
job.status = 'done';
_doneJobs.push(job);
}
_dispatch('jobEnded', __clone(job));
delete a[i][v1];
if (typeof job.end === 'function')
job.end();
found = true;
}
// Remove the priorities array:
a = _sortedByPriorityJobs;
for (i = 0, l = a.length; i < l; i++)
if (a[i].id === v1) {
a.splice(i, 1);
break;
}
if (!found)
throw new Error('[conrad.killJob] Job "' + v1 + '" not found.');
// If none of those cases, throw an error:
} else
throw new Error('[conrad.killJob] Wrong arguments.');
return this;
}
|
javascript
|
{
"resource": ""
}
|
q21094
|
_killAll
|
train
|
function _killAll() {
var k,
jobs = __extend(_jobs, _runningJobs, _waitingJobs);
// Take every jobs and push them into the _doneJobs object:
if (_parameters.history)
for (k in jobs) {
jobs[k].status = 'done';
_doneJobs.push(jobs[k]);
if (typeof jobs[k].end === 'function')
jobs[k].end();
}
// Reinitialize the different jobs lists:
_jobs = {};
_waitingJobs = {};
_runningJobs = {};
_sortedByPriorityJobs = [];
// In case some jobs are added right after the kill:
_isRunning = false;
return this;
}
|
javascript
|
{
"resource": ""
}
|
q21095
|
_hasJob
|
train
|
function _hasJob(id) {
var job = _jobs[id] || _runningJobs[id] || _waitingJobs[id];
return job ? __extend(job) : null;
}
|
javascript
|
{
"resource": ""
}
|
q21096
|
_settings
|
train
|
function _settings(v1, v2) {
var o;
if (typeof a1 === 'string' && arguments.length === 1)
return _parameters[a1];
else {
o = (typeof a1 === 'object' && arguments.length === 1) ?
a1 || {} :
{};
if (typeof a1 === 'string')
o[a1] = a2;
for (var k in o)
if (o[k] !== undefined)
_parameters[k] = o[k];
else
delete _parameters[k];
return this;
}
}
|
javascript
|
{
"resource": ""
}
|
q21097
|
_getStats
|
train
|
function _getStats(v1, v2) {
var a,
k,
i,
l,
stats,
pattern,
isPatternString;
if (!arguments.length) {
stats = [];
for (k in _jobs)
stats.push(_jobs[k]);
for (k in _waitingJobs)
stats.push(_waitingJobs[k]);
for (k in _runningJobs)
stats.push(_runningJobs[k]);
stats = stats.concat(_doneJobs);
}
if (typeof v1 === 'string')
switch (v1) {
case 'waiting':
stats = __objectValues(_waitingJobs);
break;
case 'running':
stats = __objectValues(_runningJobs);
break;
case 'done':
stats = _doneJobs;
break;
default:
pattern = v1;
}
if (v1 instanceof RegExp)
pattern = v1;
if (!pattern && (typeof v2 === 'string' || v2 instanceof RegExp))
pattern = v2;
// Filter jobs if a pattern is given:
if (pattern) {
isPatternString = typeof pattern === 'string';
if (stats instanceof Array) {
a = stats;
} else if (typeof stats === 'object') {
a = [];
for (k in stats)
a = a.concat(stats[k]);
} else {
a = [];
for (k in _jobs)
a.push(_jobs[k]);
for (k in _waitingJobs)
a.push(_waitingJobs[k]);
for (k in _runningJobs)
a.push(_runningJobs[k]);
a = a.concat(_doneJobs);
}
stats = [];
for (i = 0, l = a.length; i < l; i++)
if (isPatternString ? a[i].id === pattern : a[i].id.match(pattern))
stats.push(a[i]);
}
return __clone(stats);
}
|
javascript
|
{
"resource": ""
}
|
q21098
|
__clone
|
train
|
function __clone(item) {
var result, i, k, l;
if (!item)
return item;
if (Array.isArray(item)) {
result = [];
for (i = 0, l = item.length; i < l; i++)
result.push(__clone(item[i]));
} else if (typeof item === 'object') {
result = {};
for (i in item)
result[i] = __clone(item[i]);
} else
result = item;
return result;
}
|
javascript
|
{
"resource": ""
}
|
q21099
|
__objectValues
|
train
|
function __objectValues(o) {
var k,
a = [];
for (k in o)
a.push(o[k]);
return a;
}
|
javascript
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.