@kusto/language-service
Version:
Azure Data Explorer (a.k.a Kusto) language service for javascript (legacy code)
798 lines (740 loc) • 2.11 MB
JavaScript
/**
* @version 1.0.0.0
* @author Microsoft
* @copyright © Microsoft Corporation. All rights reserved.
* @compiler Bridge.NET 17.10.1
*/
Bridge.assembly("Kusto.JavaScript.Client", function ($asm, globals) {
"use strict";
Bridge.define("Kusto.Charting.AnomalyDataHelper2", {
statics: {
props: {
TimestampColumnName: null,
ValueColumnName: null,
SeriesColumnName: null,
AnomalySerieSuffix: null
},
ctors: {
init: function () {
this.TimestampColumnName = "Timestamp";
this.ValueColumnName = "Value";
this.SeriesColumnName = "Series";
this.AnomalySerieSuffix = "(anomaly)";
}
},
methods: {
EnchanceDataWithAnomalyDataFromServiceAsync: function (kustoContext, data) {
var $step = 0,
$task1,
$taskResult1,
$jumpFromFinally,
$tcs = new System.Threading.Tasks.TaskCompletionSource(),
$returnValue,
res,
dataAsCsl,
query,
results,
$t,
$async_e,
$asyncBody = Bridge.fn.bind(this, function () {
try {
for (;;) {
$step = System.Array.min([0,1], $step);
switch ($step) {
case 0: {
res = new Kusto.Charting.AnomalyDataHelper2.AnomalyDataFromServiceResult();
if (kustoContext == null) {
res.Data = data;
res.HasErrors = true;
res.Message = "Failed sending the request for anomalies to the service";
$tcs.setResult(res);
return;
}
dataAsCsl = Kusto.Charting.AnomalyDataHelper2.DataItemsToDataTableLiteral(data);
query = (dataAsCsl || "") + (System.String.format("| summarize dt = makelist({0}, 100000), y=makelist({1}, 100000) by {2}\r\n| extend (anomalies, scores, baseline)=series_decompose_anomalies(y)\r\n| project dt, y, anomalies, Series\r\n| mvexpand dt to typeof(datetime), y to typeof(double), anomalies to typeof(double) limit 1000000\r\n| where anomalies != 0\r\n| project dt, anomaly_value = (anomalies * anomalies)*y, Series", Kusto.Charting.AnomalyDataHelper2.TimestampColumnName, Kusto.Charting.AnomalyDataHelper2.ValueColumnName, Kusto.Charting.AnomalyDataHelper2.SeriesColumnName) || "");
if (System.Text.Encoding.UTF8.GetByteCount$2(query) > 2000000) {
res.Data = data;
res.HasErrors = true;
res.Message = "The anomalies request to the service exceeds the 2MB limit, consider adding more filters";
$tcs.setResult(res);
return;
}
$task1 = kustoContext.Kusto$Charting$IKustoClientContext$ExecuteQueryAsync(Kusto.Charting.AnomalyDataHelper2.AnomalyInputOutputRecord, query);
$step = 1;
if ($task1.isCompleted()) {
continue;
}
$task1.continue($asyncBody);
return;
}
case 1: {
$taskResult1 = $task1.getAwaitedResult();
results = $taskResult1;
results = ($t = Kusto.Charting.AnomalyDataHelper2.AnomalyInputOutputRecord, System.Linq.Enumerable.from(results, $t).ToArray($t));
if (results == null || !System.Linq.Enumerable.from(results, Kusto.Charting.AnomalyDataHelper2.AnomalyInputOutputRecord).any()) {
res.Data = data;
res.HasErrors = true;
res.Message = "Failed retrieving the anomalies result from the service";
$tcs.setResult(res);
return;
}
// Translate anomaly results back to the data points
data.AddRange(System.Linq.Enumerable.from(results, Kusto.Charting.AnomalyDataHelper2.AnomalyInputOutputRecord).select($asm.$.Kusto.Charting.AnomalyDataHelper2.f1));
res.Data = data;
res.HasErrors = false;
res.Message = "";
$tcs.setResult(res);
return;
}
default: {
$tcs.setResult(null);
return;
}
}
}
} catch($async_e1) {
$async_e = System.Exception.create($async_e1);
$tcs.setException($async_e);
}
}, arguments);
$asyncBody();
return $tcs.task;
},
DataItemsToDataTableLiteral: function (items) {
var $t;
var result = new System.Text.StringBuilder();
result.append("datatable");
result.appendLine(System.String.format("({0}:datetime,{1}:double,{2}:string)", Kusto.Charting.AnomalyDataHelper2.TimestampColumnName, Kusto.Charting.AnomalyDataHelper2.ValueColumnName, Kusto.Charting.AnomalyDataHelper2.SeriesColumnName));
result.append("[");
$t = Bridge.getEnumerator(items, Kusto.Charting.DataItem);
try {
while ($t.moveNext()) {
var item = $t.Current;
result.append("datetime(");
result.append(System.DateTime.format(item.ArgumentDateTime, "o"));
result.append("),");
result.append("double("); //needed for negative values
result.append(System.Double.format(item.ValueData));
result.append("),");
var seriesName = Kusto.Cloud.Platform.Text.StringLiteral.GetLiteral(item.SeriesName);
result.append(seriesName);
result.appendLine(",");
}
} finally {
if (Bridge.is($t, System.IDisposable)) {
$t.System$IDisposable$Dispose();
}
}
result.appendLine("]");
return result.toString();
},
EnchanceDataWithAnomalyDataFromColumns: function (data, yColumns, anomalyColumns, anomalySeriesMap) {
var $t;
anomalySeriesMap.v = new (System.Collections.Generic.Dictionary$2(System.String,System.String)).ctor();
var result = new (System.Collections.Generic.List$1(Kusto.Charting.DataItem)).ctor();
var anomalyColumnsHashset = new (System.Collections.Generic.HashSet$1(System.String)).$ctor1(anomalyColumns);
// Check how many value columns we have.
var valueColumns = yColumns;
if (Kusto.Cloud.Platform.Utils.ExtendedEnumerable.SafeFastNone$1(System.String, valueColumns)) {
valueColumns = System.Linq.Enumerable.from(data, Kusto.Charting.DataItem).where(function (d) {
return !anomalyColumnsHashset.contains(d.ValueName);
}).select($asm.$.Kusto.Charting.AnomalyDataHelper2.f2).distinct().ToArray(System.String);
}
if (valueColumns.length === 0) {
return data;
}
// Copy all data except anomalies
result.AddRange(System.Linq.Enumerable.from(data, Kusto.Charting.DataItem).where(function (d) {
return !anomalyColumnsHashset.contains(d.ValueName);
}));
for (var c = 0; c < anomalyColumns.length && c < valueColumns.length; c = (c + 1) | 0) {
var anomalyColumn = { v : anomalyColumns[System.Array.index(c, anomalyColumns)] };
var valueColumn = { v : c < valueColumns.length ? valueColumns[System.Array.index(c, valueColumns)] : System.Linq.Enumerable.from(valueColumns, System.String).last() };
var valueData = System.Linq.Enumerable.from(data, Kusto.Charting.DataItem).where((function ($me, valueColumn) {
return function (d) {
return System.String.equals(d.ValueName, valueColumn.v);
};
})(this, valueColumn)).ToArray(Kusto.Charting.DataItem);
var anomalyData = System.Linq.Enumerable.from(data, Kusto.Charting.DataItem).where((function ($me, anomalyColumn) {
return function (d) {
return System.String.equals(d.ValueName, anomalyColumn.v);
};
})(this, anomalyColumn)).ToArray(Kusto.Charting.DataItem);
if (valueData.length < anomalyData.length) {
// Streams of data are not of the same size - return
continue;
}
var anomalyPointsCount = 0;
for (var i = 0; i < anomalyData.length; i = (i + 1) | 0) {
var valuePoint = valueData[System.Array.index(i, valueData)];
var anomalyPoint = anomalyData[System.Array.index(i, anomalyData)];
// This is an anomaly
if (anomalyPoint.ValueData !== 0) {
anomalyPointsCount = (anomalyPointsCount + 1) | 0;
var seriesName = (anomalyPoint.SeriesName || "") + (Kusto.Charting.AnomalyDataHelper2.AnomalySerieSuffix || "");
var a = ($t = new Kusto.Charting.DataItem.ctor(), $t.ArgumentDateTime = anomalyPoint.ArgumentDateTime, $t.ArgumentData = anomalyPoint.ArgumentData, $t.SeriesName = seriesName, $t.ValueData = valuePoint.ValueData, $t.PrefferredChartKind = Kusto.Charting.ChartKind.Point, $t);
result.add(a);
if (!anomalySeriesMap.v.containsKey(seriesName)) {
anomalySeriesMap.v.add(seriesName, valuePoint.SeriesName);
}
}
}
//adding dummy point in order to display anomaly series in Legend, in case if there are no points to render
if (anomalyPointsCount === 0 && anomalyData.length > 0) {
var a1 = ($t = new Kusto.Charting.DataItem.ctor(), $t.ArgumentDateTime = anomalyData[System.Array.index(0, anomalyData)].ArgumentDateTime, $t.ArgumentData = null, $t.SeriesName = (anomalyData[System.Array.index(0, anomalyData)].SeriesName || "") + (Kusto.Charting.AnomalyDataHelper2.AnomalySerieSuffix || ""), $t.ValueData = Number.NaN, $t.PrefferredChartKind = Kusto.Charting.ChartKind.Point, $t);
result.add(a1);
}
}
return result;
}
}
}
});
Bridge.ns("Kusto.Charting.AnomalyDataHelper2", $asm.$);
Bridge.apply($asm.$.Kusto.Charting.AnomalyDataHelper2, {
f1: function (r) {
var $t1;
return ($t1 = new Kusto.Charting.DataItem.ctor(), $t1.ArgumentDateTime = r.Timestamp, $t1.ArgumentData = System.DateTime.format(r.Timestamp, "o"), $t1.SeriesName = (r.Series || "") + (Kusto.Charting.AnomalyDataHelper2.AnomalySerieSuffix || ""), $t1.ValueData = r.Value, $t1.PrefferredChartKind = Kusto.Charting.ChartKind.Point, $t1);
},
f2: function (d) {
return d.ValueName;
}
});
Bridge.define("Kusto.Charting.AnomalyDataHelper2.AnomalyDataFromServiceResult", {
$kind: "nested class",
fields: {
Data: null,
HasErrors: false,
Message: null
}
});
Bridge.define("Kusto.Charting.AnomalyDataHelper2.AnomalyInputOutputRecord", {
$kind: "nested class",
fields: {
Timestamp: null,
Value: 0,
Series: null
},
ctors: {
init: function () {
this.Timestamp = System.DateTime.getDefaultValue();
}
}
});
Bridge.define("Kusto.Charting.ArgumentColumnType", {
$kind: "enum",
statics: {
fields: {
None: 0,
Numeric: 2,
DateTime: 4,
TimeSpan: 8,
String: 16,
Object: 32,
Geospatial: 64,
DateTimeOrTimeSpan: 12,
StringOrDateTimeOrTimeSpan: 28,
NumericOrDateTimeOrTimeSpan: 14,
StringOrObject: 48,
AllExceptGeospatial: 62
}
},
$flags: true
});
Bridge.define("Kusto.Charting.ArgumentRestrictions", {
$kind: "enum",
statics: {
fields: {
/**
* No restrictiosn apply
*
* @static
* @public
* @memberof Kusto.Charting.ArgumentRestrictions
* @constant
* @default 0
* @type Kusto.Charting.ArgumentRestrictions
*/
None: 0,
/**
* Must find a valid argument
*
* @static
* @public
* @memberof Kusto.Charting.ArgumentRestrictions
* @constant
* @default 1
* @type Kusto.Charting.ArgumentRestrictions
*/
MustHave: 1,
/**
* Argument column used cannot appear also in series
*
* @static
* @public
* @memberof Kusto.Charting.ArgumentRestrictions
* @constant
* @default 2
* @type Kusto.Charting.ArgumentRestrictions
*/
NotIncludedInSeries: 2,
/**
* Try to locate an argument that allows geo-spatial types to appear in series
*
* @static
* @public
* @memberof Kusto.Charting.ArgumentRestrictions
* @constant
* @default 4
* @type Kusto.Charting.ArgumentRestrictions
*/
GeospatialAsSeries: 4,
/**
* Prefer picking last column that matches arguments restrictions
*
* @static
* @public
* @memberof Kusto.Charting.ArgumentRestrictions
* @constant
* @default 8
* @type Kusto.Charting.ArgumentRestrictions
*/
PreferLast: 8,
/**
* Try to locate an argument that allows numerics to appear in series
*
* @static
* @public
* @memberof Kusto.Charting.ArgumentRestrictions
* @constant
* @default 16
* @type Kusto.Charting.ArgumentRestrictions
*/
NumericAsSeries: 16
}
},
$flags: true
});
Bridge.define("Kusto.Charting.ChartKind", {
$kind: "enum",
statics: {
fields: {
Unspecified: 0,
Line: 1,
Point: 2,
Bar: 3
}
}
});
Bridge.define("Kusto.Charting.ChartLimitsPolicy", {
props: {
/**
* The maximal amount of points allowed for visualization on the chart
*
* @instance
* @public
* @memberof Kusto.Charting.ChartLimitsPolicy
* @function MaxPointsPerChartError
* @type number
*/
MaxPointsPerChartError: 0,
/**
* Amount of points above which required user's approvement to visualize chart
*
* @instance
* @public
* @memberof Kusto.Charting.ChartLimitsPolicy
* @function MaxPointsPerChartWarning
* @type number
*/
MaxPointsPerChartWarning: 0,
/**
* The maximal amount of series allowed for visualization on the chart
*
* @instance
* @public
* @memberof Kusto.Charting.ChartLimitsPolicy
* @function MaxSeriesPerChartError
* @type number
*/
MaxSeriesPerChartError: 0,
/**
* Amount of series above which required user's approvement to visualize chart
*
* @instance
* @public
* @memberof Kusto.Charting.ChartLimitsPolicy
* @function MaxSeriesPerChartWarning
* @type number
*/
MaxSeriesPerChartWarning: 0,
/**
* The maximal interval of DateTime argument allowed for visualization on the chart
*
* @instance
* @public
* @memberof Kusto.Charting.ChartLimitsPolicy
* @function MaxDatetimePeriodError
* @type System.TimeSpan
*/
MaxDatetimePeriodError: null,
ChartType: null
},
ctors: {
init: function () {
this.MaxDatetimePeriodError = new System.TimeSpan();
},
ctor: function (chartType, maxPointsPerChartError, maxPointsPerChartWarning, maxSeriesPerChartError, maxSeriesPerChartWarning, maxDatetimePeriodError) {
this.$initialize();
this.ChartType = chartType;
this.MaxPointsPerChartError = maxPointsPerChartError;
this.MaxPointsPerChartWarning = maxPointsPerChartWarning;
this.MaxSeriesPerChartError = maxSeriesPerChartError;
this.MaxSeriesPerChartWarning = maxSeriesPerChartWarning;
this.MaxDatetimePeriodError = maxDatetimePeriodError;
}
},
methods: {
Equals: function (other) {
if (other == null) {
return false;
}
return Bridge.referenceEquals(this.ChartType, other.ChartType) && this.MaxPointsPerChartError === other.MaxPointsPerChartError && this.MaxPointsPerChartWarning === other.MaxPointsPerChartWarning && this.MaxSeriesPerChartError === other.MaxSeriesPerChartError && this.MaxSeriesPerChartWarning === other.MaxSeriesPerChartWarning && System.TimeSpan.eq(this.MaxDatetimePeriodError, other.MaxDatetimePeriodError);
},
equals: function (obj) {
return this.Equals(Bridge.as(obj, Kusto.Charting.ChartLimitsPolicy));
},
getHashCode: function () {
return Bridge.getHashCode(this.ChartType) ^ this.MaxPointsPerChartError ^ this.MaxPointsPerChartWarning ^ this.MaxSeriesPerChartError ^ this.MaxSeriesPerChartWarning ^ Bridge.getHashCode(this.MaxDatetimePeriodError);
}
}
});
Bridge.define("Kusto.Charting.DataChartsHelper", {
statics: {
fields: {
c_minFractionOfIntervalsToDetectDistribution: 0,
c_minElementsAmountToFillGapsWithNans: 0,
c_decimalRoundingPrecision: 0,
c_doubleAcceptableApproximation: 0,
c_defaultArgumentNumeric: 0,
c_defaultArgumentString: null,
c_defaultArgumentDatetime: null
},
ctors: {
init: function () {
this.c_defaultArgumentDatetime = System.DateTime.getDefaultValue();
this.c_minFractionOfIntervalsToDetectDistribution = 0.8;
this.c_minElementsAmountToFillGapsWithNans = 4;
this.c_decimalRoundingPrecision = 8;
this.c_doubleAcceptableApproximation = 1E-08;
this.c_defaultArgumentNumeric = Number.NaN;
this.c_defaultArgumentString = "<empty>";
this.c_defaultArgumentDatetime = Bridge.getDefaultValue(System.DateTime);
}
},
methods: {
/**
* Generates set of a DataItem objects from provided structure,
based on required argument parameters(column type and restrictions).
Takes in account x-columns, y-columns and series if provided.
*
* @static
* @public
* @this Kusto.Charting.DataChartsHelper
* @memberof Kusto.Charting.DataChartsHelper
* @param {Kusto.Charting.IChartingDataSource} table Data source, which has to implement IChartingDataSource.
* @param {Kusto.Charting.ArgumentColumnType} argumentColumnType Required column type
* @param {Kusto.Charting.ArgumentRestrictions} argumentRestrictions Argument restrictions
* @param {System.Collections.Generic.IEnumerable$1} seriesColumns Optional. Names of columns to be considered as series.
* @param {boolean} accumulateResults Optional. Defines the necessity of accumulation in each DataItem values from the previous ones. Default - false.
* @param {string} xColumn Optional. Name of column to be considered as an argument.
* @param {System.Collections.Generic.IEnumerable$1} yColumns Optional. Names of columns to be considered as a function.
* @return {System.Collections.Generic.IEnumerable$1} Collection of DataItem objects.
*/
GetData: function (table, argumentColumnType, argumentRestrictions, seriesColumns, accumulateResults, xColumn, yColumns) {
if (argumentColumnType === void 0) { argumentColumnType = 16; }
if (argumentRestrictions === void 0) { argumentRestrictions = 0; }
if (seriesColumns === void 0) { seriesColumns = null; }
if (accumulateResults === void 0) { accumulateResults = false; }
if (xColumn === void 0) { xColumn = null; }
if (yColumns === void 0) { yColumns = null; }
var chartProps = Kusto.Charting.DataChartsHelper.GetMetaData(table, argumentColumnType, argumentRestrictions, seriesColumns, xColumn, yColumns);
return Kusto.Charting.DataChartsHelper.GetData$1(table, chartProps, accumulateResults);
},
/**
* Generates set of a DataItem objects from provided structure,
based on chart meta data
*
* @static
* @public
* @this Kusto.Charting.DataChartsHelper
* @memberof Kusto.Charting.DataChartsHelper
* @param {Kusto.Charting.IChartingDataSource} table Data source, which has to implement IChartingDataSource.
* @param {Kusto.Charting.IChartMetaData} metaData chart meta data (argument, series and data columns) for data generation
* @param {boolean} accumulateResults Optional. Defines the necessity of accumulation in each DataItem values from the previous ones. Default - false.
* @return {System.Collections.Generic.IEnumerable$1} Collection of DataItem objects.
*/
GetData$1: function (table, metaData, accumulateResults) {
if (accumulateResults === void 0) { accumulateResults = false; }
if (table == null || metaData == null) {
return System.Linq.Enumerable.empty();
}
var tableSchema = table.Kusto$Charting$IChartingDataSource$GetSchema();
// IN JS Enumeration are slow
// Special Contains and ElementAt
var allColumns = System.Linq.Enumerable.from(tableSchema, System.Tuple$2(System.String,Kusto.Charting.ArgumentColumnType)).select($asm.$.Kusto.Charting.DataChartsHelper.f1).toList(Kusto.Charting.DataChartsHelper.ColumnDesc);
var seriesList = System.Linq.Enumerable.from(metaData.Kusto$Charting$IChartMetaData$SeriesIndexes, System.Int32).any() ? System.Linq.Enumerable.from(allColumns, Kusto.Charting.DataChartsHelper.ColumnDesc).where(function (col) {
return System.Linq.Enumerable.from(metaData.Kusto$Charting$IChartMetaData$SeriesIndexes, System.Int32).contains(col.Index);
}).ToArray(Kusto.Charting.DataChartsHelper.ColumnDesc) : null;
var dataColumns = System.Linq.Enumerable.from(allColumns, Kusto.Charting.DataChartsHelper.ColumnDesc).where(function (col) {
return System.Linq.Enumerable.from(metaData.Kusto$Charting$IChartMetaData$DataIndexes, System.Int32).contains(col.Index);
}).ToArray(Kusto.Charting.DataChartsHelper.ColumnDesc);
var unusedColumns = System.Linq.Enumerable.from(allColumns, Kusto.Charting.DataChartsHelper.ColumnDesc).where(function (col) {
return System.Linq.Enumerable.from(metaData.Kusto$Charting$IChartMetaData$UnusedIndexes, System.Int32).contains(col.Index);
}).ToArray(Kusto.Charting.DataChartsHelper.ColumnDesc);
// pre building the list
var argumentData = new Kusto.Charting.DataChartsHelper.ArgumentData(metaData.Kusto$Charting$IChartMetaData$ArgumentDataColumnIndex, metaData.Kusto$Charting$IChartMetaData$ArgumentDataColumnIndex >= 0 ? allColumns.getItem(metaData.Kusto$Charting$IChartMetaData$ArgumentDataColumnIndex).Name : "", metaData.Kusto$Charting$IChartMetaData$ArgumentDataColumnIndex >= 0 ? System.Linq.Enumerable.from(tableSchema, System.Tuple$2(System.String,Kusto.Charting.ArgumentColumnType)).elementAt(metaData.Kusto$Charting$IChartMetaData$ArgumentDataColumnIndex).Item2 : Kusto.Charting.ArgumentColumnType.None, metaData.Kusto$Charting$IChartMetaData$ArgumentColumnType, metaData.Kusto$Charting$IChartMetaData$GeospatialColumnIndexes); // geospatial column indexes
var result = new (System.Collections.Generic.List$1(Kusto.Charting.DataItem)).ctor();
var lastValues = new (System.Collections.Generic.Dictionary$2(System.String,System.Double)).ctor();
for (var i = 0; i < table.Kusto$Charting$IChartingDataSource$RowsCount; i = (i + 1) | 0) {
var baseSeriesName = Kusto.Charting.DataChartsHelper.GetBaseSeriesName(table, seriesList, i);
if (!metaData.Kusto$Charting$IChartMetaData$IsDataFormedAsSeries) {
argumentData.ResolveArgumentFromRow(table, i);
Kusto.Charting.DataChartsHelper.ResolveDataItemsFromDataRow(result, table, dataColumns, unusedColumns, i, baseSeriesName, argumentData, lastValues, accumulateResults);
} else {
Kusto.Charting.DataChartsHelper.ResolveDataSeriesFromDataRow(result, table, dataColumns, unusedColumns, i, baseSeriesName, metaData.Kusto$Charting$IChartMetaData$ArgumentColumnType, accumulateResults, metaData.Kusto$Charting$IChartMetaData$ArgumentDataColumnIndex);
}
}
// Filter out series that all values are NaN
if (metaData.Kusto$Charting$IChartMetaData$ArgumentColumnType !== Kusto.Charting.ArgumentColumnType.Geospatial) {
result = Kusto.Charting.DataChartsHelper.RemoveNaNPointsIfNeeded(result, lastValues);
}
return result;
},
/**
* Figure out the chart meta data, which that will be used to generate the chart data
based on required argument parameters(column type and restrictions).
Takes in account x-columns, y-columns and series if provided.
*
* @static
* @public
* @this Kusto.Charting.DataChartsHelper
* @memberof Kusto.Charting.DataChartsHelper
* @param {Kusto.Charting.IChartingDataSource} table Data source, which has to implement IChartingDataSource.
* @param {Kusto.Charting.ArgumentColumnType} argumentColumnType Required column type
* @param {Kusto.Charting.ArgumentRestrictions} argumentRestrictions Argument restrictions
* @param {System.Collections.Generic.IEnumerable$1} seriesColumns Optional. Names of columns to be considered as series.
* @param {string} xColumn Optional. Name of column to be considered as an argument.
* @param {System.Collections.Generic.IEnumerable$1} yColumns Optional. Names of columns to be considered as a function.
* @return {Kusto.Charting.IChartMetaData} return the actual argument, series and data columns or null if fails
*/
GetMetaData: function (table, argumentColumnType, argumentRestrictions, seriesColumns, xColumn, yColumns) {
if (argumentColumnType === void 0) { argumentColumnType = 16; }
if (argumentRestrictions === void 0) { argumentRestrictions = 0; }
if (seriesColumns === void 0) { seriesColumns = null; }
if (xColumn === void 0) { xColumn = null; }
if (yColumns === void 0) { yColumns = null; }
var tableSchema = table.Kusto$Charting$IChartingDataSource$GetSchema();
if (tableSchema == null || !System.Linq.Enumerable.from(tableSchema, System.Tuple$2(System.String,Kusto.Charting.ArgumentColumnType)).any()) {
return null;
}
if (seriesColumns == null) {
seriesColumns = new (System.Collections.Generic.List$1(System.String)).ctor();
}
if (yColumns == null) {
yColumns = new (System.Collections.Generic.List$1(System.String)).ctor();
}
var metaData = { v : new Kusto.Charting.DataChartsHelper.ChartMetaData(argumentColumnType) };
Kusto.Charting.DataChartsHelper.ResolvePredefinedColumnsIndexes(table, seriesColumns, yColumns, xColumn, argumentRestrictions, metaData);
var isTableValidForCharting = false;
if (!metaData.v.IsDataFormedAsSeries) {
isTableValidForCharting = Kusto.Charting.DataChartsHelper.DetectChartDimensionsUsingColumnTypesAndData(tableSchema, table, argumentRestrictions, metaData);
metaData.v.IsDataFormedAsSeries = !isTableValidForCharting;
}
if (metaData.v.IsDataFormedAsSeries) {
isTableValidForCharting = Kusto.Charting.DataChartsHelper.DetectChartDimensionsUsingData(tableSchema, table, seriesColumns, argumentRestrictions, metaData);
}
if (!isTableValidForCharting) {
return null;
}
// Explode & Filter Data indexes
var tempDataIndex = metaData.v.DataIndexes;
metaData.v.DataIndexesList = System.Linq.Enumerable.from(tableSchema, System.Tuple$2(System.String,Kusto.Charting.ArgumentColumnType)).select(function (col, index) {
return (index !== metaData.v.ArgumentDataColumnIndex && !metaData.v.GeospatiaColumnlIndexesList.contains(index) && (!System.Linq.Enumerable.from(tempDataIndex, System.Int32).any() || System.Linq.Enumerable.from(tempDataIndex, System.Int32).contains(index)) && !System.Linq.Enumerable.from(metaData.v.SeriesIndexes, System.Int32).contains(index) && ((!metaData.v.IsDataFormedAsSeries && System.Enum.hasFlag(Kusto.Charting.ArgumentColumnType.NumericOrDateTimeOrTimeSpan, Bridge.box(col.Item2, Kusto.Charting.ArgumentColumnType, System.Enum.toStringFn(Kusto.Charting.ArgumentColumnType)))) || (metaData.v.IsDataFormedAsSeries && System.Enum.hasFlag(Kusto.Charting.ArgumentColumnType.StringOrObject, Bridge.box(col.Item2, Kusto.Charting.ArgumentColumnType, System.Enum.toStringFn(Kusto.Charting.ArgumentColumnType))))) ? index : -1);
}).where($asm.$.Kusto.Charting.DataChartsHelper.f2).toList(System.Int32);
if (metaData.v.ArgumentColumnType === Kusto.Charting.ArgumentColumnType.Geospatial) {
if (metaData.v.DataIndexesList.Count > 1) {
// in geospatial case, we want just the 1st data index, we can't afford to have more than one geo point just because the input rows has additional data index columns.
var firstDataIndex = System.Linq.Enumerable.from(metaData.v.DataIndexesList, System.Int32).first();
metaData.v.DataIndexesList.clear();
metaData.v.DataIndexesList.add(firstDataIndex);
}
if (argumentRestrictions === Kusto.Charting.ArgumentRestrictions.GeospatialAsSeries && (metaData.v.ArgumentDataColumnIndex === -1 || !System.Linq.Enumerable.from(metaData.v.DataIndexesList, System.Int32).any())) {
// not sufficient data for presenting map pie chart. Both ArgumentData and it's value are required, in addition to geo coordinates.
return null;
}
}
// Update unused indexes
metaData.v.UnusedIndexes = System.Linq.Enumerable.range(0, System.Linq.Enumerable.from(tableSchema, System.Tuple$2(System.String,Kusto.Charting.ArgumentColumnType)).count()).except(metaData.v.DataIndexes).except(metaData.v.GeospatialColumnIndexes).except(metaData.v.SeriesIndexes).except(System.Array.init([metaData.v.ArgumentDataColumnIndex], System.Int32)).toList(System.Int32);
return metaData.v;
},
RemoveNaNPointsIfNeeded: function (result, lastValues) {
var $t;
// JS doesn't have HashSets, so we're using dictionary.
var emptySeries = System.Linq.Enumerable.from(lastValues, System.Collections.Generic.KeyValuePair$2(System.String,System.Double)).where($asm.$.Kusto.Charting.DataChartsHelper.f3).toDictionary($asm.$.Kusto.Charting.DataChartsHelper.f4, $asm.$.Kusto.Charting.DataChartsHelper.f5, System.String, System.Boolean);
if (emptySeries.Count > 0) {
result = System.Linq.Enumerable.from(result, Kusto.Charting.DataItem).where(function (d) {
return !emptySeries.containsKey(d.SeriesName);
}).toList(Kusto.Charting.DataItem);
}
// Remove NaN points in case more than a half of points are NaN.
var seriesStatistics = new (System.Collections.Generic.Dictionary$2(System.String,Kusto.Charting.DataChartsHelper.SeriesStatsCounters)).ctor();
$t = Bridge.getEnumerator(result);
try {
while ($t.moveNext()) {
var r = $t.Current;
var stats = { };
if (!seriesStatistics.tryGetValue(r.SeriesName, stats)) {
stats.v = new Kusto.Charting.DataChartsHelper.SeriesStatsCounters();
}
stats.v.TotalPoints = stats.v.TotalPoints.inc();
if (Kusto.Charting.ExtendedDouble.IsFinite(r.ValueData)) {
stats.v.NonNanPoints = stats.v.NonNanPoints.inc();
}
seriesStatistics.setItem(r.SeriesName, stats.v);
}
} finally {
if (Bridge.is($t, System.IDisposable)) {
$t.System$IDisposable$Dispose();
}
}
var partialEmptySeries = System.Linq.Enumerable.from(seriesStatistics, System.Collections.Generic.KeyValuePair$2(System.String,Kusto.Charting.DataChartsHelper.SeriesStatsCounters)).where($asm.$.Kusto.Charting.DataChartsHelper.f6).toDictionary($asm.$.Kusto.Charting.DataChartsHelper.f4, $asm.$.Kusto.Charting.DataChartsHelper.f5, System.String, System.Boolean);
if (partialEmptySeries.Count > 0) {
result = System.Linq.Enumerable.from(result, Kusto.Charting.DataItem).where(function (r1) {
return !partialEmptySeries.containsKey(r1.SeriesName) || Kusto.Charting.ExtendedDouble.IsFinite(r1.ValueData);
}).toList(Kusto.Charting.DataItem);
}
return result;
},
/**
* Figure out the chart meta data, which that will be used to generate the chart data
for line-chart.
*
* @static
* @public
* @this Kusto.Charting.DataChartsHelper
* @memberof Kusto.Charting.DataChartsHelper
* @param {Kusto.Data.Utils.ChartVisualizationOptions} options
* @param {Kusto.Charting.IChartingDataSource} dataSource
* @param {System.Collections.Generic.List$1} data
* @param {Array.<string>} yColumnsToResolve
* @param {Kusto.Charting.ArgumentColumnType} argumentType
* @return {System.Collections.Generic.List$1}
*/
GetDataForLineChart: function (options, dataSource, data, yColumnsToResolve, argumentType) {
var $t, $t1;
var isTimechart = options.Visualization === Kusto.Data.Utils.VisualizationKind.TimeLineChart || options.Visualization === Kusto.Data.Utils.VisualizationKind.TimeLineWithAnomalyChart;
var isLinechart = options.Visualization === Kusto.Data.Utils.VisualizationKind.LineChart;
var isLikelyTimechart = options.Visualization === Kusto.Data.Utils.VisualizationKind.ScatterChart || options.Visualization === Kusto.Data.Utils.VisualizationKind.AreaChart || options.Visualization === Kusto.Data.Utils.VisualizationKind.StackedAreaChart;
var expectedArgTypes = null;
if (isTimechart) {
expectedArgTypes = System.Array.init([Kusto.Charting.ArgumentColumnType.DateTime, Kusto.Charting.ArgumentColumnType.TimeSpan], Kusto.Charting.ArgumentColumnType);
} else if (isLinechart) {
expectedArgTypes = System.Array.init([Kusto.Charting.ArgumentColumnType.Numeric, Kusto.Charting.ArgumentColumnType.DateTime, Kusto.Charting.ArgumentColumnType.TimeSpan], Kusto.Charting.ArgumentColumnType);
} else if (isLikelyTimechart) {
expectedArgTypes = System.Array.init([Kusto.Charting.ArgumentColumnType.DateTime, Kusto.Charting.ArgumentColumnType.TimeSpan, Kusto.Charting.ArgumentColumnType.Numeric], Kusto.Charting.ArgumentColumnType);
} else {
expectedArgTypes = System.Array.init([Kusto.Charting.ArgumentColumnType.Numeric, Kusto.Charting.ArgumentColumnType.DateTime, Kusto.Charting.ArgumentColumnType.TimeSpan], Kusto.Charting.ArgumentColumnType);
}
// Search for first data match
$t = Bridge.getEnumerator(expectedArgTypes);
try {
while ($t.moveNext()) {
var expectedArgType = $t.Current;
data = ($t1 = Kusto.Charting.DataItem, System.Linq.Enumerable.from(Kusto.Charting.DataChartsHelper.GetData(dataSource, expectedArgType, 18, options.Series, options.Accumulate, options.XColumn, yColumnsToResolve), $t1).toList($t1));
if (data != null && data.Count !== 0) {
break;
}
}
} finally {
if (Bridge.is($t, System.IDisposable)) {
$t.System$IDisposable$Dispose();
}
}
argumentType.v = Kusto.Charting.DataChartsHelper.ResolveArgumentType(data);
return data;
},
/**
* Detects if provided type is numeric.
*
* @static
* @public
* @this Kusto.Charting.DataChartsHelper
* @memberof Kusto.Charting.DataChartsHelper
* @param {System.Type} type Type to be analyzed.
* @param {boolean} considerDateTimeAndTimeSpanAsNumeric Optional. Defines if DateTime and TimeSpan should be considered as numeric.
Default - true.
* @return {boolean} True, if provided type is numreic, false - if not.
*/
IsNumericType: function (type, considerDateTimeAndTimeSpanAsNumeric) {
if (considerDateTimeAndTimeSpanAsNumeric === void 0) { considerDateTimeAndTimeSpanAsNumeric = true; }
if (type == null) {
return false;
} else if (Bridge.referenceEquals(type, System.TimeSpan) || Bridge.referenceEquals(type, System.DateTime)) {
return considerDateTimeAndTimeSpanAsNumeric;
} else if (Bridge.referenceEquals(type, System.Byte) || Bridge.referenceEquals(type, System.Decimal) || Bridge.referenceEquals(type, System.Double) || Bridge.referenceEquals(type, System.Int16) || Bridge.referenceEquals(type, System.Int32) || Bridge.referenceEquals(type, System.Int64) || Bridge.referenceEquals(type, System.SByte) || Bridge.referenceEquals(type, System.UInt16) || Bridge.referenceEquals(type, System.UInt32) || Bridge.referenceEquals(type, System.UInt64)) {
return true;
} else if (Bridge.referenceEquals(type, System.Object)) {
if (Bridge.Reflection.isGenericType(type) && Bridge.referenceEquals(Bridge.Reflection.getGenericTypeDefinition(type), System.Nullable$1)) {
return Kusto.Charting.DataChartsHelper.IsNumericType(System.Nullable.getUnderlyingType(type), considerDateTimeAndTimeSpanAsNumeric);
}
}
return false;
},
/**
* Returns names of columns, from provided data source, which which may be considered as an argument.
*
* @static
* @public
* @this Kusto.Charting.DataChartsHelper
* @memberof Kusto.Charting.DataChartsHelper
* @param {Kusto.Charting.IChartingDataSource} table Data source, which has to implement IChartingDataSource.
* @param {System.Collections.Generic.IEnumerable$1} columnsToExclude Optional. Columns to be excluded from detection.
* @return {System.Collections.Generic.IEnumerable$1} Collection of columns' names.
*/
GetAllArgumentColumns: function (table, columnsToExclude) {
if (columnsToExclude === void 0) { columnsToExclude = null; }
var result = new (System.Collections.Generic.List$1(System.String)).ctor();
var schema = table.Kusto$Charting$IChartingDataSource$GetSchema();
var n = System.Linq.Enumerable.from(table.Kusto$Charting$IChartingDataSource$GetSchema(), System.Tuple$2(System.String,Kusto.Charting.ArgumentColumnType)).count();
var columnsToExcludeDefined = columnsToExclude != null && System.Linq.Enumerable.from(columnsToExclude, System.String).any();
if (n > 1) {
for (var i = 0; i < n; i = (i + 1) | 0) {
var columnName = System.Linq.Enumerable.from(schema, System.Tuple$2(System.String,Kusto.Charting.ArgumentColumnType)).elementAt(i).Item1;
if (columnsToExcludeDefined && System.Linq.Enumerable.from(columnsToExclude, System.String).contains(columnName)) {
continue;
}
result.add(columnName);
}
}
return result;
},
/**
* Detects the first column of type string.
*
* @static
* @public
* @this Kusto.Charting.DataChartsHelper
* @memberof Kusto.Charting.DataChartsHelper
* @param {Kusto.Charting.IChartingDataSource} table Data source, which has to implement IChartingDataSource.
* @param {number} amountToSkip Amount of columns type string to be skipped
* @return {string} Name of first column of type string.
*/
GetFirstStringColumnName: function (table, amountToSkip) {
if (amountToSkip === void 0) { amountToSkip = 0; }
var schema = table.Kusto$Charting$IChartingDataSource$GetSchema();
var n = System.Linq.Enumerable.from(table.Kusto$Charting$IChartingDataSource$GetSchema(), System.Tuple$2(System.String,Kusto.Charting.ArgumentColumnType)).count();
for (var i = 0; i < n; i = (i + 1) | 0) {
if (System.Linq.Enumerable.from(schema, System.Tuple$2(System.String,Kusto.Charting.ArgumentColumnType)).elementAt(i).Item2 === Kusto.Charting.ArgumentColumnType.String) {
if (amountToSkip === 0) {
return System.Linq.Enumerable.from(schema, System.Tuple$2(System.String,Kusto.Charting.ArgumentColumnType)).elementAt(i).Item1;