@perses-dev/core 0.35.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants/dashboard-defaults.js +28 -0
- package/dist/cjs/constants/index.js +1 -0
- package/dist/cjs/model/calculations.js +1 -1
- package/dist/cjs/model/index.js +1 -0
- package/dist/cjs/model/legend.js +19 -2
- package/dist/cjs/model/units/bytes.js +84 -0
- package/dist/cjs/model/units/constants.js +23 -0
- package/dist/cjs/model/units/decimal.js +62 -0
- package/dist/cjs/model/units/index.js +31 -0
- package/dist/cjs/model/units/percent.js +73 -0
- package/dist/cjs/model/units/time.js +105 -0
- package/dist/cjs/model/units/types.js +28 -0
- package/dist/cjs/model/units/units.js +101 -0
- package/dist/cjs/model/units/utils.js +42 -0
- package/dist/cjs/model/variables.js +5 -0
- package/dist/constants/dashboard-defaults.d.ts +4 -0
- package/dist/constants/dashboard-defaults.d.ts.map +1 -0
- package/dist/constants/dashboard-defaults.js +16 -0
- package/dist/constants/dashboard-defaults.js.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +1 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/model/calculations.js +1 -1
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/dashboard.d.ts +1 -0
- package/dist/model/dashboard.d.ts.map +1 -1
- package/dist/model/dashboard.js.map +1 -1
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +5 -0
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +15 -1
- package/dist/model/legend.js.map +1 -1
- package/dist/model/thresholds.d.ts +4 -0
- package/dist/model/thresholds.d.ts.map +1 -1
- package/dist/model/thresholds.js.map +1 -1
- package/dist/model/units/bytes.d.ts +13 -0
- package/dist/model/units/bytes.d.ts.map +1 -0
- package/dist/model/units/bytes.js +66 -0
- package/dist/model/units/bytes.js.map +1 -0
- package/dist/model/units/constants.d.ts +2 -0
- package/dist/model/units/constants.d.ts.map +1 -0
- package/dist/model/units/constants.js +17 -0
- package/dist/model/units/constants.js.map +1 -0
- package/dist/model/units/decimal.d.ts +13 -0
- package/dist/model/units/decimal.d.ts.map +1 -0
- package/dist/model/units/decimal.js +49 -0
- package/dist/model/units/decimal.js.map +1 -0
- package/dist/model/units/index.d.ts +5 -0
- package/dist/model/units/index.d.ts.map +1 -0
- package/dist/model/units/index.js +18 -0
- package/dist/model/units/index.js.map +1 -0
- package/dist/model/units/percent.d.ts +12 -0
- package/dist/model/units/percent.d.ts.map +1 -0
- package/dist/model/units/percent.js +60 -0
- package/dist/model/units/percent.js.map +1 -0
- package/dist/model/units/time.d.ts +22 -0
- package/dist/model/units/time.d.ts.map +1 -0
- package/dist/model/units/time.js +91 -0
- package/dist/model/units/time.js.map +1 -0
- package/dist/model/units/types.d.ts +47 -0
- package/dist/model/units/types.d.ts.map +1 -0
- package/dist/model/units/types.js +22 -0
- package/dist/model/units/types.js.map +1 -0
- package/dist/model/units/units.d.ts +40 -0
- package/dist/model/units/units.d.ts.map +1 -0
- package/dist/model/units/units.js +80 -0
- package/dist/model/units/units.js.map +1 -0
- package/dist/model/units/utils.d.ts +4 -0
- package/dist/model/units/utils.d.ts.map +1 -0
- package/dist/model/units/utils.js +32 -0
- package/dist/model/units/utils.js.map +1 -0
- package/dist/model/variables.d.ts +1 -0
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js +1 -1
- package/dist/model/variables.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export const DEFAULT_DASHBOARD_DURATION = '1h';
|
|
14
|
+
export const DEFAULT_REFRESH_INTERVAL = '0s';
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=dashboard-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants/dashboard-defaults.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '../model';\n\nexport const DEFAULT_DASHBOARD_DURATION: DurationString = '1h';\n\nexport const DEFAULT_REFRESH_INTERVAL: DurationString = '0s';\n"],"names":["DEFAULT_DASHBOARD_DURATION","DEFAULT_REFRESH_INTERVAL"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,0BAA0B,GAAmB,IAAI,CAAC;AAE/D,OAAO,MAAMC,wBAAwB,GAAmB,IAAI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAaA,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC"}
|
package/dist/constants/index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
+
export * from './dashboard-defaults';
|
|
13
14
|
export * from './dialog';
|
|
14
15
|
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dialog';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/constants/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard-defaults';\nexport * from './dialog';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\nexport const CalculationsMap = {\n First: first,\n Last: last,\n FirstNumber: firstNumber,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n Min: min,\n Max: max,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n description: string;\n};\n\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n description: 'First value',\n },\n Last: {\n label: 'Last',\n description: 'Last value',\n },\n FirstNumber: {\n label: 'First *',\n description: 'First numeric value',\n },\n LastNumber: {\n label: 'Last *',\n description: 'Last numeric value',\n },\n Mean: {\n label: 'Average',\n description: 'Average value excluding nulls',\n },\n Sum: {\n label: 'Sum',\n description: 'The sum of all values',\n },\n Min: {\n label: 'Min',\n description: 'Minimum value',\n },\n Max: {\n label: 'Max',\n description: 'Maximum value',\n },\n} as const;\n\nexport const DEFAULT_CALCULATION: CalculationType = 'Sum';\n\ntype CalculationValue = number | null | undefined;\n\n/**\n * Calculate a multiple values for a set of time series data.\n *\n * @param values - Array of time series data.\n * @param includeCalculations - Array of calculations to include.\n */\nexport function getCalculations<IncludeCalcs extends CalculationType[]>(\n values: TimeSeriesValueTuple[],\n includeCalculations: IncludeCalcs\n): Record<\n // This extract combined with the generics above keeps the key of the returned\n // record to *just* the specified calculations.\n Extract<CalculationType, IncludeCalcs[number]>,\n CalculationValue\n> {\n const calculations = includeCalculations.reduce((initResult, calculation) => {\n initResult[calculation] = undefined;\n return initResult;\n }, {} as Record<string, CalculationValue>);\n\n // We save these values as separate values instead of directly setting them\n // in the calculations because they are needed by multiple calculations.\n let nonNullCount = 0;\n let sum = 0;\n\n // We use this large function capable of performing one or more calculations\n // in a single iteration of the data to minimize the performance impact of\n // generating multiple calculations for large timeseries values. This is\n // less optimized for certain single calculations when done in isolation (e.g.\n // `Last`), but will be more performant in the more expensive cases where\n // multiple values are being used (e.g. table legend).\n values.forEach((tuple, i) => {\n const value = tuple[1];\n\n if (i === 0 && 'First' in calculations) {\n calculations.First = value;\n }\n if (i === values.length - 1 && 'Last' in calculations) {\n calculations.Last = value;\n }\n\n // Handling specific to non-null values.\n if (typeof value === 'number') {\n nonNullCount += 1;\n sum += value;\n\n if ('FirstNumber' in calculations && calculations.FirstNumber === undefined) {\n // Save the first number we see.\n calculations.FirstNumber = value;\n }\n\n if ('LastNumber' in calculations) {\n // Keep setting the numbers we see, which will eventually be set to the\n // last number when finished iterating.\n calculations.LastNumber = value;\n }\n\n if ('Min' in calculations) {\n if (typeof calculations.Min !== 'number') {\n // Init the first time we see a number\n calculations.Min = value;\n } else {\n // Use lowest value once initialized\n calculations.Min = Math.min(calculations.Min, value);\n }\n }\n\n if ('Max' in calculations) {\n if (typeof calculations.Max !== 'number') {\n // Init the first time we see a number\n calculations.Max = value;\n } else {\n // Use highest value once initialized\n calculations.Max = Math.max(calculations.Max, value);\n }\n }\n }\n });\n\n // Set calculations that require iterating over all values.\n if (nonNullCount > 0 && 'Sum' in calculations) {\n calculations.Sum = sum;\n }\n\n if (nonNullCount > 0 && 'Mean' in calculations) {\n calculations.Mean = sum / nonNullCount;\n }\n\n return calculations;\n}\n\n/**\n * Calculate a single value for a set of time series data.\n *\n * Use `getCalculations` instead if you need multiple calculations.\n *\n * @param values - Array of time series data.\n * @param calculation - Name of the calculation to calculate.\n */\nexport function getCalculation(values: TimeSeriesValueTuple[], calculation: CalculationType) {\n return getCalculations(values, [calculation])[calculation];\n}\n\nfunction first(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'First');\n}\n\nfunction last(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Last');\n}\n\nfunction firstNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'FirstNumber');\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'LastNumber');\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Mean');\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Sum');\n}\n\nfunction min(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Min');\n}\n\nfunction max(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Max');\n}\n"],"names":["CalculationsMap","First","first","Last","last","FirstNumber","firstNumber","LastNumber","lastNumber","Mean","mean","Sum","sum","Min","min","Max","max","CALCULATIONS_CONFIG","label","description","DEFAULT_CALCULATION","getCalculations","values","includeCalculations","calculations","reduce","initResult","calculation","undefined","nonNullCount","forEach","tuple","i","value","length","Math","getCalculation"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,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WAAW,CAACgB,MAA8B,EAAoB;IACrE,OAAOc,cAAc,CAACd,MAAM,EAAE,aAAa,CAAC,CAAC;AAC/C,CAAC;AAED,SAASd,UAAU,CAACc,MAA8B,EAAoB;IACpE,OAAOc,cAAc,CAACd,MAAM,EAAE,YAAY,CAAC,CAAC;AAC9C,CAAC;AAED,SAASZ,IAAI,CAACY,MAA8B,EAAoB;IAC9D,OAAOc,cAAc,CAACd,MAAM,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,SAASV,GAAG,CAACU,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,SAASR,GAAG,CAACQ,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,SAASN,GAAG,CAACM,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\nexport const CalculationsMap = {\n First: first,\n Last: last,\n FirstNumber: firstNumber,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n Min: min,\n Max: max,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n description: string;\n};\n\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n description: 'First value',\n },\n Last: {\n label: 'Last',\n description: 'Last value',\n },\n FirstNumber: {\n label: 'First *',\n description: 'First numeric value',\n },\n LastNumber: {\n label: 'Last *',\n description: 'Last numeric value',\n },\n Mean: {\n label: 'Avg',\n description: 'Average value excluding nulls',\n },\n Sum: {\n label: 'Sum',\n description: 'The sum of all values',\n },\n Min: {\n label: 'Min',\n description: 'Minimum value',\n },\n Max: {\n label: 'Max',\n description: 'Maximum value',\n },\n} as const;\n\nexport const DEFAULT_CALCULATION: CalculationType = 'Sum';\n\ntype CalculationValue = number | null | undefined;\n\n/**\n * Calculate a multiple values for a set of time series data.\n *\n * @param values - Array of time series data.\n * @param includeCalculations - Array of calculations to include.\n */\nexport function getCalculations<IncludeCalcs extends CalculationType[]>(\n values: TimeSeriesValueTuple[],\n includeCalculations: IncludeCalcs\n): Record<\n // This extract combined with the generics above keeps the key of the returned\n // record to *just* the specified calculations.\n Extract<CalculationType, IncludeCalcs[number]>,\n CalculationValue\n> {\n const calculations = includeCalculations.reduce((initResult, calculation) => {\n initResult[calculation] = undefined;\n return initResult;\n }, {} as Record<string, CalculationValue>);\n\n // We save these values as separate values instead of directly setting them\n // in the calculations because they are needed by multiple calculations.\n let nonNullCount = 0;\n let sum = 0;\n\n // We use this large function capable of performing one or more calculations\n // in a single iteration of the data to minimize the performance impact of\n // generating multiple calculations for large timeseries values. This is\n // less optimized for certain single calculations when done in isolation (e.g.\n // `Last`), but will be more performant in the more expensive cases where\n // multiple values are being used (e.g. table legend).\n values.forEach((tuple, i) => {\n const value = tuple[1];\n\n if (i === 0 && 'First' in calculations) {\n calculations.First = value;\n }\n if (i === values.length - 1 && 'Last' in calculations) {\n calculations.Last = value;\n }\n\n // Handling specific to non-null values.\n if (typeof value === 'number') {\n nonNullCount += 1;\n sum += value;\n\n if ('FirstNumber' in calculations && calculations.FirstNumber === undefined) {\n // Save the first number we see.\n calculations.FirstNumber = value;\n }\n\n if ('LastNumber' in calculations) {\n // Keep setting the numbers we see, which will eventually be set to the\n // last number when finished iterating.\n calculations.LastNumber = value;\n }\n\n if ('Min' in calculations) {\n if (typeof calculations.Min !== 'number') {\n // Init the first time we see a number\n calculations.Min = value;\n } else {\n // Use lowest value once initialized\n calculations.Min = Math.min(calculations.Min, value);\n }\n }\n\n if ('Max' in calculations) {\n if (typeof calculations.Max !== 'number') {\n // Init the first time we see a number\n calculations.Max = value;\n } else {\n // Use highest value once initialized\n calculations.Max = Math.max(calculations.Max, value);\n }\n }\n }\n });\n\n // Set calculations that require iterating over all values.\n if (nonNullCount > 0 && 'Sum' in calculations) {\n calculations.Sum = sum;\n }\n\n if (nonNullCount > 0 && 'Mean' in calculations) {\n calculations.Mean = sum / nonNullCount;\n }\n\n return calculations;\n}\n\n/**\n * Calculate a single value for a set of time series data.\n *\n * Use `getCalculations` instead if you need multiple calculations.\n *\n * @param values - Array of time series data.\n * @param calculation - Name of the calculation to calculate.\n */\nexport function getCalculation(values: TimeSeriesValueTuple[], calculation: CalculationType) {\n return getCalculations(values, [calculation])[calculation];\n}\n\nfunction first(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'First');\n}\n\nfunction last(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Last');\n}\n\nfunction firstNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'FirstNumber');\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'LastNumber');\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Mean');\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Sum');\n}\n\nfunction min(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Min');\n}\n\nfunction max(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Max');\n}\n"],"names":["CalculationsMap","First","first","Last","last","FirstNumber","firstNumber","LastNumber","lastNumber","Mean","mean","Sum","sum","Min","min","Max","max","CALCULATIONS_CONFIG","label","description","DEFAULT_CALCULATION","getCalculations","values","includeCalculations","calculations","reduce","initResult","calculation","undefined","nonNullCount","forEach","tuple","i","value","length","Math","getCalculation"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,eAAe,GAAG;IAC7BC,KAAK,EAAEC,KAAK;IACZC,IAAI,EAAEC,IAAI;IACVC,WAAW,EAAEC,WAAW;IACxBC,UAAU,EAAEC,UAAU;IACtBC,IAAI,EAAEC,IAAI;IACVC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;CACT,CAAC;AASF,OAAO,MAAMC,mBAAmB,GAAyD;IACvFhB,KAAK,EAAE;QACLiB,KAAK,EAAE,OAAO;QACdC,WAAW,EAAE,aAAa;KAC3B;IACDhB,IAAI,EAAE;QACJe,KAAK,EAAE,MAAM;QACbC,WAAW,EAAE,YAAY;KAC1B;IACDd,WAAW,EAAE;QACXa,KAAK,EAAE,SAAS;QAChBC,WAAW,EAAE,qBAAqB;KACnC;IACDZ,UAAU,EAAE;QACVW,KAAK,EAAE,QAAQ;QACfC,WAAW,EAAE,oBAAoB;KAClC;IACDV,IAAI,EAAE;QACJS,KAAK,EAAE,KAAK;QACZC,WAAW,EAAE,+BAA+B;KAC7C;IACDR,GAAG,EAAE;QACHO,KAAK,EAAE,KAAK;QACZC,WAAW,EAAE,uBAAuB;KACrC;IACDN,GAAG,EAAE;QACHK,KAAK,EAAE,KAAK;QACZC,WAAW,EAAE,eAAe;KAC7B;IACDJ,GAAG,EAAE;QACHG,KAAK,EAAE,KAAK;QACZC,WAAW,EAAE,eAAe;KAC7B;CACF,AAAS,CAA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,CAAC;AAED,SAASzB,KAAK,CAACoB,MAA8B,EAAoB;IAC/D,OAAOc,cAAc,CAACd,MAAM,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,SAASlB,IAAI,CAACkB,MAA8B,EAAoB;IAC9D,OAAOc,cAAc,CAACd,MAAM,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,SAAShB,WAAW,CAACgB,MAA8B,EAAoB;IACrE,OAAOc,cAAc,CAACd,MAAM,EAAE,aAAa,CAAC,CAAC;AAC/C,CAAC;AAED,SAASd,UAAU,CAACc,MAA8B,EAAoB;IACpE,OAAOc,cAAc,CAACd,MAAM,EAAE,YAAY,CAAC,CAAC;AAC9C,CAAC;AAED,SAASZ,IAAI,CAACY,MAA8B,EAAoB;IAC9D,OAAOc,cAAc,CAACd,MAAM,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,SAASV,GAAG,CAACU,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,SAASR,GAAG,CAACQ,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,SAASN,GAAG,CAACM,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -14,6 +14,7 @@ export interface DashboardSpec {
|
|
|
14
14
|
display?: Display;
|
|
15
15
|
datasources?: Record<string, DatasourceSpec>;
|
|
16
16
|
duration: DurationString;
|
|
17
|
+
refreshInterval?: DurationString;
|
|
17
18
|
variables: VariableDefinition[];
|
|
18
19
|
layouts: LayoutDefinition[];
|
|
19
20
|
panels: Record<string, PanelDefinition>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../../src/model/dashboard.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,c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C;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC7C,QAAQ,EAAE,cAAc,CAAC;IACzB,eAAe,CAAC,EAAE,cAAc,CAAC;IACjC,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/dashboard.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSpec } from './datasource';\nimport { LayoutDefinition } from './layout';\nimport { PanelDefinition } from './panels';\nimport { ProjectMetadata } from './resource';\nimport { DurationString } from './time';\nimport { VariableDefinition } from './variables';\nimport { Display } from './display';\n\nexport interface DashboardResource {\n kind: 'Dashboard';\n metadata: ProjectMetadata;\n spec: DashboardSpec;\n}\n\nexport interface DashboardSpec {\n display?: Display;\n datasources?: Record<string, DatasourceSpec>;\n duration: DurationString;\n variables: VariableDefinition[];\n layouts: LayoutDefinition[];\n panels: Record<string, PanelDefinition>;\n}\n\nexport interface DashboardSelector {\n project: string;\n dashboard: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,
|
|
1
|
+
{"version":3,"sources":["../../src/model/dashboard.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSpec } from './datasource';\nimport { LayoutDefinition } from './layout';\nimport { PanelDefinition } from './panels';\nimport { ProjectMetadata } from './resource';\nimport { DurationString } from './time';\nimport { VariableDefinition } from './variables';\nimport { Display } from './display';\n\nexport interface DashboardResource {\n kind: 'Dashboard';\n metadata: ProjectMetadata;\n spec: DashboardSpec;\n}\n\nexport interface DashboardSpec {\n display?: Display;\n datasources?: Record<string, DatasourceSpec>;\n duration: DurationString;\n refreshInterval?: DurationString;\n variables: VariableDefinition[];\n layouts: LayoutDefinition[];\n panels: Record<string, PanelDefinition>;\n}\n\nexport interface DashboardSelector {\n project: string;\n dashboard: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WA2BC"}
|
package/dist/model/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
package/dist/model/index.js
CHANGED
package/dist/model/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './calculations';\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './http';\nexport * from './layout';\nexport * from './legend';\nexport * from './notice';\nexport * from './panels';\nexport * from './query';\nexport * from './resource';\nexport * from './thresholds';\nexport * from './time';\nexport * from './time-series-data';\nexport * from './time-series-queries';\nexport * from './variables';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './calculations';\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './http';\nexport * from './layout';\nexport * from './legend';\nexport * from './notice';\nexport * from './panels';\nexport * from './query';\nexport * from './resource';\nexport * from './thresholds';\nexport * from './time';\nexport * from './time-series-data';\nexport * from './time-series-queries';\nexport * from './units';\nexport * from './variables';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
package/dist/model/legend.d.ts
CHANGED
|
@@ -2,13 +2,18 @@ export declare const legendPositions: readonly ["Bottom", "Right"];
|
|
|
2
2
|
export declare type LegendPositions = (typeof legendPositions)[number];
|
|
3
3
|
export declare const legendModes: readonly ["List", "Table"];
|
|
4
4
|
export declare type LegendMode = (typeof legendModes)[number];
|
|
5
|
+
export declare const legendSizes: readonly ["Small", "Medium"];
|
|
6
|
+
export declare type LegendSize = (typeof legendSizes)[number];
|
|
5
7
|
export interface LegendOptionsBase {
|
|
6
8
|
position: LegendPositions;
|
|
7
9
|
mode?: LegendMode;
|
|
10
|
+
size?: LegendSize;
|
|
8
11
|
}
|
|
9
12
|
export declare function isValidLegendPosition(position: LegendPositions): boolean;
|
|
10
13
|
export declare function isValidLegendMode(mode: LegendMode): boolean;
|
|
14
|
+
export declare function isValidLegendSize(size: LegendSize): boolean;
|
|
11
15
|
export declare const DEFAULT_LEGEND: Required<LegendOptionsBase>;
|
|
12
16
|
export declare function getLegendPosition(position?: LegendPositions): "Bottom" | "Right";
|
|
13
17
|
export declare function getLegendMode(mode?: LegendMode): "List" | "Table";
|
|
18
|
+
export declare function getLegendSize(size?: LegendSize): "Small" | "Medium";
|
|
14
19
|
//# sourceMappingURL=legend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,eAAe,8BAA+B,CAAC;AAC5D,oBAAY,eAAe,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,eAAO,MAAM,WAAW,4BAA6B,CAAC;AACtD,oBAAY,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAGtD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,WAE9D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,WAEjD;AAED,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,eAAe,8BAA+B,CAAC;AAC5D,oBAAY,eAAe,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,eAAO,MAAM,WAAW,4BAA6B,CAAC;AACtD,oBAAY,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD,eAAO,MAAM,WAAW,8BAA+B,CAAC;AACxD,oBAAY,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAGtD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,WAE9D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,WAEjD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,WAEjD;AAED,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,iBAAiB,CAItD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,eAAe,sBAQ3D;AAED,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,UAAU,oBAM9C;AAED,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,UAAU,sBAM9C"}
|
package/dist/model/legend.js
CHANGED
|
@@ -22,15 +22,23 @@ export const legendModes = [
|
|
|
22
22
|
'List',
|
|
23
23
|
'Table'
|
|
24
24
|
];
|
|
25
|
+
export const legendSizes = [
|
|
26
|
+
'Small',
|
|
27
|
+
'Medium'
|
|
28
|
+
];
|
|
25
29
|
export function isValidLegendPosition(position) {
|
|
26
30
|
return legendPositions.includes(position);
|
|
27
31
|
}
|
|
28
32
|
export function isValidLegendMode(mode) {
|
|
29
33
|
return legendModes.includes(mode);
|
|
30
34
|
}
|
|
35
|
+
export function isValidLegendSize(size) {
|
|
36
|
+
return legendSizes.includes(size);
|
|
37
|
+
}
|
|
31
38
|
export const DEFAULT_LEGEND = {
|
|
32
39
|
position: 'Bottom',
|
|
33
|
-
mode: 'List'
|
|
40
|
+
mode: 'List',
|
|
41
|
+
size: 'Medium'
|
|
34
42
|
};
|
|
35
43
|
export function getLegendPosition(position) {
|
|
36
44
|
if (position === undefined) {
|
|
@@ -47,5 +55,11 @@ export function getLegendMode(mode) {
|
|
|
47
55
|
}
|
|
48
56
|
return mode;
|
|
49
57
|
}
|
|
58
|
+
export function getLegendSize(size) {
|
|
59
|
+
if (!size || !isValidLegendSize(size)) {
|
|
60
|
+
return DEFAULT_LEGEND.size;
|
|
61
|
+
}
|
|
62
|
+
return size;
|
|
63
|
+
}
|
|
50
64
|
|
|
51
65
|
//# sourceMappingURL=legend.js.map
|
package/dist/model/legend.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/legend.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// This file contains common/shared legend model code.\n// See the `components` package for legend model code specific to the Legend\n// component and the `plugin-system` package for legend model code specific to\n// panel plugin specs.\n\nexport const legendPositions = ['Bottom', 'Right'] as const;\nexport type LegendPositions = (typeof legendPositions)[number];\n\nexport const legendModes = ['List', 'Table'] as const;\nexport type LegendMode = (typeof legendModes)[number];\n\n// Common legend options used across some UI components and panel specifications\nexport interface LegendOptionsBase {\n position: LegendPositions;\n mode?: LegendMode;\n}\n\nexport function isValidLegendPosition(position: LegendPositions) {\n return (legendPositions as readonly string[]).includes(position);\n}\n\nexport function isValidLegendMode(mode: LegendMode) {\n return (legendModes as readonly string[]).includes(mode);\n}\n\nexport const DEFAULT_LEGEND: Required<LegendOptionsBase> = {\n position: 'Bottom',\n mode: 'List',\n};\n\nexport function getLegendPosition(position?: LegendPositions) {\n if (position === undefined) {\n return DEFAULT_LEGEND.position;\n }\n if (isValidLegendPosition(position)) {\n return position;\n }\n return DEFAULT_LEGEND.position;\n}\n\nexport function getLegendMode(mode?: LegendMode) {\n if (!mode || !isValidLegendMode(mode)) {\n return DEFAULT_LEGEND.mode;\n }\n\n return mode;\n}\n"],"names":["legendPositions","legendModes","isValidLegendPosition","position","includes","isValidLegendMode","mode","DEFAULT_LEGEND","getLegendPosition","undefined","getLegendMode"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,sDAAsD;AACtD,4EAA4E;AAC5E,+EAA+E;AAC/E,sBAAsB;AAEtB,OAAO,MAAMA,eAAe,GAAG;IAAC,QAAQ;IAAE,OAAO;CAAC,AAAS,CAAC;AAG5D,OAAO,MAAMC,WAAW,GAAG;IAAC,MAAM;IAAE,OAAO;CAAC,AAAS,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../src/model/legend.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// This file contains common/shared legend model code.\n// See the `components` package for legend model code specific to the Legend\n// component and the `plugin-system` package for legend model code specific to\n// panel plugin specs.\n\nexport const legendPositions = ['Bottom', 'Right'] as const;\nexport type LegendPositions = (typeof legendPositions)[number];\n\nexport const legendModes = ['List', 'Table'] as const;\nexport type LegendMode = (typeof legendModes)[number];\n\nexport const legendSizes = ['Small', 'Medium'] as const;\nexport type LegendSize = (typeof legendSizes)[number];\n\n// Common legend options used across some UI components and panel specifications\nexport interface LegendOptionsBase {\n position: LegendPositions;\n mode?: LegendMode;\n size?: LegendSize;\n}\n\nexport function isValidLegendPosition(position: LegendPositions) {\n return (legendPositions as readonly string[]).includes(position);\n}\n\nexport function isValidLegendMode(mode: LegendMode) {\n return (legendModes as readonly string[]).includes(mode);\n}\n\nexport function isValidLegendSize(size: LegendSize) {\n return (legendSizes as readonly string[]).includes(size);\n}\n\nexport const DEFAULT_LEGEND: Required<LegendOptionsBase> = {\n position: 'Bottom',\n mode: 'List',\n size: 'Medium',\n};\n\nexport function getLegendPosition(position?: LegendPositions) {\n if (position === undefined) {\n return DEFAULT_LEGEND.position;\n }\n if (isValidLegendPosition(position)) {\n return position;\n }\n return DEFAULT_LEGEND.position;\n}\n\nexport function getLegendMode(mode?: LegendMode) {\n if (!mode || !isValidLegendMode(mode)) {\n return DEFAULT_LEGEND.mode;\n }\n\n return mode;\n}\n\nexport function getLegendSize(size?: LegendSize) {\n if (!size || !isValidLegendSize(size)) {\n return DEFAULT_LEGEND.size;\n }\n\n return size;\n}\n"],"names":["legendPositions","legendModes","legendSizes","isValidLegendPosition","position","includes","isValidLegendMode","mode","isValidLegendSize","size","DEFAULT_LEGEND","getLegendPosition","undefined","getLegendMode","getLegendSize"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,sDAAsD;AACtD,4EAA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AASO,aAAa,CAACL,IAAiB,EAAE;IAC/C,IAAI,CAACA,IAAI,IAAI,CAACD,iBAAiB,CAACC,IAAI,CAAC,EAAE;QACrC,OAAOC,cAAc,CAACD,IAAI,CAAC;IAC7B,CAAC;IAED,OAAOA,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thresholds.d.ts","sourceRoot":"","sources":["../../src/model/thresholds.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;CACvB"}
|
|
1
|
+
{"version":3,"file":"thresholds.d.ts","sourceRoot":"","sources":["../../src/model/thresholds.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/thresholds.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface StepOptions {\n value: number;\n color?: string;\n name?: string;\n}\n\nexport interface ThresholdOptions {\n mode?: 'Percent' | 'Absolute';\n default_color?: string;\n max?: number; // is this same as the max in GaugeChartOptions? can we remove?\n steps?: StepOptions[];\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,
|
|
1
|
+
{"version":3,"sources":["../../src/model/thresholds.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface StepOptions {\n value: number;\n color?: string;\n name?: string;\n}\n\nexport interface ThresholdOptions {\n mode?: 'Percent' | 'Absolute';\n default_color?: string;\n max?: number; // is this same as the max in GaugeChartOptions? can we remove?\n steps?: StepOptions[];\n}\n\nexport interface ThresholdColorPalette {\n defaultColor: string;\n palette: string[];\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAgBC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UnitGroupConfig, UnitConfig } from './types';
|
|
2
|
+
declare const bytesUnitKinds: readonly ["Bytes"];
|
|
3
|
+
declare type BytesUnitKind = (typeof bytesUnitKinds)[number];
|
|
4
|
+
export declare type BytesUnitOptions = {
|
|
5
|
+
kind: BytesUnitKind;
|
|
6
|
+
decimal_places?: number;
|
|
7
|
+
abbreviate?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
|
|
10
|
+
export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>>;
|
|
11
|
+
export declare function formatBytes(bytes: number, options: BytesUnitOptions): string;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAKtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAOzE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,UAmCnE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import numbro from 'numbro';
|
|
14
|
+
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
15
|
+
import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
|
|
16
|
+
const DEFAULT_NUMBRO_MANTISSA = 2;
|
|
17
|
+
const bytesUnitKinds = [
|
|
18
|
+
'Bytes'
|
|
19
|
+
];
|
|
20
|
+
export const BYTES_GROUP_CONFIG = {
|
|
21
|
+
label: 'Bytes',
|
|
22
|
+
decimal_places: true,
|
|
23
|
+
abbreviate: true
|
|
24
|
+
};
|
|
25
|
+
export const BYTES_UNIT_CONFIG = {
|
|
26
|
+
// These units are powers of 1000.
|
|
27
|
+
// In other words, 1 KB = 1000 bytes.
|
|
28
|
+
Bytes: {
|
|
29
|
+
group: 'Bytes',
|
|
30
|
+
label: 'Bytes'
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export function formatBytes(bytes, options) {
|
|
34
|
+
const { abbreviate , decimal_places } = options;
|
|
35
|
+
if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {
|
|
36
|
+
const formatterOptions = {
|
|
37
|
+
style: 'unit',
|
|
38
|
+
unit: 'byte',
|
|
39
|
+
unitDisplay: 'long',
|
|
40
|
+
useGrouping: true
|
|
41
|
+
};
|
|
42
|
+
if (hasDecimalPlaces(decimal_places)) {
|
|
43
|
+
formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
|
|
44
|
+
formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
|
|
45
|
+
} else {
|
|
46
|
+
// This can happen if bytes is between -1000 and 1000
|
|
47
|
+
if (shouldAbbreviate(abbreviate)) {
|
|
48
|
+
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return Intl.NumberFormat('en-US', formatterOptions).format(bytes);
|
|
52
|
+
}
|
|
53
|
+
// numbro is able to add units like KB, MB, GB, etc. correctly
|
|
54
|
+
return numbro(bytes).format({
|
|
55
|
+
output: 'byte',
|
|
56
|
+
base: 'decimal',
|
|
57
|
+
spaceSeparated: true,
|
|
58
|
+
mantissa: hasDecimalPlaces(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,
|
|
59
|
+
// trimMantissa trims trailing 0s
|
|
60
|
+
trimMantissa: !hasDecimalPlaces(decimal_places),
|
|
61
|
+
// optionalMantissa excludes all the decimal places if they're all zeros
|
|
62
|
+
optionalMantissa: !hasDecimalPlaces(decimal_places)
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = (typeof bytesUnitKinds)[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n abbreviate: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n // These units are powers of 1000.\n // In other words, 1 KB = 1000 bytes.\n Bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\nexport function formatBytes(bytes: number, options: BytesUnitOptions) {\n const { abbreviate, decimal_places } = options;\n\n if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n // This can happen if bytes is between -1000 and 1000\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(bytes);\n }\n\n // numbro is able to add units like KB, MB, GB, etc. correctly\n return numbro(bytes).format({\n output: 'byte',\n base: 'decimal',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimal_places),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimal_places),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldAbbreviate","DEFAULT_NUMBRO_MANTISSA","bytesUnitKinds","BYTES_GROUP_CONFIG","label","decimal_places","abbreviate","BYTES_UNIT_CONFIG","Bytes","group","formatBytes","bytes","options","Math","abs","formatterOptions","style","unit","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","Intl","NumberFormat","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,MAAM,MAAM,QAAQ,CAAC;AAE5B,SAASC,sBAAsB,QAAQ,aAAa,CAAC;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,gBAAgB,QAAQ,SAAS,CAAC;AAEjF,MAAMC,uBAAuB,GAAG,CAAC,AAAC;AAElC,MAAMC,cAAc,GAAG;IAAC,OAAO;CAAC,AAAS,AAAC;AAO1C,OAAO,MAAMC,kBAAkB,GAAoB;IACjDC,KAAK,EAAE,OAAO;IACdC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,iBAAiB,GAAgD;IAC5E,kCAAkC;IAClC,qCAAqC;IACrCC,KAAK,EAAE;QACLC,KAAK,EAAE,OAAO;QACdL,KAAK,EAAE,OAAO;KACf;CACF,CAAC;AAEF,OAAO,SAASM,WAAW,CAACC,KAAa,EAAEC,OAAyB,EAAE;IACpE,MAAM,EAAEN,UAAU,CAAA,EAAED,cAAc,CAAA,EAAE,GAAGO,OAAO,AAAC;IAE/C,IAAI,CAACZ,gBAAgB,CAACM,UAAU,CAAC,IAAIO,IAAI,CAACC,GAAG,CAACH,KAAK,CAAC,GAAG,IAAI,EAAE;QAC3D,MAAMI,gBAAgB,GAA6B;YACjDC,KAAK,EAAE,MAAM;YACbC,IAAI,EAAE,MAAM;YACZC,WAAW,EAAE,MAAM;YACnBC,WAAW,EAAE,IAAI;SAClB,AAAC;QAEF,IAAIrB,gBAAgB,CAACO,cAAc,CAAC,EAAE;YACpCU,gBAAgB,CAACK,qBAAqB,GAAGrB,kBAAkB,CAACM,cAAc,CAAC,CAAC;YAC5EU,gBAAgB,CAACM,qBAAqB,GAAGtB,kBAAkB,CAACM,cAAc,CAAC,CAAC;QAC9E,OAAO;YACL,qDAAqD;YACrD,IAAIL,gBAAgB,CAACM,UAAU,CAAC,EAAE;gBAChCS,gBAAgB,CAACO,wBAAwB,GAAGzB,sBAAsB,CAAC;YACrE,CAAC;QACH,CAAC;QAED,OAAO0B,IAAI,CAACC,YAAY,CAAC,OAAO,EAAET,gBAAgB,CAAC,CAACU,MAAM,CAACd,KAAK,CAAC,CAAC;IACpE,CAAC;IAED,8DAA8D;IAC9D,OAAOf,MAAM,CAACe,KAAK,CAAC,CAACc,MAAM,CAAC;QAC1BC,MAAM,EAAE,MAAM;QACdC,IAAI,EAAE,SAAS;QACfC,cAAc,EAAE,IAAI;QACpBC,QAAQ,EAAE/B,gBAAgB,CAACO,cAAc,CAAC,GAAGA,cAAc,GAAGJ,uBAAuB;QACrF,iCAAiC;QACjC6B,YAAY,EAAE,CAAChC,gBAAgB,CAACO,cAAc,CAAC;QAC/C,wEAAwE;QACxE0B,gBAAgB,EAAE,CAACjC,gBAAgB,CAACO,cAAc,CAAC;KACpD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/model/units/constants.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,sBAAsB,IAAI,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
// Common constants needed across individual unit groups and the overall
|
|
14
|
+
// combined units.
|
|
15
|
+
export const MAX_SIGNIFICANT_DIGITS = 3;
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/constants.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Common constants needed across individual unit groups and the overall\n// combined units.\nexport const MAX_SIGNIFICANT_DIGITS = 3;\n"],"names":["MAX_SIGNIFICANT_DIGITS"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,wEAAwE;AACxE,kBAAkB;AAClB,OAAO,MAAMA,sBAAsB,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UnitGroupConfig, UnitConfig } from './types';
|
|
2
|
+
declare const decimalUnitKinds: readonly ["Decimal"];
|
|
3
|
+
declare type DecimalUnitKind = (typeof decimalUnitKinds)[number];
|
|
4
|
+
export declare type DecimalUnitOptions = {
|
|
5
|
+
kind: DecimalUnitKind;
|
|
6
|
+
decimal_places?: number;
|
|
7
|
+
abbreviate?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
|
|
10
|
+
export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>>;
|
|
11
|
+
export declare function formatDecimal(value: number, options: DecimalUnitOptions): string;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=decimal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAC9C,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAK7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAsBhF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
14
|
+
import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
|
|
15
|
+
const decimalUnitKinds = [
|
|
16
|
+
'Decimal'
|
|
17
|
+
];
|
|
18
|
+
export const DECIMAL_GROUP_CONFIG = {
|
|
19
|
+
label: 'Decimal',
|
|
20
|
+
decimal_places: true,
|
|
21
|
+
abbreviate: true
|
|
22
|
+
};
|
|
23
|
+
export const DECIMAL_UNIT_CONFIG = {
|
|
24
|
+
Decimal: {
|
|
25
|
+
group: 'Decimal',
|
|
26
|
+
label: 'Decimal'
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export function formatDecimal(value, options) {
|
|
30
|
+
const { abbreviate , decimal_places } = options;
|
|
31
|
+
const formatterOptions = {
|
|
32
|
+
style: 'decimal',
|
|
33
|
+
useGrouping: true
|
|
34
|
+
};
|
|
35
|
+
if (shouldAbbreviate(abbreviate)) {
|
|
36
|
+
formatterOptions.notation = 'compact';
|
|
37
|
+
}
|
|
38
|
+
if (hasDecimalPlaces(decimal_places)) {
|
|
39
|
+
formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
|
|
40
|
+
formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
|
|
41
|
+
} else {
|
|
42
|
+
if (shouldAbbreviate(abbreviate)) {
|
|
43
|
+
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return Intl.NumberFormat('en-US', formatterOptions).format(value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=decimal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst decimalUnitKinds = ['Decimal'] as const;\ntype DecimalUnitKind = (typeof decimalUnitKinds)[number];\nexport type DecimalUnitOptions = {\n kind: DecimalUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimal_places: true,\n abbreviate: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>> = {\n Decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, options: DecimalUnitOptions): string {\n const { abbreviate, decimal_places } = options;\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldAbbreviate","decimalUnitKinds","DECIMAL_GROUP_CONFIG","label","decimal_places","abbreviate","DECIMAL_UNIT_CONFIG","Decimal","group","formatDecimal","value","options","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,gBAAgB,QAAQ,SAAS,CAAC;AAEjF,MAAMC,gBAAgB,GAAG;IAAC,SAAS;CAAC,AAAS,AAAC;AAO9C,OAAO,MAAMC,oBAAoB,GAAoB;IACnDC,KAAK,EAAE,SAAS;IAChBC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,mBAAmB,GAAkD;IAChFC,OAAO,EAAE;QACPC,KAAK,EAAE,SAAS;QAChBL,KAAK,EAAE,SAAS;KACjB;CACF,CAAC;AAEF,OAAO,SAASM,aAAa,CAACC,KAAa,EAAEC,OAA2B,EAAU;IAChF,MAAM,EAAEN,UAAU,CAAA,EAAED,cAAc,CAAA,EAAE,GAAGO,OAAO,AAAC;IAE/C,MAAMC,gBAAgB,GAA6B;QACjDC,KAAK,EAAE,SAAS;QAChBC,WAAW,EAAE,IAAI;KAClB,AAAC;IAEF,IAAId,gBAAgB,CAACK,UAAU,CAAC,EAAE;QAChCO,gBAAgB,CAACG,QAAQ,GAAG,SAAS,CAAC;IACxC,CAAC;IAED,IAAIjB,gBAAgB,CAACM,cAAc,CAAC,EAAE;QACpCQ,gBAAgB,CAACI,qBAAqB,GAAGjB,kBAAkB,CAACK,cAAc,CAAC,CAAC;QAC5EQ,gBAAgB,CAACK,qBAAqB,GAAGlB,kBAAkB,CAACK,cAAc,CAAC,CAAC;IAC9E,OAAO;QACL,IAAIJ,gBAAgB,CAACK,UAAU,CAAC,EAAE;YAChCO,gBAAgB,CAACM,wBAAwB,GAAGrB,sBAAsB,CAAC;QACrE,CAAC;IACH,CAAC;IAED,OAAOsB,IAAI,CAACC,YAAY,CAAC,OAAO,EAAER,gBAAgB,CAAC,CAACS,MAAM,CAACX,KAAK,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/units/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export * from './utils';
|
|
14
|
+
export * from './units';
|
|
15
|
+
export * from './constants';
|
|
16
|
+
export * from './types';
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './utils';\nexport * from './units';\nexport * from './constants';\nexport * from './types';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UnitGroupConfig, UnitConfig } from './types';
|
|
2
|
+
declare const percentUnitKinds: readonly ["Percent", "PercentDecimal", "%"];
|
|
3
|
+
declare type PercentUnitKind = (typeof percentUnitKinds)[number];
|
|
4
|
+
export declare type PercentUnitOptions = {
|
|
5
|
+
kind: PercentUnitKind;
|
|
6
|
+
decimal_places?: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const PERCENT_GROUP_CONFIG: UnitGroupConfig;
|
|
9
|
+
export declare const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>>;
|
|
10
|
+
export declare function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=percent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AACrE,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAgB7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAmBjG"}
|