Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
indexOf: function(posX, withMeta) {
var widths = this.getWidths();
var totalColumnWidth = this.getFrameWidth();
var adjustableIndex = (withMeta) ? 0 : this.columnModel.getVisibleMetaColumnCount();
var columnIndex = 0;
if (posX >= totalColumnWidth) {
columnIndex = widths.length - 1;
} else {
snippet.forEachArray(widths, function(width, index) { // eslint-disable-line consistent-return
width += CELL_BORDER_WIDTH;
columnIndex = index;
if (posX > width) {
posX -= width;
} else {
return false;
}
});
}
return Math.max(0, columnIndex - adjustableIndex);
},
const from = {
line: range.from.line,
ch: 0
};
const to = {
line: range.to.line,
ch: doc.getLineHandle(range.to.line).text.length
};
const lengthOfCurrentLineBefore = doc.getLine(to.line).length;
const textToModify = doc.getRange(from, to);
const textLinesToModify = textToModify.split('\n');
util.forEachArray(textLinesToModify, (line, index) => {
textLinesToModify[index] = getHeadingMarkdown(line, size);
});
doc.replaceRange(textLinesToModify.join('\n'), from, to);
range.to.ch += doc.getLine(to.line).length - lengthOfCurrentLineBefore;
doc.setSelection(from, range.to);
cm.focus();
}
});
function max(arr, condition, context) {
let result;
if (!condition) {
result = Math.max(...arr);
} else {
([result] = arr);
const rest = arr.slice(1);
let maxValue = condition.call(context, result, 0);
snippet.forEachArray(rest, (item, index) => {
const compareValue = condition.call(context, item, index + 1);
if (compareValue > maxValue) {
maxValue = compareValue;
result = item;
}
});
}
return result;
}
_divideLegendLabels: function(labels, count) {
var limitCount = Math.round(labels.length / count);
var results = [];
var temp = [];
snippet.forEachArray(labels, function(label) {
if (temp.length < limitCount) {
temp.push(label);
} else {
results.push(temp);
temp = [label];
}
});
if (temp.length) {
results.push(temp);
}
return results;
},
snippet.forEachArray(chartData2DArray, function(row, rowIndex) {
var lastCellIndex = row.length - 1;
snippet.forEachArray(row, function(cell, cellIndex) {
var cellContent = (snippet.isNumber(cell) ? cell : '"' + cell + '"');
csvText += cellContent;
if (cellIndex < lastCellIndex) {
csvText += itemDelimiter;
}
});
if (rowIndex < lastRowIndex) {
csvText += lineDelimiter;
}
});
function _makeCsvBodyWithRawData(chartData2DArray, option) {
var csvText = '';
var lineDelimiter = (option && option.lineDelimiter) || '\u000a';
var itemDelimiter = (option && option.itemDelimiter) || ',';
var lastRowIndex = chartData2DArray.length - 1;
snippet.forEachArray(chartData2DArray, function(row, rowIndex) {
var lastCellIndex = row.length - 1;
snippet.forEachArray(row, function(cell, cellIndex) {
var cellContent = (snippet.isNumber(cell) ? cell : '"' + cell + '"');
csvText += cellContent;
if (cellIndex < lastCellIndex) {
csvText += itemDelimiter;
}
});
if (rowIndex < lastRowIndex) {
csvText += lineDelimiter;
}
});
let handlers, isNeedNext;
handlers = this._keyEventHandlers.DEFAULT;
if (handlers) {
util.forEachArray(handlers, handler => {
isNeedNext = handler(event, range, keyMap);
return isNeedNext;
});
}
handlers = this._keyEventHandlers[keyMap];
if (handlers && isNeedNext !== false) {
util.forEachArray(handlers, handler => handler(event, range, keyMap));
}
}
getDimensionMap: function(types) {
var self = this;
var dimensionMap = {};
if (types && types.length) {
snippet.forEachArray(types, function(type) {
dimensionMap[type] = self.dimensionMap[type];
});
} else {
dimensionMap = this.dimensionMap;
}
return JSON.parse(JSON.stringify((dimensionMap)));
},
_runKeyEventHandlers(event, keyMap) {
const range = this.getRange();
let handlers, isNeedNext;
handlers = this._keyEventHandlers.DEFAULT;
if (handlers) {
util.forEachArray(handlers, handler => {
isNeedNext = handler(event, range, keyMap);
return isNeedNext;
});
}
handlers = this._keyEventHandlers[keyMap];
if (handlers && isNeedNext !== false) {
util.forEachArray(handlers, handler => handler(event, range, keyMap));
}
}