@splunk/visualization-encoding
Advanced tools
Comparing version 20.3.0 to 20.4.0
@@ -90,3 +90,3 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 20); | ||
/******/ return __webpack_require__(__webpack_require__.s = 17); | ||
/******/ }) | ||
@@ -96,3 +96,3 @@ /************************************************************************/ | ||
/***/ 20: | ||
/***/ 17: | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -99,0 +99,0 @@ |
468
DataFrame.js
@@ -100,3 +100,3 @@ /*! | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const TypeSafeValue_1 = __webpack_require__(6); | ||
const TypeSafeValue_1 = __webpack_require__(4); | ||
/** | ||
@@ -139,3 +139,3 @@ * Base DataPoint class and associated DataPoint selectors | ||
getRawValue() { | ||
return this.value.value; | ||
return this.value.toRawValue(); | ||
} | ||
@@ -159,3 +159,3 @@ /** | ||
module.exports = require("@splunk/moment"); | ||
module.exports = require("lodash"); | ||
@@ -341,6 +341,143 @@ /***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const colorUtils_1 = __webpack_require__(9); | ||
const types_1 = __webpack_require__(6); | ||
const moment_1 = __webpack_require__(7); | ||
/** | ||
* @implements {TypedValue} | ||
* TypeSafeValue implements the TypedValue interface, and adds additional methods 'isOk' which can be used to determine | ||
* if the value was properly coerced into the expected type. When isOk is false, it means that coerced value cannot | ||
* be relied upon. For example, if the type is 'time' but isOk is false, it is possible that the coerced value could be NaN. | ||
* A field named originalValue can be used for user-facing error messages in situations where isOk is false. For example: | ||
* "'cat' was not an OK value for a 'time' field". This class's fields are all immutable. | ||
*/ | ||
class TypeSafeValue { | ||
constructor(type, value, isOk, originalValue) { | ||
/** | ||
* isTypeSafe. This is a marker field. The presence of this field can be used at runtime to determine if TypedValue is rigorous, | ||
* loose. Loose TypedValue such as {type:'number', value:'cat'} are handy for testing, but can lie. Obviously 'cat' | ||
* is not a number. If the isTypeSafe field is present then the instance is a TypeSafeValue | ||
* @type {boolean} | ||
*/ | ||
this.isTypeSafe = true; | ||
/** | ||
* isOk. This field tells if the original value passed into this's constructor honored its type contract. | ||
* @type {boolean} | ||
*/ | ||
this.isOk = true; | ||
this.type = type; | ||
this.value = value; | ||
this.isOk = isOk; | ||
this.originalValue = originalValue; | ||
} | ||
/** | ||
* returns a TypeSafeValue, either by converting the non TypeSafeValue to | ||
* a TypeSafeValue, or by simply returning the passed-in TypeSafeValue | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {TypeSafeValue<T>} | ||
*/ | ||
static from(typedValue) { | ||
if (typedValue.isTypeSafe) { | ||
return typedValue; // just return what was passed in since it is already TypeSafeValue | ||
} | ||
else { | ||
const { value: originalValue, type } = typedValue; | ||
const [value, isOk] = TypeSafeValue.coerceValue(typedValue); | ||
return new TypeSafeValue(type, value, isOk, originalValue); | ||
} | ||
} | ||
/** | ||
* Creates a TypeSafeValue from a raw value | ||
* @param value | ||
* @returns {TypeSafeValue<DataType>} | ||
*/ | ||
static fromRaw(value) { | ||
const type = types_1.getDataTypeForPoint(value); | ||
return new TypeSafeValue(type, value, true, value); | ||
} | ||
/** | ||
* attempts to coerce the provided value to the provided type. Returns tuple | ||
* of the coerced value and a boolean telling if the coercion was clean (true) | ||
* or if the coercion was likely produced an unusable result, such as NaN for | ||
* a number, or '' for a color. | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {[any, boolean]} | ||
*/ | ||
static coerceValue(typedValue) { | ||
const { type, value } = typedValue; | ||
let coercedVal = null; | ||
let isOk; | ||
let acceptableType = true; | ||
try { | ||
switch (type) { | ||
case 'number': { | ||
isOk = types_1.isNumber(value); | ||
coercedVal = Number(value); | ||
break; | ||
} | ||
case 'time': { | ||
isOk = types_1.isTime(value); | ||
if (value instanceof Date) { | ||
coercedVal = value; | ||
} | ||
else { | ||
// for case like `VM-203`, It will be convereted to a Date. | ||
coercedVal = isOk ? new Date(value) : 'Invalid Date'; | ||
} | ||
break; | ||
} | ||
case 'string': { | ||
isOk = types_1.isString(value); | ||
coercedVal = value.toString(); | ||
break; | ||
} | ||
case 'color': { | ||
isOk = colorUtils_1.isColor(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
case 'sparkline': { | ||
isOk = Array.isArray(value) && value[0] === '##__SPARKLINE__##'; | ||
coercedVal = value; | ||
break; | ||
} | ||
case 'array': { | ||
isOk = Array.isArray(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
default: { | ||
acceptableType = false; | ||
} | ||
} | ||
} | ||
catch (e) { | ||
isOk = false; | ||
} | ||
if (!acceptableType) { | ||
throw new Error(`unknown type: '${type}'`); | ||
} | ||
return [coercedVal, isOk]; | ||
} | ||
toRawValue() { | ||
switch (this.type) { | ||
case 'time': | ||
return moment_1.default(this.value).format(); | ||
case 'sparkline': | ||
case 'array': | ||
case 'number': | ||
case 'string': | ||
case 'color': | ||
default: | ||
return this.value; | ||
} | ||
} | ||
} | ||
exports.TypeSafeValue = TypeSafeValue; | ||
/***/ }), | ||
@@ -355,3 +492,3 @@ /* 5 */ | ||
const DataSeries_1 = __webpack_require__(3); | ||
const types_1 = __webpack_require__(7); | ||
const types_1 = __webpack_require__(6); | ||
/** | ||
@@ -392,3 +529,3 @@ * Base DataFrame class and associated DataFrame selectors | ||
let dataPoints = []; | ||
const dataType = types_1.inferDataTypeFromSample(types_1.drawSample(data)); | ||
const dataType = types_1.inferDataTypeFromData(data); | ||
let field = fields[idx]; | ||
@@ -399,3 +536,3 @@ if (field.name) { | ||
} | ||
data.forEach(value => { | ||
data.forEach((value) => { | ||
dataPoints.push(new DataPoint_1.DataPoint(field, { value: value, type: dataType })); | ||
@@ -433,3 +570,3 @@ }); | ||
const indexedSeries = []; | ||
indexes.forEach(index => { | ||
indexes.forEach((index) => { | ||
const ds = this.series[index]; // should we allow negative indexes? | ||
@@ -469,3 +606,3 @@ if (ds != null) { | ||
const namedSeries = []; | ||
names.forEach(name => { | ||
names.forEach((name) => { | ||
const found = this.seriesByName(name); | ||
@@ -493,3 +630,3 @@ found && namedSeries.push(found); | ||
seriesByName(field) { | ||
return this.series.find(dataSeries => field === dataSeries.field); | ||
return this.series.find((dataSeries) => field === dataSeries.field); | ||
} | ||
@@ -505,3 +642,3 @@ /** | ||
// fixme todo ...what do we do about 'mixed mode' columns? | ||
dataSeries => dataSeries.points.some(dataPoint => type === dataPoint.getValue().type)); | ||
(dataSeries) => dataSeries.points.some((dataPoint) => type === dataPoint.getValue().type)); | ||
} | ||
@@ -514,3 +651,3 @@ /** | ||
setValue(v) { | ||
this.series.forEach(s => s.setValue(v)); | ||
this.series.forEach((s) => s.setValue(v)); | ||
} | ||
@@ -524,3 +661,3 @@ /** | ||
const values = []; | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
values.push(s.getRawValue()); | ||
@@ -537,3 +674,3 @@ }); | ||
const values = []; | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
values.push(s.getValue()); | ||
@@ -549,3 +686,3 @@ }); | ||
getField() { | ||
const points = this.series.map(s => s.getField()); | ||
const points = this.series.map((s) => s.getField()); | ||
return new DataSeries_1.DataSeries(points); | ||
@@ -577,3 +714,3 @@ } | ||
const overallSeries = new DataSeries_1.DataSeries(); | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
const m = s[funcName](); | ||
@@ -595,142 +732,6 @@ m && overallSeries.points.push(m); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const colorUtils_1 = __webpack_require__(4); | ||
const types_1 = __webpack_require__(7); | ||
const moment_1 = __webpack_require__(7); | ||
const lodash_1 = __webpack_require__(2); | ||
const colorUtils_1 = __webpack_require__(9); | ||
/** | ||
* @implements {TypedValue} | ||
* TypeSafeValue implements the TypedValue interface, and adds additional methods 'isOk' which can be used to determine | ||
* if the value was properly coerced into the expected type. When isOk is false, it means that coerced value cannot | ||
* be relied upon. For example, if the type is 'time' but isOk is false, it is possible that the coerced value could be NaN. | ||
* A field named originalValue can be used for user-facing error messages in situations where isOk is false. For example: | ||
* "'cat' was not an OK value for a 'time' field". This class's fields are all immutable. | ||
*/ | ||
class TypeSafeValue { | ||
constructor(type, value, isOk, originalValue) { | ||
/** | ||
* isTypeSafe. This is a marker field. The presence of this field can be used at runtime to determine if TypedValue is rigorous, | ||
* loose. Loose TypedValue such as {type:'number', value:'cat'} are handy for testing, but can lie. Obviously 'cat' | ||
* is not a number. If the isTypeSafe field is present then the instance is a TypeSafeValue | ||
* @type {boolean} | ||
*/ | ||
this.isTypeSafe = true; | ||
/** | ||
* isOk. This field tells if the original value passed into this's constructor honored its type contract. | ||
* @type {boolean} | ||
*/ | ||
this.isOk = true; | ||
this.type = type; | ||
this.value = value; | ||
this.isOk = isOk; | ||
this.originalValue = originalValue; | ||
} | ||
/** | ||
* returns a TypeSafeValue, either by converting the non TypeSafeValue to | ||
* a TypeSafeValue, or by simply returning the passed-in TypeSafeValue | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {TypeSafeValue<T>} | ||
*/ | ||
static from(typedValue) { | ||
if (typedValue.isTypeSafe) { | ||
return typedValue; // just return what was passed in since it is already TypeSafeValue | ||
} | ||
else { | ||
const { value: originalValue, type } = typedValue; | ||
const [value, isOk] = TypeSafeValue.coerceValue(typedValue); | ||
return new TypeSafeValue(type, value, isOk, originalValue); | ||
} | ||
} | ||
/** | ||
* Creates a TypeSafeValue from a raw value | ||
* @param value | ||
* @returns {TypeSafeValue<DataType>} | ||
*/ | ||
static fromRaw(value) { | ||
const type = types_1.getDataTypeForPoint(value); | ||
return new TypeSafeValue(type, value, true, value); | ||
} | ||
/** | ||
* attempts to coerce the provided value to the provided type. Returns tuple | ||
* of the coerced value and a boolean telling if the coercion was clean (true) | ||
* or if the coercion was likely produced an unusable result, such as NaN for | ||
* a number, or '' for a color. | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {[any, boolean]} | ||
*/ | ||
static coerceValue(typedValue) { | ||
const { type, value } = typedValue; | ||
let coercedVal = null; | ||
let isOk; | ||
let acceptableType = true; | ||
try { | ||
switch (type) { | ||
case 'number': { | ||
isOk = types_1.isNumber(value); | ||
coercedVal = Number(value); | ||
break; | ||
} | ||
case 'time': { | ||
isOk = types_1.isTime(value); | ||
if (value instanceof Date) { | ||
coercedVal = value; | ||
} | ||
else { | ||
// for case like `VM-203`, It will be convereted to a Date. | ||
coercedVal = isOk ? new Date(value) : 'Invalid Date'; | ||
} | ||
break; | ||
} | ||
case 'string': { | ||
isOk = types_1.isString(value); | ||
coercedVal = value.toString(); | ||
break; | ||
} | ||
case 'color': { | ||
isOk = colorUtils_1.isColor(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
default: { | ||
acceptableType = false; | ||
} | ||
} | ||
} | ||
catch (e) { | ||
isOk = false; | ||
} | ||
if (!acceptableType) { | ||
throw new Error(`unknown type: '${type}'`); | ||
} | ||
return [coercedVal, isOk]; | ||
} | ||
} | ||
exports.TypeSafeValue = TypeSafeValue; | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isNumber", function() { return isNumber; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isTime", function() { return isTime; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isString", function() { return isString; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDataTypeForPoint", function() { return getDataTypeForPoint; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "inferDataTypeFromSample", function() { return inferDataTypeFromSample; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drawSample", function() { return drawSample; }); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(10); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_isObject__WEBPACK_IMPORTED_MODULE_2__); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_splunk_moment__WEBPACK_IMPORTED_MODULE_3__); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__); | ||
/** | ||
* returns true if this dataPoint is a finite number | ||
@@ -740,6 +741,6 @@ * @param dataPoint | ||
*/ | ||
function isNumber(dataPoint) { | ||
return lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default()(+dataPoint) && lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default()(+dataPoint); | ||
return lodash_1.isFinite(+dataPoint) && lodash_1.isNumber(+dataPoint); | ||
} | ||
exports.isNumber = isNumber; | ||
/** | ||
@@ -750,11 +751,22 @@ *returns OK if data is time | ||
*/ | ||
function isTime(dataPoint) { | ||
if (!dataPoint) { | ||
return false; | ||
} // only support time string in ISO_8601 format: https://www.w3.org/TR/NOTE-datetime | ||
return typeof dataPoint === 'string' ? _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint, _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default.a.ISO_8601, true).isValid() : _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint).isValid(); | ||
if (!dataPoint) { | ||
return false; | ||
} | ||
// only support time string in following format: https://www.w3.org/TR/NOTE-datetime | ||
const supportedDateFormats = [ | ||
'YYYY-MM-DD', | ||
moment_1.default.ISO_8601, | ||
'YYYY-MM-DDTHH:mm', | ||
'YYYY-MM-DDTHH:mm:ss.SSS', | ||
'YYYY-MM-DDTHH:mm:ss', | ||
'YYYY-MM-DD HH:MM', | ||
'YYYY-MM-DD HH:MM:SS', | ||
'YYYY-MM-DD HH:MM:SS.SSS', | ||
]; | ||
return typeof dataPoint === 'string' | ||
? moment_1.default(dataPoint, supportedDateFormats, true).isValid() | ||
: moment_1.default(dataPoint).isValid(); | ||
} | ||
exports.isTime = isTime; | ||
/** | ||
@@ -765,6 +777,6 @@ * returns OK if data is string | ||
*/ | ||
function isString(dataPoint) { | ||
return typeof dataPoint === 'string'; | ||
return typeof dataPoint === 'string'; | ||
} | ||
exports.isString = isString; | ||
/** | ||
@@ -779,18 +791,26 @@ * getDataTypeForPoint | ||
*/ | ||
var getDataTypeForPoint = function getDataTypeForPoint(dataPoint) { | ||
if (lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default()(dataPoint)) { | ||
exports.getDataTypeForPoint = (dataPoint) => { | ||
if (Array.isArray(dataPoint)) { | ||
if (dataPoint.length > 1 && dataPoint[0] === '##__SPARKLINE__##') { | ||
return 'sparkline'; | ||
} | ||
return 'array'; | ||
} | ||
else if (lodash_1.isObject(dataPoint)) { | ||
return 'unknown'; | ||
} | ||
else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} | ||
else if (colorUtils_1.isColor(dataPoint)) { | ||
return 'color'; | ||
} | ||
else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} | ||
else if (isString(dataPoint)) { | ||
return 'string'; | ||
} | ||
// nulls, objects, etc | ||
return 'unknown'; | ||
} else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} else if (Object(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__["isColor"])(dataPoint)) { | ||
return 'color'; | ||
} else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} else if (isString(dataPoint)) { | ||
return 'string'; | ||
} // nulls, objects, etc | ||
return 'unknown'; | ||
}; | ||
@@ -805,23 +825,24 @@ /** | ||
*/ | ||
var inferDataTypeFromSample = function inferDataTypeFromSample(dataSample) { | ||
var typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0 | ||
}; | ||
dataSample.forEach(function (point) { | ||
return typeMatches[getDataTypeForPoint(point)] += 1; | ||
}); | ||
var typeCount = -1; | ||
var returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach(function (key) { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
exports.inferDataTypeFromSample = (dataSample) => { | ||
const typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0, | ||
array: 0, | ||
sparkline: 0, | ||
}; | ||
dataSample.forEach((point) => { | ||
typeMatches[exports.getDataTypeForPoint(point)] += 1; | ||
}); | ||
let typeCount = -1; | ||
let returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach((key) => { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
}; | ||
@@ -835,34 +856,31 @@ /** | ||
*/ | ||
var drawSample = function drawSample(data) { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} // small enough to check everything | ||
return data; | ||
exports.drawSample = (data) => { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} | ||
// small enough to check everything | ||
return data; | ||
}; | ||
/** | ||
* | ||
* @param {*} data | ||
*/ | ||
exports.inferDataTypeFromData = (data) => exports.inferDataTypeFromSample(exports.drawSample(data)); | ||
/***/ }), | ||
/* 8 */, | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isNumber"); | ||
/***/ }), | ||
/* 10 */ | ||
/* 7 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isFinite"); | ||
module.exports = require("@splunk/moment"); | ||
/***/ }), | ||
/* 11 */ | ||
/* 8 */, | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isObject"); | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
@@ -869,0 +887,0 @@ /***/ }) |
226
DataPoint.js
@@ -100,3 +100,3 @@ /*! | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const TypeSafeValue_1 = __webpack_require__(6); | ||
const TypeSafeValue_1 = __webpack_require__(4); | ||
/** | ||
@@ -139,3 +139,3 @@ * Base DataPoint class and associated DataPoint selectors | ||
getRawValue() { | ||
return this.value.value; | ||
return this.value.toRawValue(); | ||
} | ||
@@ -159,3 +159,3 @@ /** | ||
module.exports = require("@splunk/moment"); | ||
module.exports = require("lodash"); | ||
@@ -165,9 +165,2 @@ /***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
/***/ }), | ||
/* 5 */, | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -178,4 +171,5 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const colorUtils_1 = __webpack_require__(4); | ||
const types_1 = __webpack_require__(7); | ||
const colorUtils_1 = __webpack_require__(9); | ||
const types_1 = __webpack_require__(6); | ||
const moment_1 = __webpack_require__(7); | ||
/** | ||
@@ -274,2 +268,12 @@ * @implements {TypedValue} | ||
} | ||
case 'sparkline': { | ||
isOk = Array.isArray(value) && value[0] === '##__SPARKLINE__##'; | ||
coercedVal = value; | ||
break; | ||
} | ||
case 'array': { | ||
isOk = Array.isArray(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
default: { | ||
@@ -288,2 +292,15 @@ acceptableType = false; | ||
} | ||
toRawValue() { | ||
switch (this.type) { | ||
case 'time': | ||
return moment_1.default(this.value).format(); | ||
case 'sparkline': | ||
case 'array': | ||
case 'number': | ||
case 'string': | ||
case 'color': | ||
default: | ||
return this.value; | ||
} | ||
} | ||
} | ||
@@ -294,28 +311,12 @@ exports.TypeSafeValue = TypeSafeValue; | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/* 5 */, | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isNumber", function() { return isNumber; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isTime", function() { return isTime; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isString", function() { return isString; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDataTypeForPoint", function() { return getDataTypeForPoint; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "inferDataTypeFromSample", function() { return inferDataTypeFromSample; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drawSample", function() { return drawSample; }); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(10); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_isObject__WEBPACK_IMPORTED_MODULE_2__); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_splunk_moment__WEBPACK_IMPORTED_MODULE_3__); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const moment_1 = __webpack_require__(7); | ||
const lodash_1 = __webpack_require__(2); | ||
const colorUtils_1 = __webpack_require__(9); | ||
/** | ||
@@ -326,6 +327,6 @@ * returns true if this dataPoint is a finite number | ||
*/ | ||
function isNumber(dataPoint) { | ||
return lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default()(+dataPoint) && lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default()(+dataPoint); | ||
return lodash_1.isFinite(+dataPoint) && lodash_1.isNumber(+dataPoint); | ||
} | ||
exports.isNumber = isNumber; | ||
/** | ||
@@ -336,11 +337,22 @@ *returns OK if data is time | ||
*/ | ||
function isTime(dataPoint) { | ||
if (!dataPoint) { | ||
return false; | ||
} // only support time string in ISO_8601 format: https://www.w3.org/TR/NOTE-datetime | ||
return typeof dataPoint === 'string' ? _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint, _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default.a.ISO_8601, true).isValid() : _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint).isValid(); | ||
if (!dataPoint) { | ||
return false; | ||
} | ||
// only support time string in following format: https://www.w3.org/TR/NOTE-datetime | ||
const supportedDateFormats = [ | ||
'YYYY-MM-DD', | ||
moment_1.default.ISO_8601, | ||
'YYYY-MM-DDTHH:mm', | ||
'YYYY-MM-DDTHH:mm:ss.SSS', | ||
'YYYY-MM-DDTHH:mm:ss', | ||
'YYYY-MM-DD HH:MM', | ||
'YYYY-MM-DD HH:MM:SS', | ||
'YYYY-MM-DD HH:MM:SS.SSS', | ||
]; | ||
return typeof dataPoint === 'string' | ||
? moment_1.default(dataPoint, supportedDateFormats, true).isValid() | ||
: moment_1.default(dataPoint).isValid(); | ||
} | ||
exports.isTime = isTime; | ||
/** | ||
@@ -351,6 +363,6 @@ * returns OK if data is string | ||
*/ | ||
function isString(dataPoint) { | ||
return typeof dataPoint === 'string'; | ||
return typeof dataPoint === 'string'; | ||
} | ||
exports.isString = isString; | ||
/** | ||
@@ -365,18 +377,26 @@ * getDataTypeForPoint | ||
*/ | ||
var getDataTypeForPoint = function getDataTypeForPoint(dataPoint) { | ||
if (lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default()(dataPoint)) { | ||
exports.getDataTypeForPoint = (dataPoint) => { | ||
if (Array.isArray(dataPoint)) { | ||
if (dataPoint.length > 1 && dataPoint[0] === '##__SPARKLINE__##') { | ||
return 'sparkline'; | ||
} | ||
return 'array'; | ||
} | ||
else if (lodash_1.isObject(dataPoint)) { | ||
return 'unknown'; | ||
} | ||
else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} | ||
else if (colorUtils_1.isColor(dataPoint)) { | ||
return 'color'; | ||
} | ||
else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} | ||
else if (isString(dataPoint)) { | ||
return 'string'; | ||
} | ||
// nulls, objects, etc | ||
return 'unknown'; | ||
} else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} else if (Object(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__["isColor"])(dataPoint)) { | ||
return 'color'; | ||
} else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} else if (isString(dataPoint)) { | ||
return 'string'; | ||
} // nulls, objects, etc | ||
return 'unknown'; | ||
}; | ||
@@ -391,23 +411,24 @@ /** | ||
*/ | ||
var inferDataTypeFromSample = function inferDataTypeFromSample(dataSample) { | ||
var typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0 | ||
}; | ||
dataSample.forEach(function (point) { | ||
return typeMatches[getDataTypeForPoint(point)] += 1; | ||
}); | ||
var typeCount = -1; | ||
var returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach(function (key) { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
exports.inferDataTypeFromSample = (dataSample) => { | ||
const typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0, | ||
array: 0, | ||
sparkline: 0, | ||
}; | ||
dataSample.forEach((point) => { | ||
typeMatches[exports.getDataTypeForPoint(point)] += 1; | ||
}); | ||
let typeCount = -1; | ||
let returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach((key) => { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
}; | ||
@@ -421,34 +442,31 @@ /** | ||
*/ | ||
var drawSample = function drawSample(data) { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} // small enough to check everything | ||
return data; | ||
exports.drawSample = (data) => { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} | ||
// small enough to check everything | ||
return data; | ||
}; | ||
/** | ||
* | ||
* @param {*} data | ||
*/ | ||
exports.inferDataTypeFromData = (data) => exports.inferDataTypeFromSample(exports.drawSample(data)); | ||
/***/ }), | ||
/* 8 */, | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isNumber"); | ||
/***/ }), | ||
/* 10 */ | ||
/* 7 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isFinite"); | ||
module.exports = require("@splunk/moment"); | ||
/***/ }), | ||
/* 11 */ | ||
/* 8 */, | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isObject"); | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
@@ -455,0 +473,0 @@ /***/ }) |
@@ -90,3 +90,3 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 13); | ||
/******/ return __webpack_require__(__webpack_require__.s = 10); | ||
/******/ }) | ||
@@ -101,3 +101,3 @@ /************************************************************************/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const TypeSafeValue_1 = __webpack_require__(6); | ||
const TypeSafeValue_1 = __webpack_require__(4); | ||
/** | ||
@@ -140,3 +140,3 @@ * Base DataPoint class and associated DataPoint selectors | ||
getRawValue() { | ||
return this.value.value; | ||
return this.value.toRawValue(); | ||
} | ||
@@ -160,3 +160,3 @@ /** | ||
module.exports = require("@splunk/moment"); | ||
module.exports = require("lodash"); | ||
@@ -342,6 +342,143 @@ /***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const colorUtils_1 = __webpack_require__(9); | ||
const types_1 = __webpack_require__(6); | ||
const moment_1 = __webpack_require__(7); | ||
/** | ||
* @implements {TypedValue} | ||
* TypeSafeValue implements the TypedValue interface, and adds additional methods 'isOk' which can be used to determine | ||
* if the value was properly coerced into the expected type. When isOk is false, it means that coerced value cannot | ||
* be relied upon. For example, if the type is 'time' but isOk is false, it is possible that the coerced value could be NaN. | ||
* A field named originalValue can be used for user-facing error messages in situations where isOk is false. For example: | ||
* "'cat' was not an OK value for a 'time' field". This class's fields are all immutable. | ||
*/ | ||
class TypeSafeValue { | ||
constructor(type, value, isOk, originalValue) { | ||
/** | ||
* isTypeSafe. This is a marker field. The presence of this field can be used at runtime to determine if TypedValue is rigorous, | ||
* loose. Loose TypedValue such as {type:'number', value:'cat'} are handy for testing, but can lie. Obviously 'cat' | ||
* is not a number. If the isTypeSafe field is present then the instance is a TypeSafeValue | ||
* @type {boolean} | ||
*/ | ||
this.isTypeSafe = true; | ||
/** | ||
* isOk. This field tells if the original value passed into this's constructor honored its type contract. | ||
* @type {boolean} | ||
*/ | ||
this.isOk = true; | ||
this.type = type; | ||
this.value = value; | ||
this.isOk = isOk; | ||
this.originalValue = originalValue; | ||
} | ||
/** | ||
* returns a TypeSafeValue, either by converting the non TypeSafeValue to | ||
* a TypeSafeValue, or by simply returning the passed-in TypeSafeValue | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {TypeSafeValue<T>} | ||
*/ | ||
static from(typedValue) { | ||
if (typedValue.isTypeSafe) { | ||
return typedValue; // just return what was passed in since it is already TypeSafeValue | ||
} | ||
else { | ||
const { value: originalValue, type } = typedValue; | ||
const [value, isOk] = TypeSafeValue.coerceValue(typedValue); | ||
return new TypeSafeValue(type, value, isOk, originalValue); | ||
} | ||
} | ||
/** | ||
* Creates a TypeSafeValue from a raw value | ||
* @param value | ||
* @returns {TypeSafeValue<DataType>} | ||
*/ | ||
static fromRaw(value) { | ||
const type = types_1.getDataTypeForPoint(value); | ||
return new TypeSafeValue(type, value, true, value); | ||
} | ||
/** | ||
* attempts to coerce the provided value to the provided type. Returns tuple | ||
* of the coerced value and a boolean telling if the coercion was clean (true) | ||
* or if the coercion was likely produced an unusable result, such as NaN for | ||
* a number, or '' for a color. | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {[any, boolean]} | ||
*/ | ||
static coerceValue(typedValue) { | ||
const { type, value } = typedValue; | ||
let coercedVal = null; | ||
let isOk; | ||
let acceptableType = true; | ||
try { | ||
switch (type) { | ||
case 'number': { | ||
isOk = types_1.isNumber(value); | ||
coercedVal = Number(value); | ||
break; | ||
} | ||
case 'time': { | ||
isOk = types_1.isTime(value); | ||
if (value instanceof Date) { | ||
coercedVal = value; | ||
} | ||
else { | ||
// for case like `VM-203`, It will be convereted to a Date. | ||
coercedVal = isOk ? new Date(value) : 'Invalid Date'; | ||
} | ||
break; | ||
} | ||
case 'string': { | ||
isOk = types_1.isString(value); | ||
coercedVal = value.toString(); | ||
break; | ||
} | ||
case 'color': { | ||
isOk = colorUtils_1.isColor(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
case 'sparkline': { | ||
isOk = Array.isArray(value) && value[0] === '##__SPARKLINE__##'; | ||
coercedVal = value; | ||
break; | ||
} | ||
case 'array': { | ||
isOk = Array.isArray(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
default: { | ||
acceptableType = false; | ||
} | ||
} | ||
} | ||
catch (e) { | ||
isOk = false; | ||
} | ||
if (!acceptableType) { | ||
throw new Error(`unknown type: '${type}'`); | ||
} | ||
return [coercedVal, isOk]; | ||
} | ||
toRawValue() { | ||
switch (this.type) { | ||
case 'time': | ||
return moment_1.default(this.value).format(); | ||
case 'sparkline': | ||
case 'array': | ||
case 'number': | ||
case 'string': | ||
case 'color': | ||
default: | ||
return this.value; | ||
} | ||
} | ||
} | ||
exports.TypeSafeValue = TypeSafeValue; | ||
/***/ }), | ||
@@ -356,3 +493,3 @@ /* 5 */ | ||
const DataSeries_1 = __webpack_require__(3); | ||
const types_1 = __webpack_require__(7); | ||
const types_1 = __webpack_require__(6); | ||
/** | ||
@@ -393,3 +530,3 @@ * Base DataFrame class and associated DataFrame selectors | ||
let dataPoints = []; | ||
const dataType = types_1.inferDataTypeFromSample(types_1.drawSample(data)); | ||
const dataType = types_1.inferDataTypeFromData(data); | ||
let field = fields[idx]; | ||
@@ -400,3 +537,3 @@ if (field.name) { | ||
} | ||
data.forEach(value => { | ||
data.forEach((value) => { | ||
dataPoints.push(new DataPoint_1.DataPoint(field, { value: value, type: dataType })); | ||
@@ -434,3 +571,3 @@ }); | ||
const indexedSeries = []; | ||
indexes.forEach(index => { | ||
indexes.forEach((index) => { | ||
const ds = this.series[index]; // should we allow negative indexes? | ||
@@ -470,3 +607,3 @@ if (ds != null) { | ||
const namedSeries = []; | ||
names.forEach(name => { | ||
names.forEach((name) => { | ||
const found = this.seriesByName(name); | ||
@@ -494,3 +631,3 @@ found && namedSeries.push(found); | ||
seriesByName(field) { | ||
return this.series.find(dataSeries => field === dataSeries.field); | ||
return this.series.find((dataSeries) => field === dataSeries.field); | ||
} | ||
@@ -506,3 +643,3 @@ /** | ||
// fixme todo ...what do we do about 'mixed mode' columns? | ||
dataSeries => dataSeries.points.some(dataPoint => type === dataPoint.getValue().type)); | ||
(dataSeries) => dataSeries.points.some((dataPoint) => type === dataPoint.getValue().type)); | ||
} | ||
@@ -515,3 +652,3 @@ /** | ||
setValue(v) { | ||
this.series.forEach(s => s.setValue(v)); | ||
this.series.forEach((s) => s.setValue(v)); | ||
} | ||
@@ -525,3 +662,3 @@ /** | ||
const values = []; | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
values.push(s.getRawValue()); | ||
@@ -538,3 +675,3 @@ }); | ||
const values = []; | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
values.push(s.getValue()); | ||
@@ -550,3 +687,3 @@ }); | ||
getField() { | ||
const points = this.series.map(s => s.getField()); | ||
const points = this.series.map((s) => s.getField()); | ||
return new DataSeries_1.DataSeries(points); | ||
@@ -578,3 +715,3 @@ } | ||
const overallSeries = new DataSeries_1.DataSeries(); | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
const m = s[funcName](); | ||
@@ -596,142 +733,6 @@ m && overallSeries.points.push(m); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const colorUtils_1 = __webpack_require__(4); | ||
const types_1 = __webpack_require__(7); | ||
const moment_1 = __webpack_require__(7); | ||
const lodash_1 = __webpack_require__(2); | ||
const colorUtils_1 = __webpack_require__(9); | ||
/** | ||
* @implements {TypedValue} | ||
* TypeSafeValue implements the TypedValue interface, and adds additional methods 'isOk' which can be used to determine | ||
* if the value was properly coerced into the expected type. When isOk is false, it means that coerced value cannot | ||
* be relied upon. For example, if the type is 'time' but isOk is false, it is possible that the coerced value could be NaN. | ||
* A field named originalValue can be used for user-facing error messages in situations where isOk is false. For example: | ||
* "'cat' was not an OK value for a 'time' field". This class's fields are all immutable. | ||
*/ | ||
class TypeSafeValue { | ||
constructor(type, value, isOk, originalValue) { | ||
/** | ||
* isTypeSafe. This is a marker field. The presence of this field can be used at runtime to determine if TypedValue is rigorous, | ||
* loose. Loose TypedValue such as {type:'number', value:'cat'} are handy for testing, but can lie. Obviously 'cat' | ||
* is not a number. If the isTypeSafe field is present then the instance is a TypeSafeValue | ||
* @type {boolean} | ||
*/ | ||
this.isTypeSafe = true; | ||
/** | ||
* isOk. This field tells if the original value passed into this's constructor honored its type contract. | ||
* @type {boolean} | ||
*/ | ||
this.isOk = true; | ||
this.type = type; | ||
this.value = value; | ||
this.isOk = isOk; | ||
this.originalValue = originalValue; | ||
} | ||
/** | ||
* returns a TypeSafeValue, either by converting the non TypeSafeValue to | ||
* a TypeSafeValue, or by simply returning the passed-in TypeSafeValue | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {TypeSafeValue<T>} | ||
*/ | ||
static from(typedValue) { | ||
if (typedValue.isTypeSafe) { | ||
return typedValue; // just return what was passed in since it is already TypeSafeValue | ||
} | ||
else { | ||
const { value: originalValue, type } = typedValue; | ||
const [value, isOk] = TypeSafeValue.coerceValue(typedValue); | ||
return new TypeSafeValue(type, value, isOk, originalValue); | ||
} | ||
} | ||
/** | ||
* Creates a TypeSafeValue from a raw value | ||
* @param value | ||
* @returns {TypeSafeValue<DataType>} | ||
*/ | ||
static fromRaw(value) { | ||
const type = types_1.getDataTypeForPoint(value); | ||
return new TypeSafeValue(type, value, true, value); | ||
} | ||
/** | ||
* attempts to coerce the provided value to the provided type. Returns tuple | ||
* of the coerced value and a boolean telling if the coercion was clean (true) | ||
* or if the coercion was likely produced an unusable result, such as NaN for | ||
* a number, or '' for a color. | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {[any, boolean]} | ||
*/ | ||
static coerceValue(typedValue) { | ||
const { type, value } = typedValue; | ||
let coercedVal = null; | ||
let isOk; | ||
let acceptableType = true; | ||
try { | ||
switch (type) { | ||
case 'number': { | ||
isOk = types_1.isNumber(value); | ||
coercedVal = Number(value); | ||
break; | ||
} | ||
case 'time': { | ||
isOk = types_1.isTime(value); | ||
if (value instanceof Date) { | ||
coercedVal = value; | ||
} | ||
else { | ||
// for case like `VM-203`, It will be convereted to a Date. | ||
coercedVal = isOk ? new Date(value) : 'Invalid Date'; | ||
} | ||
break; | ||
} | ||
case 'string': { | ||
isOk = types_1.isString(value); | ||
coercedVal = value.toString(); | ||
break; | ||
} | ||
case 'color': { | ||
isOk = colorUtils_1.isColor(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
default: { | ||
acceptableType = false; | ||
} | ||
} | ||
} | ||
catch (e) { | ||
isOk = false; | ||
} | ||
if (!acceptableType) { | ||
throw new Error(`unknown type: '${type}'`); | ||
} | ||
return [coercedVal, isOk]; | ||
} | ||
} | ||
exports.TypeSafeValue = TypeSafeValue; | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isNumber", function() { return isNumber; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isTime", function() { return isTime; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isString", function() { return isString; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDataTypeForPoint", function() { return getDataTypeForPoint; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "inferDataTypeFromSample", function() { return inferDataTypeFromSample; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drawSample", function() { return drawSample; }); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(10); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_isObject__WEBPACK_IMPORTED_MODULE_2__); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_splunk_moment__WEBPACK_IMPORTED_MODULE_3__); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__); | ||
/** | ||
* returns true if this dataPoint is a finite number | ||
@@ -741,6 +742,6 @@ * @param dataPoint | ||
*/ | ||
function isNumber(dataPoint) { | ||
return lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default()(+dataPoint) && lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default()(+dataPoint); | ||
return lodash_1.isFinite(+dataPoint) && lodash_1.isNumber(+dataPoint); | ||
} | ||
exports.isNumber = isNumber; | ||
/** | ||
@@ -751,11 +752,22 @@ *returns OK if data is time | ||
*/ | ||
function isTime(dataPoint) { | ||
if (!dataPoint) { | ||
return false; | ||
} // only support time string in ISO_8601 format: https://www.w3.org/TR/NOTE-datetime | ||
return typeof dataPoint === 'string' ? _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint, _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default.a.ISO_8601, true).isValid() : _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint).isValid(); | ||
if (!dataPoint) { | ||
return false; | ||
} | ||
// only support time string in following format: https://www.w3.org/TR/NOTE-datetime | ||
const supportedDateFormats = [ | ||
'YYYY-MM-DD', | ||
moment_1.default.ISO_8601, | ||
'YYYY-MM-DDTHH:mm', | ||
'YYYY-MM-DDTHH:mm:ss.SSS', | ||
'YYYY-MM-DDTHH:mm:ss', | ||
'YYYY-MM-DD HH:MM', | ||
'YYYY-MM-DD HH:MM:SS', | ||
'YYYY-MM-DD HH:MM:SS.SSS', | ||
]; | ||
return typeof dataPoint === 'string' | ||
? moment_1.default(dataPoint, supportedDateFormats, true).isValid() | ||
: moment_1.default(dataPoint).isValid(); | ||
} | ||
exports.isTime = isTime; | ||
/** | ||
@@ -766,6 +778,6 @@ * returns OK if data is string | ||
*/ | ||
function isString(dataPoint) { | ||
return typeof dataPoint === 'string'; | ||
return typeof dataPoint === 'string'; | ||
} | ||
exports.isString = isString; | ||
/** | ||
@@ -780,18 +792,26 @@ * getDataTypeForPoint | ||
*/ | ||
var getDataTypeForPoint = function getDataTypeForPoint(dataPoint) { | ||
if (lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default()(dataPoint)) { | ||
exports.getDataTypeForPoint = (dataPoint) => { | ||
if (Array.isArray(dataPoint)) { | ||
if (dataPoint.length > 1 && dataPoint[0] === '##__SPARKLINE__##') { | ||
return 'sparkline'; | ||
} | ||
return 'array'; | ||
} | ||
else if (lodash_1.isObject(dataPoint)) { | ||
return 'unknown'; | ||
} | ||
else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} | ||
else if (colorUtils_1.isColor(dataPoint)) { | ||
return 'color'; | ||
} | ||
else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} | ||
else if (isString(dataPoint)) { | ||
return 'string'; | ||
} | ||
// nulls, objects, etc | ||
return 'unknown'; | ||
} else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} else if (Object(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__["isColor"])(dataPoint)) { | ||
return 'color'; | ||
} else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} else if (isString(dataPoint)) { | ||
return 'string'; | ||
} // nulls, objects, etc | ||
return 'unknown'; | ||
}; | ||
@@ -806,23 +826,24 @@ /** | ||
*/ | ||
var inferDataTypeFromSample = function inferDataTypeFromSample(dataSample) { | ||
var typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0 | ||
}; | ||
dataSample.forEach(function (point) { | ||
return typeMatches[getDataTypeForPoint(point)] += 1; | ||
}); | ||
var typeCount = -1; | ||
var returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach(function (key) { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
exports.inferDataTypeFromSample = (dataSample) => { | ||
const typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0, | ||
array: 0, | ||
sparkline: 0, | ||
}; | ||
dataSample.forEach((point) => { | ||
typeMatches[exports.getDataTypeForPoint(point)] += 1; | ||
}); | ||
let typeCount = -1; | ||
let returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach((key) => { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
}; | ||
@@ -836,16 +857,25 @@ /** | ||
*/ | ||
exports.drawSample = (data) => { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} | ||
// small enough to check everything | ||
return data; | ||
}; | ||
/** | ||
* | ||
* @param {*} data | ||
*/ | ||
exports.inferDataTypeFromData = (data) => exports.inferDataTypeFromSample(exports.drawSample(data)); | ||
var drawSample = function drawSample(data) { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} // small enough to check everything | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("@splunk/moment"); | ||
return data; | ||
}; | ||
/***/ }), | ||
@@ -856,19 +886,6 @@ /* 8 */, | ||
module.exports = require("lodash/isNumber"); | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
/***/ }), | ||
/* 10 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isFinite"); | ||
/***/ }), | ||
/* 11 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isObject"); | ||
/***/ }), | ||
/* 12 */, | ||
/* 13 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -875,0 +892,0 @@ |
@@ -100,3 +100,3 @@ /*! | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const TypeSafeValue_1 = __webpack_require__(6); | ||
const TypeSafeValue_1 = __webpack_require__(4); | ||
/** | ||
@@ -139,3 +139,3 @@ * Base DataPoint class and associated DataPoint selectors | ||
getRawValue() { | ||
return this.value.value; | ||
return this.value.toRawValue(); | ||
} | ||
@@ -159,3 +159,3 @@ /** | ||
module.exports = require("@splunk/moment"); | ||
module.exports = require("lodash"); | ||
@@ -341,9 +341,2 @@ /***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
/***/ }), | ||
/* 5 */, | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -354,4 +347,5 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const colorUtils_1 = __webpack_require__(4); | ||
const types_1 = __webpack_require__(7); | ||
const colorUtils_1 = __webpack_require__(9); | ||
const types_1 = __webpack_require__(6); | ||
const moment_1 = __webpack_require__(7); | ||
/** | ||
@@ -450,2 +444,12 @@ * @implements {TypedValue} | ||
} | ||
case 'sparkline': { | ||
isOk = Array.isArray(value) && value[0] === '##__SPARKLINE__##'; | ||
coercedVal = value; | ||
break; | ||
} | ||
case 'array': { | ||
isOk = Array.isArray(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
default: { | ||
@@ -464,2 +468,15 @@ acceptableType = false; | ||
} | ||
toRawValue() { | ||
switch (this.type) { | ||
case 'time': | ||
return moment_1.default(this.value).format(); | ||
case 'sparkline': | ||
case 'array': | ||
case 'number': | ||
case 'string': | ||
case 'color': | ||
default: | ||
return this.value; | ||
} | ||
} | ||
} | ||
@@ -470,28 +487,12 @@ exports.TypeSafeValue = TypeSafeValue; | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/* 5 */, | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isNumber", function() { return isNumber; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isTime", function() { return isTime; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isString", function() { return isString; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDataTypeForPoint", function() { return getDataTypeForPoint; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "inferDataTypeFromSample", function() { return inferDataTypeFromSample; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drawSample", function() { return drawSample; }); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(10); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_isObject__WEBPACK_IMPORTED_MODULE_2__); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_splunk_moment__WEBPACK_IMPORTED_MODULE_3__); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const moment_1 = __webpack_require__(7); | ||
const lodash_1 = __webpack_require__(2); | ||
const colorUtils_1 = __webpack_require__(9); | ||
/** | ||
@@ -502,6 +503,6 @@ * returns true if this dataPoint is a finite number | ||
*/ | ||
function isNumber(dataPoint) { | ||
return lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default()(+dataPoint) && lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default()(+dataPoint); | ||
return lodash_1.isFinite(+dataPoint) && lodash_1.isNumber(+dataPoint); | ||
} | ||
exports.isNumber = isNumber; | ||
/** | ||
@@ -512,11 +513,22 @@ *returns OK if data is time | ||
*/ | ||
function isTime(dataPoint) { | ||
if (!dataPoint) { | ||
return false; | ||
} // only support time string in ISO_8601 format: https://www.w3.org/TR/NOTE-datetime | ||
return typeof dataPoint === 'string' ? _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint, _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default.a.ISO_8601, true).isValid() : _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint).isValid(); | ||
if (!dataPoint) { | ||
return false; | ||
} | ||
// only support time string in following format: https://www.w3.org/TR/NOTE-datetime | ||
const supportedDateFormats = [ | ||
'YYYY-MM-DD', | ||
moment_1.default.ISO_8601, | ||
'YYYY-MM-DDTHH:mm', | ||
'YYYY-MM-DDTHH:mm:ss.SSS', | ||
'YYYY-MM-DDTHH:mm:ss', | ||
'YYYY-MM-DD HH:MM', | ||
'YYYY-MM-DD HH:MM:SS', | ||
'YYYY-MM-DD HH:MM:SS.SSS', | ||
]; | ||
return typeof dataPoint === 'string' | ||
? moment_1.default(dataPoint, supportedDateFormats, true).isValid() | ||
: moment_1.default(dataPoint).isValid(); | ||
} | ||
exports.isTime = isTime; | ||
/** | ||
@@ -527,6 +539,6 @@ * returns OK if data is string | ||
*/ | ||
function isString(dataPoint) { | ||
return typeof dataPoint === 'string'; | ||
return typeof dataPoint === 'string'; | ||
} | ||
exports.isString = isString; | ||
/** | ||
@@ -541,18 +553,26 @@ * getDataTypeForPoint | ||
*/ | ||
var getDataTypeForPoint = function getDataTypeForPoint(dataPoint) { | ||
if (lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default()(dataPoint)) { | ||
exports.getDataTypeForPoint = (dataPoint) => { | ||
if (Array.isArray(dataPoint)) { | ||
if (dataPoint.length > 1 && dataPoint[0] === '##__SPARKLINE__##') { | ||
return 'sparkline'; | ||
} | ||
return 'array'; | ||
} | ||
else if (lodash_1.isObject(dataPoint)) { | ||
return 'unknown'; | ||
} | ||
else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} | ||
else if (colorUtils_1.isColor(dataPoint)) { | ||
return 'color'; | ||
} | ||
else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} | ||
else if (isString(dataPoint)) { | ||
return 'string'; | ||
} | ||
// nulls, objects, etc | ||
return 'unknown'; | ||
} else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} else if (Object(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__["isColor"])(dataPoint)) { | ||
return 'color'; | ||
} else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} else if (isString(dataPoint)) { | ||
return 'string'; | ||
} // nulls, objects, etc | ||
return 'unknown'; | ||
}; | ||
@@ -567,23 +587,24 @@ /** | ||
*/ | ||
var inferDataTypeFromSample = function inferDataTypeFromSample(dataSample) { | ||
var typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0 | ||
}; | ||
dataSample.forEach(function (point) { | ||
return typeMatches[getDataTypeForPoint(point)] += 1; | ||
}); | ||
var typeCount = -1; | ||
var returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach(function (key) { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
exports.inferDataTypeFromSample = (dataSample) => { | ||
const typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0, | ||
array: 0, | ||
sparkline: 0, | ||
}; | ||
dataSample.forEach((point) => { | ||
typeMatches[exports.getDataTypeForPoint(point)] += 1; | ||
}); | ||
let typeCount = -1; | ||
let returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach((key) => { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
}; | ||
@@ -597,34 +618,31 @@ /** | ||
*/ | ||
var drawSample = function drawSample(data) { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} // small enough to check everything | ||
return data; | ||
exports.drawSample = (data) => { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} | ||
// small enough to check everything | ||
return data; | ||
}; | ||
/** | ||
* | ||
* @param {*} data | ||
*/ | ||
exports.inferDataTypeFromData = (data) => exports.inferDataTypeFromSample(exports.drawSample(data)); | ||
/***/ }), | ||
/* 8 */, | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isNumber"); | ||
/***/ }), | ||
/* 10 */ | ||
/* 7 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isFinite"); | ||
module.exports = require("@splunk/moment"); | ||
/***/ }), | ||
/* 11 */ | ||
/* 8 */, | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isObject"); | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
@@ -631,0 +649,0 @@ /***/ }) |
@@ -90,3 +90,3 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 35); | ||
/******/ return __webpack_require__(__webpack_require__.s = 33); | ||
/******/ }) | ||
@@ -96,3 +96,3 @@ /************************************************************************/ | ||
/***/ 35: | ||
/***/ 33: | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -99,0 +99,0 @@ |
@@ -90,3 +90,3 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 15); | ||
/******/ return __webpack_require__(__webpack_require__.s = 11); | ||
/******/ }) | ||
@@ -96,3 +96,3 @@ /************************************************************************/ | ||
/***/ 15: | ||
/***/ 11: | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -103,4 +103,4 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const nearley_1 = __webpack_require__(17); | ||
const grammar = __webpack_require__(18); | ||
const nearley_1 = __webpack_require__(14); | ||
const grammar = __webpack_require__(15); | ||
class DslParser { | ||
@@ -124,3 +124,3 @@ static parse(dsl) { | ||
/***/ 17: | ||
/***/ 14: | ||
/***/ (function(module, exports) { | ||
@@ -132,6 +132,6 @@ | ||
/***/ 18: | ||
/***/ 15: | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var _toConsumableArray = __webpack_require__(19); | ||
var _toConsumableArray = __webpack_require__(16); | ||
@@ -823,3 +823,3 @@ // Generated automatically by nearley, version 2.19.5 | ||
/***/ 19: | ||
/***/ 16: | ||
/***/ (function(module, exports) { | ||
@@ -826,0 +826,0 @@ |
@@ -90,3 +90,3 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 36); | ||
/******/ return __webpack_require__(__webpack_require__.s = 34); | ||
/******/ }) | ||
@@ -96,3 +96,3 @@ /************************************************************************/ | ||
/***/ 36: | ||
/***/ 34: | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -99,0 +99,0 @@ |
@@ -90,3 +90,3 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 37); | ||
/******/ return __webpack_require__(__webpack_require__.s = 35); | ||
/******/ }) | ||
@@ -96,3 +96,3 @@ /************************************************************************/ | ||
/***/ 37: | ||
/***/ 35: | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -103,3 +103,3 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const T = __webpack_require__(38); | ||
const T = __webpack_require__(36); | ||
/** | ||
@@ -148,3 +148,3 @@ * data point | ||
/***/ 38: | ||
/***/ 36: | ||
/***/ (function(module, exports) { | ||
@@ -151,0 +151,0 @@ |
@@ -90,8 +90,18 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 21); | ||
/******/ return __webpack_require__(__webpack_require__.s = 18); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ({ | ||
/***/ 15: | ||
/******/ ([ | ||
/* 0 */, | ||
/* 1 */, | ||
/* 2 */, | ||
/* 3 */, | ||
/* 4 */, | ||
/* 5 */, | ||
/* 6 */, | ||
/* 7 */, | ||
/* 8 */, | ||
/* 9 */, | ||
/* 10 */, | ||
/* 11 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -102,4 +112,4 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const nearley_1 = __webpack_require__(17); | ||
const grammar = __webpack_require__(18); | ||
const nearley_1 = __webpack_require__(14); | ||
const grammar = __webpack_require__(15); | ||
class DslParser { | ||
@@ -122,4 +132,5 @@ static parse(dsl) { | ||
/***/ }), | ||
/***/ 17: | ||
/* 12 */, | ||
/* 13 */, | ||
/* 14 */ | ||
/***/ (function(module, exports) { | ||
@@ -130,7 +141,6 @@ | ||
/***/ }), | ||
/***/ 18: | ||
/* 15 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var _toConsumableArray = __webpack_require__(19); | ||
var _toConsumableArray = __webpack_require__(16); | ||
@@ -821,4 +831,3 @@ // Generated automatically by nearley, version 2.19.5 | ||
/***/ }), | ||
/***/ 19: | ||
/* 16 */ | ||
/***/ (function(module, exports) { | ||
@@ -829,4 +838,4 @@ | ||
/***/ }), | ||
/***/ 21: | ||
/* 17 */, | ||
/* 18 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -837,3 +846,3 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const DslParser_1 = __webpack_require__(15); | ||
const DslParser_1 = __webpack_require__(11); | ||
class EncodingParser { | ||
@@ -891,4 +900,3 @@ static parseOptions(optionsStanza) { | ||
/***/ }) | ||
/******/ }); | ||
/******/ ]); | ||
//# sourceMappingURL=EncodingParser.js.map |
@@ -90,3 +90,3 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 39); | ||
/******/ return __webpack_require__(__webpack_require__.s = 37); | ||
/******/ }) | ||
@@ -96,3 +96,3 @@ /************************************************************************/ | ||
/***/ 39: | ||
/***/ 37: | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -99,0 +99,0 @@ |
470
Formatter.js
@@ -100,3 +100,3 @@ /*! | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const TypeSafeValue_1 = __webpack_require__(6); | ||
const TypeSafeValue_1 = __webpack_require__(4); | ||
/** | ||
@@ -139,3 +139,3 @@ * Base DataPoint class and associated DataPoint selectors | ||
getRawValue() { | ||
return this.value.value; | ||
return this.value.toRawValue(); | ||
} | ||
@@ -159,3 +159,3 @@ /** | ||
module.exports = require("@splunk/moment"); | ||
module.exports = require("lodash"); | ||
@@ -341,6 +341,143 @@ /***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const colorUtils_1 = __webpack_require__(9); | ||
const types_1 = __webpack_require__(6); | ||
const moment_1 = __webpack_require__(7); | ||
/** | ||
* @implements {TypedValue} | ||
* TypeSafeValue implements the TypedValue interface, and adds additional methods 'isOk' which can be used to determine | ||
* if the value was properly coerced into the expected type. When isOk is false, it means that coerced value cannot | ||
* be relied upon. For example, if the type is 'time' but isOk is false, it is possible that the coerced value could be NaN. | ||
* A field named originalValue can be used for user-facing error messages in situations where isOk is false. For example: | ||
* "'cat' was not an OK value for a 'time' field". This class's fields are all immutable. | ||
*/ | ||
class TypeSafeValue { | ||
constructor(type, value, isOk, originalValue) { | ||
/** | ||
* isTypeSafe. This is a marker field. The presence of this field can be used at runtime to determine if TypedValue is rigorous, | ||
* loose. Loose TypedValue such as {type:'number', value:'cat'} are handy for testing, but can lie. Obviously 'cat' | ||
* is not a number. If the isTypeSafe field is present then the instance is a TypeSafeValue | ||
* @type {boolean} | ||
*/ | ||
this.isTypeSafe = true; | ||
/** | ||
* isOk. This field tells if the original value passed into this's constructor honored its type contract. | ||
* @type {boolean} | ||
*/ | ||
this.isOk = true; | ||
this.type = type; | ||
this.value = value; | ||
this.isOk = isOk; | ||
this.originalValue = originalValue; | ||
} | ||
/** | ||
* returns a TypeSafeValue, either by converting the non TypeSafeValue to | ||
* a TypeSafeValue, or by simply returning the passed-in TypeSafeValue | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {TypeSafeValue<T>} | ||
*/ | ||
static from(typedValue) { | ||
if (typedValue.isTypeSafe) { | ||
return typedValue; // just return what was passed in since it is already TypeSafeValue | ||
} | ||
else { | ||
const { value: originalValue, type } = typedValue; | ||
const [value, isOk] = TypeSafeValue.coerceValue(typedValue); | ||
return new TypeSafeValue(type, value, isOk, originalValue); | ||
} | ||
} | ||
/** | ||
* Creates a TypeSafeValue from a raw value | ||
* @param value | ||
* @returns {TypeSafeValue<DataType>} | ||
*/ | ||
static fromRaw(value) { | ||
const type = types_1.getDataTypeForPoint(value); | ||
return new TypeSafeValue(type, value, true, value); | ||
} | ||
/** | ||
* attempts to coerce the provided value to the provided type. Returns tuple | ||
* of the coerced value and a boolean telling if the coercion was clean (true) | ||
* or if the coercion was likely produced an unusable result, such as NaN for | ||
* a number, or '' for a color. | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {[any, boolean]} | ||
*/ | ||
static coerceValue(typedValue) { | ||
const { type, value } = typedValue; | ||
let coercedVal = null; | ||
let isOk; | ||
let acceptableType = true; | ||
try { | ||
switch (type) { | ||
case 'number': { | ||
isOk = types_1.isNumber(value); | ||
coercedVal = Number(value); | ||
break; | ||
} | ||
case 'time': { | ||
isOk = types_1.isTime(value); | ||
if (value instanceof Date) { | ||
coercedVal = value; | ||
} | ||
else { | ||
// for case like `VM-203`, It will be convereted to a Date. | ||
coercedVal = isOk ? new Date(value) : 'Invalid Date'; | ||
} | ||
break; | ||
} | ||
case 'string': { | ||
isOk = types_1.isString(value); | ||
coercedVal = value.toString(); | ||
break; | ||
} | ||
case 'color': { | ||
isOk = colorUtils_1.isColor(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
case 'sparkline': { | ||
isOk = Array.isArray(value) && value[0] === '##__SPARKLINE__##'; | ||
coercedVal = value; | ||
break; | ||
} | ||
case 'array': { | ||
isOk = Array.isArray(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
default: { | ||
acceptableType = false; | ||
} | ||
} | ||
} | ||
catch (e) { | ||
isOk = false; | ||
} | ||
if (!acceptableType) { | ||
throw new Error(`unknown type: '${type}'`); | ||
} | ||
return [coercedVal, isOk]; | ||
} | ||
toRawValue() { | ||
switch (this.type) { | ||
case 'time': | ||
return moment_1.default(this.value).format(); | ||
case 'sparkline': | ||
case 'array': | ||
case 'number': | ||
case 'string': | ||
case 'color': | ||
default: | ||
return this.value; | ||
} | ||
} | ||
} | ||
exports.TypeSafeValue = TypeSafeValue; | ||
/***/ }), | ||
@@ -355,3 +492,3 @@ /* 5 */ | ||
const DataSeries_1 = __webpack_require__(3); | ||
const types_1 = __webpack_require__(7); | ||
const types_1 = __webpack_require__(6); | ||
/** | ||
@@ -392,3 +529,3 @@ * Base DataFrame class and associated DataFrame selectors | ||
let dataPoints = []; | ||
const dataType = types_1.inferDataTypeFromSample(types_1.drawSample(data)); | ||
const dataType = types_1.inferDataTypeFromData(data); | ||
let field = fields[idx]; | ||
@@ -399,3 +536,3 @@ if (field.name) { | ||
} | ||
data.forEach(value => { | ||
data.forEach((value) => { | ||
dataPoints.push(new DataPoint_1.DataPoint(field, { value: value, type: dataType })); | ||
@@ -433,3 +570,3 @@ }); | ||
const indexedSeries = []; | ||
indexes.forEach(index => { | ||
indexes.forEach((index) => { | ||
const ds = this.series[index]; // should we allow negative indexes? | ||
@@ -469,3 +606,3 @@ if (ds != null) { | ||
const namedSeries = []; | ||
names.forEach(name => { | ||
names.forEach((name) => { | ||
const found = this.seriesByName(name); | ||
@@ -493,3 +630,3 @@ found && namedSeries.push(found); | ||
seriesByName(field) { | ||
return this.series.find(dataSeries => field === dataSeries.field); | ||
return this.series.find((dataSeries) => field === dataSeries.field); | ||
} | ||
@@ -505,3 +642,3 @@ /** | ||
// fixme todo ...what do we do about 'mixed mode' columns? | ||
dataSeries => dataSeries.points.some(dataPoint => type === dataPoint.getValue().type)); | ||
(dataSeries) => dataSeries.points.some((dataPoint) => type === dataPoint.getValue().type)); | ||
} | ||
@@ -514,3 +651,3 @@ /** | ||
setValue(v) { | ||
this.series.forEach(s => s.setValue(v)); | ||
this.series.forEach((s) => s.setValue(v)); | ||
} | ||
@@ -524,3 +661,3 @@ /** | ||
const values = []; | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
values.push(s.getRawValue()); | ||
@@ -537,3 +674,3 @@ }); | ||
const values = []; | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
values.push(s.getValue()); | ||
@@ -549,3 +686,3 @@ }); | ||
getField() { | ||
const points = this.series.map(s => s.getField()); | ||
const points = this.series.map((s) => s.getField()); | ||
return new DataSeries_1.DataSeries(points); | ||
@@ -577,3 +714,3 @@ } | ||
const overallSeries = new DataSeries_1.DataSeries(); | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
const m = s[funcName](); | ||
@@ -595,142 +732,6 @@ m && overallSeries.points.push(m); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const colorUtils_1 = __webpack_require__(4); | ||
const types_1 = __webpack_require__(7); | ||
const moment_1 = __webpack_require__(7); | ||
const lodash_1 = __webpack_require__(2); | ||
const colorUtils_1 = __webpack_require__(9); | ||
/** | ||
* @implements {TypedValue} | ||
* TypeSafeValue implements the TypedValue interface, and adds additional methods 'isOk' which can be used to determine | ||
* if the value was properly coerced into the expected type. When isOk is false, it means that coerced value cannot | ||
* be relied upon. For example, if the type is 'time' but isOk is false, it is possible that the coerced value could be NaN. | ||
* A field named originalValue can be used for user-facing error messages in situations where isOk is false. For example: | ||
* "'cat' was not an OK value for a 'time' field". This class's fields are all immutable. | ||
*/ | ||
class TypeSafeValue { | ||
constructor(type, value, isOk, originalValue) { | ||
/** | ||
* isTypeSafe. This is a marker field. The presence of this field can be used at runtime to determine if TypedValue is rigorous, | ||
* loose. Loose TypedValue such as {type:'number', value:'cat'} are handy for testing, but can lie. Obviously 'cat' | ||
* is not a number. If the isTypeSafe field is present then the instance is a TypeSafeValue | ||
* @type {boolean} | ||
*/ | ||
this.isTypeSafe = true; | ||
/** | ||
* isOk. This field tells if the original value passed into this's constructor honored its type contract. | ||
* @type {boolean} | ||
*/ | ||
this.isOk = true; | ||
this.type = type; | ||
this.value = value; | ||
this.isOk = isOk; | ||
this.originalValue = originalValue; | ||
} | ||
/** | ||
* returns a TypeSafeValue, either by converting the non TypeSafeValue to | ||
* a TypeSafeValue, or by simply returning the passed-in TypeSafeValue | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {TypeSafeValue<T>} | ||
*/ | ||
static from(typedValue) { | ||
if (typedValue.isTypeSafe) { | ||
return typedValue; // just return what was passed in since it is already TypeSafeValue | ||
} | ||
else { | ||
const { value: originalValue, type } = typedValue; | ||
const [value, isOk] = TypeSafeValue.coerceValue(typedValue); | ||
return new TypeSafeValue(type, value, isOk, originalValue); | ||
} | ||
} | ||
/** | ||
* Creates a TypeSafeValue from a raw value | ||
* @param value | ||
* @returns {TypeSafeValue<DataType>} | ||
*/ | ||
static fromRaw(value) { | ||
const type = types_1.getDataTypeForPoint(value); | ||
return new TypeSafeValue(type, value, true, value); | ||
} | ||
/** | ||
* attempts to coerce the provided value to the provided type. Returns tuple | ||
* of the coerced value and a boolean telling if the coercion was clean (true) | ||
* or if the coercion was likely produced an unusable result, such as NaN for | ||
* a number, or '' for a color. | ||
* @param {TypedValue<T>} typedValue | ||
* @returns {[any, boolean]} | ||
*/ | ||
static coerceValue(typedValue) { | ||
const { type, value } = typedValue; | ||
let coercedVal = null; | ||
let isOk; | ||
let acceptableType = true; | ||
try { | ||
switch (type) { | ||
case 'number': { | ||
isOk = types_1.isNumber(value); | ||
coercedVal = Number(value); | ||
break; | ||
} | ||
case 'time': { | ||
isOk = types_1.isTime(value); | ||
if (value instanceof Date) { | ||
coercedVal = value; | ||
} | ||
else { | ||
// for case like `VM-203`, It will be convereted to a Date. | ||
coercedVal = isOk ? new Date(value) : 'Invalid Date'; | ||
} | ||
break; | ||
} | ||
case 'string': { | ||
isOk = types_1.isString(value); | ||
coercedVal = value.toString(); | ||
break; | ||
} | ||
case 'color': { | ||
isOk = colorUtils_1.isColor(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
default: { | ||
acceptableType = false; | ||
} | ||
} | ||
} | ||
catch (e) { | ||
isOk = false; | ||
} | ||
if (!acceptableType) { | ||
throw new Error(`unknown type: '${type}'`); | ||
} | ||
return [coercedVal, isOk]; | ||
} | ||
} | ||
exports.TypeSafeValue = TypeSafeValue; | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isNumber", function() { return isNumber; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isTime", function() { return isTime; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isString", function() { return isString; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDataTypeForPoint", function() { return getDataTypeForPoint; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "inferDataTypeFromSample", function() { return inferDataTypeFromSample; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drawSample", function() { return drawSample; }); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(10); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_isObject__WEBPACK_IMPORTED_MODULE_2__); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_splunk_moment__WEBPACK_IMPORTED_MODULE_3__); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__); | ||
/** | ||
* returns true if this dataPoint is a finite number | ||
@@ -740,6 +741,6 @@ * @param dataPoint | ||
*/ | ||
function isNumber(dataPoint) { | ||
return lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default()(+dataPoint) && lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default()(+dataPoint); | ||
return lodash_1.isFinite(+dataPoint) && lodash_1.isNumber(+dataPoint); | ||
} | ||
exports.isNumber = isNumber; | ||
/** | ||
@@ -750,11 +751,22 @@ *returns OK if data is time | ||
*/ | ||
function isTime(dataPoint) { | ||
if (!dataPoint) { | ||
return false; | ||
} // only support time string in ISO_8601 format: https://www.w3.org/TR/NOTE-datetime | ||
return typeof dataPoint === 'string' ? _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint, _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default.a.ISO_8601, true).isValid() : _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint).isValid(); | ||
if (!dataPoint) { | ||
return false; | ||
} | ||
// only support time string in following format: https://www.w3.org/TR/NOTE-datetime | ||
const supportedDateFormats = [ | ||
'YYYY-MM-DD', | ||
moment_1.default.ISO_8601, | ||
'YYYY-MM-DDTHH:mm', | ||
'YYYY-MM-DDTHH:mm:ss.SSS', | ||
'YYYY-MM-DDTHH:mm:ss', | ||
'YYYY-MM-DD HH:MM', | ||
'YYYY-MM-DD HH:MM:SS', | ||
'YYYY-MM-DD HH:MM:SS.SSS', | ||
]; | ||
return typeof dataPoint === 'string' | ||
? moment_1.default(dataPoint, supportedDateFormats, true).isValid() | ||
: moment_1.default(dataPoint).isValid(); | ||
} | ||
exports.isTime = isTime; | ||
/** | ||
@@ -765,6 +777,6 @@ * returns OK if data is string | ||
*/ | ||
function isString(dataPoint) { | ||
return typeof dataPoint === 'string'; | ||
return typeof dataPoint === 'string'; | ||
} | ||
exports.isString = isString; | ||
/** | ||
@@ -779,18 +791,26 @@ * getDataTypeForPoint | ||
*/ | ||
var getDataTypeForPoint = function getDataTypeForPoint(dataPoint) { | ||
if (lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default()(dataPoint)) { | ||
exports.getDataTypeForPoint = (dataPoint) => { | ||
if (Array.isArray(dataPoint)) { | ||
if (dataPoint.length > 1 && dataPoint[0] === '##__SPARKLINE__##') { | ||
return 'sparkline'; | ||
} | ||
return 'array'; | ||
} | ||
else if (lodash_1.isObject(dataPoint)) { | ||
return 'unknown'; | ||
} | ||
else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} | ||
else if (colorUtils_1.isColor(dataPoint)) { | ||
return 'color'; | ||
} | ||
else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} | ||
else if (isString(dataPoint)) { | ||
return 'string'; | ||
} | ||
// nulls, objects, etc | ||
return 'unknown'; | ||
} else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} else if (Object(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__["isColor"])(dataPoint)) { | ||
return 'color'; | ||
} else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} else if (isString(dataPoint)) { | ||
return 'string'; | ||
} // nulls, objects, etc | ||
return 'unknown'; | ||
}; | ||
@@ -805,23 +825,24 @@ /** | ||
*/ | ||
var inferDataTypeFromSample = function inferDataTypeFromSample(dataSample) { | ||
var typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0 | ||
}; | ||
dataSample.forEach(function (point) { | ||
return typeMatches[getDataTypeForPoint(point)] += 1; | ||
}); | ||
var typeCount = -1; | ||
var returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach(function (key) { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
exports.inferDataTypeFromSample = (dataSample) => { | ||
const typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0, | ||
array: 0, | ||
sparkline: 0, | ||
}; | ||
dataSample.forEach((point) => { | ||
typeMatches[exports.getDataTypeForPoint(point)] += 1; | ||
}); | ||
let typeCount = -1; | ||
let returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach((key) => { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
}; | ||
@@ -835,16 +856,25 @@ /** | ||
*/ | ||
exports.drawSample = (data) => { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} | ||
// small enough to check everything | ||
return data; | ||
}; | ||
/** | ||
* | ||
* @param {*} data | ||
*/ | ||
exports.inferDataTypeFromData = (data) => exports.inferDataTypeFromSample(exports.drawSample(data)); | ||
var drawSample = function drawSample(data) { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} // small enough to check everything | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("@splunk/moment"); | ||
return data; | ||
}; | ||
/***/ }), | ||
@@ -907,18 +937,6 @@ /* 8 */ | ||
module.exports = require("lodash/isNumber"); | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
/***/ }), | ||
/* 10 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isFinite"); | ||
/***/ }), | ||
/* 11 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isObject"); | ||
/***/ }) | ||
/******/ ]); | ||
//# sourceMappingURL=Formatter.js.map |
@@ -90,3 +90,3 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 17); | ||
/******/ return __webpack_require__(__webpack_require__.s = 14); | ||
/******/ }) | ||
@@ -140,3 +140,3 @@ /************************************************************************/ | ||
getRawValue() { | ||
return this.value.value; | ||
return this.value.toRawValue(); | ||
} | ||
@@ -157,53 +157,6 @@ /** | ||
/* 2 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ (function(module, exports) { | ||
"use strict"; | ||
module.exports = require("lodash"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const DataFrame_1 = __webpack_require__(4); | ||
const DataSeries_1 = __webpack_require__(3); | ||
const DataPoint_1 = __webpack_require__(1); | ||
class AbstractFormatter { | ||
format(dataPrimitive) { | ||
if (dataPrimitive instanceof DataFrame_1.DataFrame) { | ||
const newSeries = []; | ||
dataPrimitive.series.forEach((dataSeries, i) => { | ||
newSeries.push(this.formatSeries(dataSeries, i)); | ||
}); | ||
return new DataFrame_1.DataFrame(newSeries); | ||
} | ||
else if (dataPrimitive instanceof DataSeries_1.DataSeries) { | ||
return this.formatSeries(dataPrimitive); | ||
} | ||
else { | ||
return this.formatPoint(dataPrimitive); | ||
} | ||
} | ||
formatSeries(s, i = 0) { | ||
const newPoints = []; | ||
s.points.forEach((dataPoint, j) => { | ||
newPoints.push(this.formatPoint(dataPoint, s, i, j)); | ||
}); | ||
return new DataSeries_1.DataSeries(newPoints); // new DataSeries must have the type of the formatter's output | ||
} | ||
formatPoint(p, s, i = 0, j = 0) { | ||
const { field } = p; | ||
const tmp = this.formatTypedValue(p, s, i, j); | ||
return new DataPoint_1.DataPoint(field, tmp); | ||
} | ||
makeArrays2D(a) { | ||
if (Array.isArray(a)) { | ||
if (Array.isArray(a[0])) { | ||
return a; | ||
} | ||
else { | ||
return [a]; | ||
} | ||
} | ||
throw new Error("argument wasn't array"); | ||
} | ||
} | ||
exports.AbstractFormatter = AbstractFormatter; | ||
/***/ }), | ||
@@ -393,5 +346,58 @@ /* 3 */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const DataFrame_1 = __webpack_require__(5); | ||
const DataSeries_1 = __webpack_require__(3); | ||
const DataPoint_1 = __webpack_require__(1); | ||
class AbstractFormatter { | ||
format(dataPrimitive) { | ||
if (dataPrimitive instanceof DataFrame_1.DataFrame) { | ||
const newSeries = []; | ||
dataPrimitive.series.forEach((dataSeries, i) => { | ||
newSeries.push(this.formatSeries(dataSeries, i)); | ||
}); | ||
return new DataFrame_1.DataFrame(newSeries); | ||
} | ||
else if (dataPrimitive instanceof DataSeries_1.DataSeries) { | ||
return this.formatSeries(dataPrimitive); | ||
} | ||
else { | ||
return this.formatPoint(dataPrimitive); | ||
} | ||
} | ||
formatSeries(s, i = 0) { | ||
const newPoints = []; | ||
s.points.forEach((dataPoint, j) => { | ||
newPoints.push(this.formatPoint(dataPoint, s, i, j)); | ||
}); | ||
return new DataSeries_1.DataSeries(newPoints); // new DataSeries must have the type of the formatter's output | ||
} | ||
formatPoint(p, s, i = 0, j = 0) { | ||
const { field } = p; | ||
const tmp = this.formatTypedValue(p, s, i, j); | ||
return new DataPoint_1.DataPoint(field, tmp); | ||
} | ||
makeArrays2D(a) { | ||
if (Array.isArray(a)) { | ||
if (Array.isArray(a[0])) { | ||
return a; | ||
} | ||
else { | ||
return [a]; | ||
} | ||
} | ||
throw new Error("argument wasn't array"); | ||
} | ||
} | ||
exports.AbstractFormatter = AbstractFormatter; | ||
/***/ }), | ||
/* 5 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const DataPoint_1 = __webpack_require__(1); | ||
const DataSeries_1 = __webpack_require__(3); | ||
const types_1 = __webpack_require__(8); | ||
const types_1 = __webpack_require__(7); | ||
/** | ||
@@ -432,3 +438,3 @@ * Base DataFrame class and associated DataFrame selectors | ||
let dataPoints = []; | ||
const dataType = types_1.inferDataTypeFromSample(types_1.drawSample(data)); | ||
const dataType = types_1.inferDataTypeFromData(data); | ||
let field = fields[idx]; | ||
@@ -439,3 +445,3 @@ if (field.name) { | ||
} | ||
data.forEach(value => { | ||
data.forEach((value) => { | ||
dataPoints.push(new DataPoint_1.DataPoint(field, { value: value, type: dataType })); | ||
@@ -473,3 +479,3 @@ }); | ||
const indexedSeries = []; | ||
indexes.forEach(index => { | ||
indexes.forEach((index) => { | ||
const ds = this.series[index]; // should we allow negative indexes? | ||
@@ -509,3 +515,3 @@ if (ds != null) { | ||
const namedSeries = []; | ||
names.forEach(name => { | ||
names.forEach((name) => { | ||
const found = this.seriesByName(name); | ||
@@ -533,3 +539,3 @@ found && namedSeries.push(found); | ||
seriesByName(field) { | ||
return this.series.find(dataSeries => field === dataSeries.field); | ||
return this.series.find((dataSeries) => field === dataSeries.field); | ||
} | ||
@@ -545,3 +551,3 @@ /** | ||
// fixme todo ...what do we do about 'mixed mode' columns? | ||
dataSeries => dataSeries.points.some(dataPoint => type === dataPoint.getValue().type)); | ||
(dataSeries) => dataSeries.points.some((dataPoint) => type === dataPoint.getValue().type)); | ||
} | ||
@@ -554,3 +560,3 @@ /** | ||
setValue(v) { | ||
this.series.forEach(s => s.setValue(v)); | ||
this.series.forEach((s) => s.setValue(v)); | ||
} | ||
@@ -564,3 +570,3 @@ /** | ||
const values = []; | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
values.push(s.getRawValue()); | ||
@@ -577,3 +583,3 @@ }); | ||
const values = []; | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
values.push(s.getValue()); | ||
@@ -589,3 +595,3 @@ }); | ||
getField() { | ||
const points = this.series.map(s => s.getField()); | ||
const points = this.series.map((s) => s.getField()); | ||
return new DataSeries_1.DataSeries(points); | ||
@@ -617,3 +623,3 @@ } | ||
const overallSeries = new DataSeries_1.DataSeries(); | ||
this.series.forEach(s => { | ||
this.series.forEach((s) => { | ||
const m = s[funcName](); | ||
@@ -629,3 +635,2 @@ m && overallSeries.points.push(m); | ||
/***/ }), | ||
/* 5 */, | ||
/* 6 */ | ||
@@ -638,3 +643,4 @@ /***/ (function(module, exports, __webpack_require__) { | ||
const colorUtils_1 = __webpack_require__(11); | ||
const types_1 = __webpack_require__(8); | ||
const types_1 = __webpack_require__(7); | ||
const moment_1 = __webpack_require__(8); | ||
/** | ||
@@ -733,2 +739,12 @@ * @implements {TypedValue} | ||
} | ||
case 'sparkline': { | ||
isOk = Array.isArray(value) && value[0] === '##__SPARKLINE__##'; | ||
coercedVal = value; | ||
break; | ||
} | ||
case 'array': { | ||
isOk = Array.isArray(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
default: { | ||
@@ -747,2 +763,15 @@ acceptableType = false; | ||
} | ||
toRawValue() { | ||
switch (this.type) { | ||
case 'time': | ||
return moment_1.default(this.value).format(); | ||
case 'sparkline': | ||
case 'array': | ||
case 'number': | ||
case 'string': | ||
case 'color': | ||
default: | ||
return this.value; | ||
} | ||
} | ||
} | ||
@@ -754,33 +783,10 @@ exports.TypeSafeValue = TypeSafeValue; | ||
/* 7 */ | ||
/***/ (function(module, exports) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
module.exports = require("@splunk/moment"); | ||
/***/ }), | ||
/* 8 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isNumber", function() { return isNumber; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isTime", function() { return isTime; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isString", function() { return isString; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDataTypeForPoint", function() { return getDataTypeForPoint; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "inferDataTypeFromSample", function() { return inferDataTypeFromSample; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drawSample", function() { return drawSample; }); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(12); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(13); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(14); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_isObject__WEBPACK_IMPORTED_MODULE_2__); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(7); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_splunk_moment__WEBPACK_IMPORTED_MODULE_3__); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(11); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const moment_1 = __webpack_require__(8); | ||
const lodash_1 = __webpack_require__(2); | ||
const colorUtils_1 = __webpack_require__(11); | ||
/** | ||
@@ -791,6 +797,6 @@ * returns true if this dataPoint is a finite number | ||
*/ | ||
function isNumber(dataPoint) { | ||
return lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default()(+dataPoint) && lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default()(+dataPoint); | ||
return lodash_1.isFinite(+dataPoint) && lodash_1.isNumber(+dataPoint); | ||
} | ||
exports.isNumber = isNumber; | ||
/** | ||
@@ -801,11 +807,22 @@ *returns OK if data is time | ||
*/ | ||
function isTime(dataPoint) { | ||
if (!dataPoint) { | ||
return false; | ||
} // only support time string in ISO_8601 format: https://www.w3.org/TR/NOTE-datetime | ||
return typeof dataPoint === 'string' ? _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint, _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default.a.ISO_8601, true).isValid() : _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint).isValid(); | ||
if (!dataPoint) { | ||
return false; | ||
} | ||
// only support time string in following format: https://www.w3.org/TR/NOTE-datetime | ||
const supportedDateFormats = [ | ||
'YYYY-MM-DD', | ||
moment_1.default.ISO_8601, | ||
'YYYY-MM-DDTHH:mm', | ||
'YYYY-MM-DDTHH:mm:ss.SSS', | ||
'YYYY-MM-DDTHH:mm:ss', | ||
'YYYY-MM-DD HH:MM', | ||
'YYYY-MM-DD HH:MM:SS', | ||
'YYYY-MM-DD HH:MM:SS.SSS', | ||
]; | ||
return typeof dataPoint === 'string' | ||
? moment_1.default(dataPoint, supportedDateFormats, true).isValid() | ||
: moment_1.default(dataPoint).isValid(); | ||
} | ||
exports.isTime = isTime; | ||
/** | ||
@@ -816,6 +833,6 @@ * returns OK if data is string | ||
*/ | ||
function isString(dataPoint) { | ||
return typeof dataPoint === 'string'; | ||
return typeof dataPoint === 'string'; | ||
} | ||
exports.isString = isString; | ||
/** | ||
@@ -830,18 +847,26 @@ * getDataTypeForPoint | ||
*/ | ||
var getDataTypeForPoint = function getDataTypeForPoint(dataPoint) { | ||
if (lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default()(dataPoint)) { | ||
exports.getDataTypeForPoint = (dataPoint) => { | ||
if (Array.isArray(dataPoint)) { | ||
if (dataPoint.length > 1 && dataPoint[0] === '##__SPARKLINE__##') { | ||
return 'sparkline'; | ||
} | ||
return 'array'; | ||
} | ||
else if (lodash_1.isObject(dataPoint)) { | ||
return 'unknown'; | ||
} | ||
else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} | ||
else if (colorUtils_1.isColor(dataPoint)) { | ||
return 'color'; | ||
} | ||
else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} | ||
else if (isString(dataPoint)) { | ||
return 'string'; | ||
} | ||
// nulls, objects, etc | ||
return 'unknown'; | ||
} else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} else if (Object(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__["isColor"])(dataPoint)) { | ||
return 'color'; | ||
} else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} else if (isString(dataPoint)) { | ||
return 'string'; | ||
} // nulls, objects, etc | ||
return 'unknown'; | ||
}; | ||
@@ -856,23 +881,24 @@ /** | ||
*/ | ||
var inferDataTypeFromSample = function inferDataTypeFromSample(dataSample) { | ||
var typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0 | ||
}; | ||
dataSample.forEach(function (point) { | ||
return typeMatches[getDataTypeForPoint(point)] += 1; | ||
}); | ||
var typeCount = -1; | ||
var returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach(function (key) { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
exports.inferDataTypeFromSample = (dataSample) => { | ||
const typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0, | ||
array: 0, | ||
sparkline: 0, | ||
}; | ||
dataSample.forEach((point) => { | ||
typeMatches[exports.getDataTypeForPoint(point)] += 1; | ||
}); | ||
let typeCount = -1; | ||
let returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach((key) => { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
}; | ||
@@ -886,16 +912,25 @@ /** | ||
*/ | ||
exports.drawSample = (data) => { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} | ||
// small enough to check everything | ||
return data; | ||
}; | ||
/** | ||
* | ||
* @param {*} data | ||
*/ | ||
exports.inferDataTypeFromData = (data) => exports.inferDataTypeFromSample(exports.drawSample(data)); | ||
var drawSample = function drawSample(data) { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} // small enough to check everything | ||
/***/ }), | ||
/* 8 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("@splunk/moment"); | ||
return data; | ||
}; | ||
/***/ }), | ||
@@ -910,23 +945,5 @@ /* 9 */, | ||
/***/ }), | ||
/* 12 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isNumber"); | ||
/***/ }), | ||
/* 13 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isFinite"); | ||
/***/ }), | ||
/* 12 */, | ||
/* 13 */, | ||
/* 14 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isObject"); | ||
/***/ }), | ||
/* 15 */, | ||
/* 16 */, | ||
/* 17 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -937,3 +954,3 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Formatter_1 = __webpack_require__(2); | ||
const Formatter_1 = __webpack_require__(4); | ||
const TypeSafeValue_1 = __webpack_require__(6); | ||
@@ -961,3 +978,3 @@ /** | ||
class Type extends Formatter_1.AbstractFormatter { | ||
formatTypedValue(p, s) { | ||
formatTypedValue(p) { | ||
return TypeSafeValue_1.TypeSafeValue.fromRaw(p.getValue().type); | ||
@@ -964,0 +981,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Splunk", | ||
"version": "20.3.0", | ||
"version": "20.4.0", | ||
"scripts": { | ||
@@ -20,3 +20,3 @@ "build": "NODE_ENV=production webpack --config ./webpack.config.js --bail", | ||
"lint:ci": "yarn run eslint:ci", | ||
"lint:ts": "eslint . --ext \".ts,.tsx\" --config ./.tslintrc.js --no-eslintrc", | ||
"lint:ts": "eslint . --ext \".ts,.tsx\" --config ../../.tslintrc.js --no-eslintrc", | ||
"publish:ci": "cicd-publish-package", | ||
@@ -35,3 +35,5 @@ "test:unit": "jest src/.*", | ||
"jexl": "^2.2.2", | ||
"lodash": "4.17.20", | ||
"nearley": "^2.19.1", | ||
"numbro": "2.3.1", | ||
"prop-types": "^15.7.2" | ||
@@ -46,5 +48,5 @@ }, | ||
"@splunk/react-docs": "^0.7.0", | ||
"@splunk/visualization-build-tools": "^20.3.0", | ||
"@splunk/visualization-themes": "^20.3.0", | ||
"@splunk/visualizations-shared": "^20.3.0", | ||
"@splunk/visualization-build-tools": "^20.4.0", | ||
"@splunk/visualization-themes": "^20.4.0", | ||
"@splunk/visualizations-shared": "^20.4.0", | ||
"@splunk/webpack-configs": "^4.0.0", | ||
@@ -51,0 +53,0 @@ "@types/jest": "^25.1.4", |
@@ -90,3 +90,3 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 41); | ||
/******/ return __webpack_require__(__webpack_require__.s = 39); | ||
/******/ }) | ||
@@ -96,3 +96,3 @@ /************************************************************************/ | ||
/***/ 41: | ||
/***/ 39: | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -103,3 +103,3 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const helper_1 = __webpack_require__(42); | ||
const helper_1 = __webpack_require__(40); | ||
exports.expr0 = { type: 'identifier', v: 'WOPR' }; | ||
@@ -309,3 +309,3 @@ exports.expr1 = { | ||
/***/ 42: | ||
/***/ 40: | ||
/***/ (function(module, exports) { | ||
@@ -312,0 +312,0 @@ |
@@ -90,3 +90,3 @@ /*! | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 6); | ||
/******/ return __webpack_require__(__webpack_require__.s = 4); | ||
/******/ }) | ||
@@ -100,3 +100,3 @@ /************************************************************************/ | ||
module.exports = require("@splunk/moment"); | ||
module.exports = require("lodash"); | ||
@@ -106,9 +106,2 @@ /***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
/***/ }), | ||
/* 5 */, | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -119,4 +112,5 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const colorUtils_1 = __webpack_require__(4); | ||
const types_1 = __webpack_require__(7); | ||
const colorUtils_1 = __webpack_require__(9); | ||
const types_1 = __webpack_require__(6); | ||
const moment_1 = __webpack_require__(7); | ||
/** | ||
@@ -215,2 +209,12 @@ * @implements {TypedValue} | ||
} | ||
case 'sparkline': { | ||
isOk = Array.isArray(value) && value[0] === '##__SPARKLINE__##'; | ||
coercedVal = value; | ||
break; | ||
} | ||
case 'array': { | ||
isOk = Array.isArray(value); | ||
coercedVal = value; | ||
break; | ||
} | ||
default: { | ||
@@ -229,2 +233,15 @@ acceptableType = false; | ||
} | ||
toRawValue() { | ||
switch (this.type) { | ||
case 'time': | ||
return moment_1.default(this.value).format(); | ||
case 'sparkline': | ||
case 'array': | ||
case 'number': | ||
case 'string': | ||
case 'color': | ||
default: | ||
return this.value; | ||
} | ||
} | ||
} | ||
@@ -235,28 +252,12 @@ exports.TypeSafeValue = TypeSafeValue; | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/* 5 */, | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isNumber", function() { return isNumber; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isTime", function() { return isTime; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isString", function() { return isString; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDataTypeForPoint", function() { return getDataTypeForPoint; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "inferDataTypeFromSample", function() { return inferDataTypeFromSample; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drawSample", function() { return drawSample; }); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9); | ||
/* harmony import */ var lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_isNumber__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(10); | ||
/* harmony import */ var lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_isFinite__WEBPACK_IMPORTED_MODULE_1__); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11); | ||
/* harmony import */ var lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_isObject__WEBPACK_IMPORTED_MODULE_2__); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2); | ||
/* harmony import */ var _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_splunk_moment__WEBPACK_IMPORTED_MODULE_3__); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4); | ||
/* harmony import */ var _splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const moment_1 = __webpack_require__(7); | ||
const lodash_1 = __webpack_require__(2); | ||
const colorUtils_1 = __webpack_require__(9); | ||
/** | ||
@@ -267,6 +268,6 @@ * returns true if this dataPoint is a finite number | ||
*/ | ||
function isNumber(dataPoint) { | ||
return lodash_isFinite__WEBPACK_IMPORTED_MODULE_1___default()(+dataPoint) && lodash_isNumber__WEBPACK_IMPORTED_MODULE_0___default()(+dataPoint); | ||
return lodash_1.isFinite(+dataPoint) && lodash_1.isNumber(+dataPoint); | ||
} | ||
exports.isNumber = isNumber; | ||
/** | ||
@@ -277,11 +278,22 @@ *returns OK if data is time | ||
*/ | ||
function isTime(dataPoint) { | ||
if (!dataPoint) { | ||
return false; | ||
} // only support time string in ISO_8601 format: https://www.w3.org/TR/NOTE-datetime | ||
return typeof dataPoint === 'string' ? _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint, _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default.a.ISO_8601, true).isValid() : _splunk_moment__WEBPACK_IMPORTED_MODULE_3___default()(dataPoint).isValid(); | ||
if (!dataPoint) { | ||
return false; | ||
} | ||
// only support time string in following format: https://www.w3.org/TR/NOTE-datetime | ||
const supportedDateFormats = [ | ||
'YYYY-MM-DD', | ||
moment_1.default.ISO_8601, | ||
'YYYY-MM-DDTHH:mm', | ||
'YYYY-MM-DDTHH:mm:ss.SSS', | ||
'YYYY-MM-DDTHH:mm:ss', | ||
'YYYY-MM-DD HH:MM', | ||
'YYYY-MM-DD HH:MM:SS', | ||
'YYYY-MM-DD HH:MM:SS.SSS', | ||
]; | ||
return typeof dataPoint === 'string' | ||
? moment_1.default(dataPoint, supportedDateFormats, true).isValid() | ||
: moment_1.default(dataPoint).isValid(); | ||
} | ||
exports.isTime = isTime; | ||
/** | ||
@@ -292,6 +304,6 @@ * returns OK if data is string | ||
*/ | ||
function isString(dataPoint) { | ||
return typeof dataPoint === 'string'; | ||
return typeof dataPoint === 'string'; | ||
} | ||
exports.isString = isString; | ||
/** | ||
@@ -306,18 +318,26 @@ * getDataTypeForPoint | ||
*/ | ||
var getDataTypeForPoint = function getDataTypeForPoint(dataPoint) { | ||
if (lodash_isObject__WEBPACK_IMPORTED_MODULE_2___default()(dataPoint)) { | ||
exports.getDataTypeForPoint = (dataPoint) => { | ||
if (Array.isArray(dataPoint)) { | ||
if (dataPoint.length > 1 && dataPoint[0] === '##__SPARKLINE__##') { | ||
return 'sparkline'; | ||
} | ||
return 'array'; | ||
} | ||
else if (lodash_1.isObject(dataPoint)) { | ||
return 'unknown'; | ||
} | ||
else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} | ||
else if (colorUtils_1.isColor(dataPoint)) { | ||
return 'color'; | ||
} | ||
else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} | ||
else if (isString(dataPoint)) { | ||
return 'string'; | ||
} | ||
// nulls, objects, etc | ||
return 'unknown'; | ||
} else if (isNumber(dataPoint)) { | ||
return 'number'; | ||
} else if (Object(_splunk_visualizations_shared_colorUtils__WEBPACK_IMPORTED_MODULE_4__["isColor"])(dataPoint)) { | ||
return 'color'; | ||
} else if (isTime(dataPoint)) { | ||
return 'time'; | ||
} else if (isString(dataPoint)) { | ||
return 'string'; | ||
} // nulls, objects, etc | ||
return 'unknown'; | ||
}; | ||
@@ -332,23 +352,24 @@ /** | ||
*/ | ||
var inferDataTypeFromSample = function inferDataTypeFromSample(dataSample) { | ||
var typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0 | ||
}; | ||
dataSample.forEach(function (point) { | ||
return typeMatches[getDataTypeForPoint(point)] += 1; | ||
}); | ||
var typeCount = -1; | ||
var returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach(function (key) { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
exports.inferDataTypeFromSample = (dataSample) => { | ||
const typeMatches = { | ||
time: 0, | ||
number: 0, | ||
string: 0, | ||
color: 0, | ||
unknown: 0, | ||
array: 0, | ||
sparkline: 0, | ||
}; | ||
dataSample.forEach((point) => { | ||
typeMatches[exports.getDataTypeForPoint(point)] += 1; | ||
}); | ||
let typeCount = -1; | ||
let returnType = 'unknown'; | ||
Object.keys(typeMatches).forEach((key) => { | ||
if (typeMatches[key] > typeCount) { | ||
typeCount = typeMatches[key]; | ||
returnType = key; | ||
} | ||
}); | ||
return returnType; | ||
}; | ||
@@ -362,34 +383,31 @@ /** | ||
*/ | ||
var drawSample = function drawSample(data) { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} // small enough to check everything | ||
return data; | ||
exports.drawSample = (data) => { | ||
if (data.length > 2) { | ||
return [data[0], data[Math.floor(data.length / 2)], data[data.length - 1]]; | ||
} | ||
if (data.length === 2) { | ||
return [data[0], data[1]]; | ||
} | ||
// small enough to check everything | ||
return data; | ||
}; | ||
/** | ||
* | ||
* @param {*} data | ||
*/ | ||
exports.inferDataTypeFromData = (data) => exports.inferDataTypeFromSample(exports.drawSample(data)); | ||
/***/ }), | ||
/* 8 */, | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isNumber"); | ||
/***/ }), | ||
/* 10 */ | ||
/* 7 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isFinite"); | ||
module.exports = require("@splunk/moment"); | ||
/***/ }), | ||
/* 11 */ | ||
/* 8 */, | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isObject"); | ||
module.exports = require("@splunk/visualizations-shared/colorUtils"); | ||
@@ -396,0 +414,0 @@ /***/ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4922086
9
52340
+ Addedlodash@4.17.20
+ Addednumbro@2.3.1
+ Addedbignumber.js@8.1.1(transitive)
+ Addedlodash@4.17.20(transitive)
+ Addednumbro@2.3.1(transitive)