dtable-sdk
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -16,18 +16,2 @@ "use strict"; | ||
var STATISTICS_COUNT_TYPE = { | ||
COUNT: 'count', | ||
ADVANCED: 'advanced', | ||
DAY: 'day', | ||
WEEK: 'week', | ||
QUARTAR: 'quartar', | ||
MONTH: 'month', | ||
YEAR: 'year', | ||
SUM: 'Sum', | ||
MAX: 'Max', | ||
MIN: 'Min', | ||
MEAN: 'Mean', | ||
PROVINCE: 'province', | ||
CITY: 'city', | ||
DISTRICT: 'district' | ||
}; | ||
var SUPPORT_SORT_COLUMNS = [_dtableStore.CellType.TEXT, _dtableStore.CellType.NUMBER, _dtableStore.CellType.DATE, _dtableStore.CellType.SINGLE_SELECT, _dtableStore.CellType.FORMULA, _dtableStore.CellType.LINK_FORMULA, _dtableStore.CellType.CTIME, _dtableStore.CellType.MTIME, _dtableStore.CellType.RATE]; | ||
@@ -46,30 +30,2 @@ | ||
}, { | ||
key: "isValidRow", | ||
value: function isValidRow(row, formulaRow, linkRow, column, includeEmpty) { | ||
var columnType = column.type, | ||
columnKey = column.key; | ||
if (includeEmpty || columnType === _dtableStore.CellType.CHECKBOX) return true; | ||
var cellValue; | ||
if (columnType === _dtableStore.CellType.FORMULA || columnType === _dtableStore.CellType.LINK_FORMULA) { | ||
cellValue = formulaRow ? formulaRow[columnKey] : null; | ||
} else if (columnType === _dtableStore.CellType.GEOLOCATION) { | ||
var value = row[columnKey]; | ||
var geo_format = column.data.geo_format; | ||
return isEmptyGeolocationCell(value, geo_format); | ||
} else if (columnType === _dtableStore.CellType.LINK) { | ||
cellValue = linkRow ? linkRow[columnKey] : null; | ||
} else { | ||
cellValue = row[columnKey]; | ||
} | ||
return cellValue || cellValue === 0; | ||
} | ||
}, { | ||
key: "getLinkDisplayString", | ||
value: function getLinkDisplayString(rowIds, linkedTable) { | ||
var displayColumnKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '0000'; | ||
return (0, _dtableStore.getLinkDisplayString)(rowIds, linkedTable, displayColumnKey); | ||
} | ||
}, { | ||
key: "getNumberDisplayString", | ||
@@ -85,7 +41,2 @@ value: function getNumberDisplayString(value, columnData) { | ||
}, { | ||
key: "getTableLinkRows", | ||
value: function getTableLinkRows(rows, table, value) { | ||
return _dtableStore.RowUtils.getTableLinkRows(rows, table, value); | ||
} | ||
}, { | ||
key: "getCellValueDisplayString", | ||
@@ -108,4 +59,9 @@ value: function getCellValueDisplayString(row, type, key, _ref) { | ||
}, { | ||
key: "getFormulaDisplayString", | ||
value: function getFormulaDisplayString(cellValue, columnData) { | ||
return (0, _dtableStore.getFormulaDisplayString)(cellValue, columnData); | ||
} | ||
}, { | ||
key: "getGroupLabel", | ||
value: function getGroupLabel(cellValue, formulaRow, linkRow, column, dateGranularity, geoGranularity, value) { | ||
value: function getGroupLabel(cellValue, formulaRow, column, dateGranularity, geoGranularity, value) { | ||
var type = column.type, | ||
@@ -218,5 +174,11 @@ key = column.key, | ||
{ | ||
if (!linkRow) return null; | ||
var linkCellValue = linkRow[key] || cellValue; | ||
return linkCellValue || []; | ||
var linkCellValue = formulaRow && formulaRow[key]; | ||
if (!Array.isArray(linkCellValue)) { | ||
return []; | ||
} | ||
return linkCellValue.map(function (linkVal) { | ||
return linkVal.display_value; | ||
}); | ||
} | ||
@@ -242,130 +204,2 @@ | ||
}, { | ||
key: "getTotal", | ||
value: function getTotal(summary_column_key, summary_column_type, summary_type, summary_method) { | ||
var rows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : []; | ||
var formula_rows = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; | ||
var rowsLength = rows.length; | ||
var total; | ||
if (summary_type === STATISTICS_COUNT_TYPE.COUNT) { | ||
total = rowsLength; | ||
} else if (summary_type === STATISTICS_COUNT_TYPE.ADVANCED) { | ||
switch (summary_method) { | ||
case 'Distinct_values': | ||
{ | ||
var count = 0; | ||
var existMap = {}; | ||
rows.forEach(function (r) { | ||
var num; | ||
if (_dtableStore.FORMULA_COLUMN_TYPES.includes(summary_column_type)) { | ||
var formulaRow = formula_rows[r._id] || {}; | ||
num = formulaRow[summary_column_key]; | ||
num = Array.isArray(num) ? num[0] : num; | ||
} else { | ||
num = r[summary_column_key]; | ||
} | ||
if (!num) { | ||
if (num === 0) { | ||
num = '0'; | ||
} else { | ||
num = !!num; | ||
} | ||
} | ||
if (!existMap[num]) { | ||
existMap[num] = true; | ||
count++; | ||
} | ||
}); | ||
total = count; | ||
break; | ||
} | ||
case "Sum": | ||
case "Mean": | ||
{ | ||
var sum = 0; | ||
var validNumbersCount = 0; | ||
rows.forEach(function (r) { | ||
var num; | ||
if (_dtableStore.FORMULA_COLUMN_TYPES.includes(summary_column_type)) { | ||
var formulaRow = formula_rows[r._id] || {}; | ||
num = formulaRow[summary_column_key]; | ||
num = Array.isArray(num) ? num[0] : num; | ||
} else { | ||
num = r[summary_column_key]; | ||
} | ||
if ((0, _dtableStore.isNumber)(num)) { | ||
validNumbersCount++; | ||
sum += num; | ||
} | ||
}); | ||
if (summary_method === "Sum") { | ||
total = Number.parseFloat(sum.toFixed(8)); | ||
} else if (summary_method === "Mean") { | ||
total = validNumbersCount === 0 ? 0 : Number.parseFloat((sum / validNumbersCount).toFixed(8)); | ||
} | ||
break; | ||
} | ||
case "Max": | ||
case "Min": | ||
{ | ||
if (rowsLength > 0) { | ||
var result = rows.reduce(function (current, next) { | ||
var currentValue, nextValue; | ||
if (_dtableStore.FORMULA_COLUMN_TYPES.includes(summary_column_type)) { | ||
var currentFormulaRow = formula_rows[current._id]; | ||
var nextFormulaRow = formula_rows[next._id]; | ||
currentValue = currentFormulaRow && currentFormulaRow[summary_column_key]; | ||
nextValue = nextFormulaRow && nextFormulaRow[summary_column_key]; | ||
currentValue = Array.isArray(currentValue) ? currentValue[0] : currentValue; | ||
nextValue = Array.isArray(nextValue) ? nextValue[0] : nextValue; | ||
} else { | ||
currentValue = current[summary_column_key]; | ||
nextValue = next[summary_column_key]; | ||
} | ||
if (!nextValue && nextValue !== 0) { | ||
return current; | ||
} | ||
var isNextGreater = currentValue < nextValue; | ||
if (summary_method === "Min") { | ||
return isNextGreater ? current : next; | ||
} else { | ||
return isNextGreater ? next : current; | ||
} | ||
}); | ||
if (_dtableStore.FORMULA_COLUMN_TYPES.includes(summary_column_type)) { | ||
var formulaRow = formula_rows[result._id]; | ||
total = formulaRow && formulaRow[summary_column_key]; | ||
total = Array.isArray(total) ? total[0] : total; | ||
} else { | ||
total = result[summary_column_key]; | ||
} | ||
} | ||
break; | ||
} | ||
default: | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
return total || 0; | ||
} | ||
}, { | ||
key: "sortStatistics", | ||
@@ -459,29 +293,2 @@ value: function sortStatistics(statistics, column, sort_key) { | ||
} | ||
}, { | ||
key: "sortStatisticData", | ||
value: function sortStatisticData(statistics, sort_type) { | ||
statistics.sort(function (currResult, nextResult) { | ||
var current = currResult.value; | ||
var next = nextResult.value; | ||
if (!current && current !== 0) { | ||
return -1; | ||
} | ||
if (!next && next !== 0) { | ||
return 1; | ||
} | ||
if (sort_type === 'ascending') { | ||
return current > next ? 1 : -1; | ||
} else { | ||
return current > next ? -1 : 1; | ||
} | ||
}); | ||
} | ||
}, { | ||
key: "isArrayCellValue", | ||
value: function isArrayCellValue(columnType) { | ||
return [_dtableStore.CellType.MULTIPLE_SELECT, _dtableStore.CellType.COLLABORATOR, _dtableStore.CellType.LINK].includes(columnType); | ||
} | ||
}]); | ||
@@ -504,17 +311,3 @@ | ||
var isEmptyGeolocationCell = function isEmptyGeolocationCell(value, format) { | ||
if (!value) return null; | ||
if (format === 'lng_lat') { | ||
return value.lng && value.lat; | ||
} | ||
if (format === 'country_region') { | ||
return value.country_region; | ||
} | ||
return value.province; | ||
}; | ||
var _default = StatUtils; | ||
exports["default"] = _default; |
{ | ||
"name": "dtable-sdk", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "dtable sdk", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63238
1302