@perses-dev/components 0.55.0-beta.9 → 0.55.0-rc.0

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.
Files changed (97) hide show
  1. package/dist/DragAndDrop/DragAndDropList.d.ts +10 -2
  2. package/dist/DragAndDrop/DragAndDropList.d.ts.map +1 -1
  3. package/dist/DragAndDrop/DragAndDropList.js +6 -4
  4. package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
  5. package/dist/EChart/EChart.d.ts +1 -1
  6. package/dist/EChart/EChart.d.ts.map +1 -1
  7. package/dist/EChart/EChart.js +12 -25
  8. package/dist/EChart/EChart.js.map +1 -1
  9. package/dist/FormatControls/FormatControls.d.ts.map +1 -1
  10. package/dist/FormatControls/FormatControls.js +42 -4
  11. package/dist/FormatControls/FormatControls.js.map +1 -1
  12. package/dist/FormatControls/UnitSelector.js +4 -4
  13. package/dist/FormatControls/UnitSelector.js.map +1 -1
  14. package/dist/Legend/TableLegend.d.ts.map +1 -1
  15. package/dist/Legend/TableLegend.js +2 -1
  16. package/dist/Legend/TableLegend.js.map +1 -1
  17. package/dist/LinksEditor/LinkEditorForm.d.ts +1 -0
  18. package/dist/LinksEditor/LinkEditorForm.d.ts.map +1 -1
  19. package/dist/LinksEditor/LinkEditorForm.js +1 -0
  20. package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
  21. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -1
  22. package/dist/OptionsEditorLayout/OptionsEditorControl.js +2 -3
  23. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  24. package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts.map +1 -1
  25. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +6 -3
  26. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
  27. package/dist/Table/Table.d.ts.map +1 -1
  28. package/dist/Table/Table.js +3 -0
  29. package/dist/Table/Table.js.map +1 -1
  30. package/dist/Table/TableToolbar.d.ts.map +1 -1
  31. package/dist/Table/TableToolbar.js +1 -0
  32. package/dist/Table/TableToolbar.js.map +1 -1
  33. package/dist/Table/VirtualizedTable.d.ts +1 -1
  34. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  35. package/dist/Table/VirtualizedTable.js +10 -19
  36. package/dist/Table/VirtualizedTable.js.map +1 -1
  37. package/dist/Table/model/table-model.d.ts +6 -2
  38. package/dist/Table/model/table-model.d.ts.map +1 -1
  39. package/dist/Table/model/table-model.js.map +1 -1
  40. package/dist/ThresholdsEditor/ThresholdsEditor.js +1 -3
  41. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  42. package/dist/TimeRangeSelector/DateTimeRangePicker.js +1 -1
  43. package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
  44. package/dist/TimeRangeSelector/TimeRangeSelector.js +4 -4
  45. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
  46. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
  47. package/dist/TimeSeriesTooltip/TimeChartTooltip.js +27 -16
  48. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
  49. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  50. package/dist/TimeSeriesTooltip/utils.js +6 -2
  51. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  52. package/dist/TransformsEditor/TransformEditor.d.ts.map +1 -1
  53. package/dist/TransformsEditor/TransformEditor.js +89 -0
  54. package/dist/TransformsEditor/TransformEditor.js.map +1 -1
  55. package/dist/controls/TextField.d.ts.map +1 -1
  56. package/dist/controls/TextField.js +15 -10
  57. package/dist/controls/TextField.js.map +1 -1
  58. package/dist/model/custom.d.ts +22 -0
  59. package/dist/model/custom.d.ts.map +1 -0
  60. package/dist/model/custom.js +243 -0
  61. package/dist/model/custom.js.map +1 -0
  62. package/dist/model/index.d.ts +1 -0
  63. package/dist/model/index.d.ts.map +1 -1
  64. package/dist/model/index.js +1 -0
  65. package/dist/model/index.js.map +1 -1
  66. package/dist/model/transforms.d.ts +22 -1
  67. package/dist/model/transforms.d.ts.map +1 -1
  68. package/dist/model/transforms.js +2 -1
  69. package/dist/model/transforms.js.map +1 -1
  70. package/dist/model/units.d.ts +12 -10
  71. package/dist/model/units.d.ts.map +1 -1
  72. package/dist/model/units.js +33 -28
  73. package/dist/model/units.js.map +1 -1
  74. package/dist/utils/index.d.ts +0 -2
  75. package/dist/utils/index.d.ts.map +1 -1
  76. package/dist/utils/index.js +0 -2
  77. package/dist/utils/index.js.map +1 -1
  78. package/dist/utils/text.d.ts.map +1 -1
  79. package/dist/utils/text.js +14 -18
  80. package/dist/utils/text.js.map +1 -1
  81. package/dist/utils/transform-data.d.ts +5 -0
  82. package/dist/utils/transform-data.d.ts.map +1 -1
  83. package/dist/utils/transform-data.js +96 -0
  84. package/dist/utils/transform-data.js.map +1 -1
  85. package/dist/utils/variable-interpolation.d.ts +11 -0
  86. package/dist/utils/variable-interpolation.d.ts.map +1 -1
  87. package/dist/utils/variable-interpolation.js +64 -0
  88. package/dist/utils/variable-interpolation.js.map +1 -1
  89. package/package.json +3 -3
  90. package/dist/utils/component-ids.d.ts +0 -8
  91. package/dist/utils/component-ids.d.ts.map +0 -1
  92. package/dist/utils/component-ids.js +0 -27
  93. package/dist/utils/component-ids.js.map +0 -1
  94. package/dist/utils/memo.d.ts +0 -13
  95. package/dist/utils/memo.d.ts.map +0 -1
  96. package/dist/utils/memo.js +0 -50
  97. package/dist/utils/memo.js.map +0 -1
@@ -12,6 +12,7 @@ export * from './percent';
12
12
  export * from './temperature';
13
13
  export * from './decimal';
14
14
  export * from './throughput';
15
+ export * from './custom';
15
16
  export * from './formatterCache';
16
17
  export * from './units';
17
18
  export * from './utils';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
@@ -24,6 +24,7 @@ export * from "./percent.js";
24
24
  export * from "./temperature.js";
25
25
  export * from "./decimal.js";
26
26
  export * from "./throughput.js";
27
+ export * from "./custom.js";
27
28
  export * from "./formatterCache.js";
28
29
  export * from "./units.js";
29
30
  export * from "./utils.js";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 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 './graph';\nexport * from './theme';\nexport * from './timeOption';\nexport * from './timeZoneOption';\nexport * from './action';\nexport * from './legend';\nexport * from './time';\nexport * from './bits';\nexport * from './bytes';\nexport * from './currency';\nexport * from './percent';\nexport * from './temperature';\nexport * from './decimal';\nexport * from './throughput';\nexport * from './formatterCache';\nexport * from './units';\nexport * from './utils';\nexport * from './types';\nexport * from './thresholds';\nexport * from './transforms';\nexport * from './value-mapping';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAU;AACxB,cAAc,aAAU;AACxB,cAAc,kBAAe;AAC7B,cAAc,sBAAmB;AACjC,cAAc,cAAW;AACzB,cAAc,cAAW;AACzB,cAAc,YAAS;AACvB,cAAc,YAAS;AACvB,cAAc,aAAU;AACxB,cAAc,gBAAa;AAC3B,cAAc,eAAY;AAC1B,cAAc,mBAAgB;AAC9B,cAAc,eAAY;AAC1B,cAAc,kBAAe;AAC7B,cAAc,sBAAmB;AACjC,cAAc,aAAU;AACxB,cAAc,aAAU;AACxB,cAAc,aAAU;AACxB,cAAc,kBAAe;AAC7B,cAAc,kBAAe;AAC7B,cAAc,qBAAkB"}
1
+ {"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 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 './graph';\nexport * from './theme';\nexport * from './timeOption';\nexport * from './timeZoneOption';\nexport * from './action';\nexport * from './legend';\nexport * from './time';\nexport * from './bits';\nexport * from './bytes';\nexport * from './currency';\nexport * from './percent';\nexport * from './temperature';\nexport * from './decimal';\nexport * from './throughput';\nexport * from './custom';\nexport * from './formatterCache';\nexport * from './units';\nexport * from './utils';\nexport * from './types';\nexport * from './thresholds';\nexport * from './transforms';\nexport * from './value-mapping';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAU;AACxB,cAAc,aAAU;AACxB,cAAc,kBAAe;AAC7B,cAAc,sBAAmB;AACjC,cAAc,cAAW;AACzB,cAAc,cAAW;AACzB,cAAc,YAAS;AACvB,cAAc,YAAS;AACvB,cAAc,aAAU;AACxB,cAAc,gBAAa;AAC3B,cAAc,eAAY;AAC1B,cAAc,mBAAgB;AAC9B,cAAc,eAAY;AAC1B,cAAc,kBAAe;AAC7B,cAAc,cAAW;AACzB,cAAc,sBAAmB;AACjC,cAAc,aAAU;AACxB,cAAc,aAAU;AACxB,cAAc,aAAU;AACxB,cAAc,kBAAe;AAC7B,cAAc,kBAAe;AAC7B,cAAc,qBAAkB"}
@@ -32,12 +32,33 @@ export interface MergeSeriesTransform {
32
32
  kind: 'MergeSeries';
33
33
  spec: TransformCommonSpec;
34
34
  }
35
- export type Transform = JoinByColumnValueTransform | MergeColumnsTransform | MergeIndexedColumnsTransform | MergeSeriesTransform | ExtractColumnFieldsTransform;
35
+ /**
36
+ * Pivot multi-series table rows into a time × label matrix
37
+ * (Grafana groupingToMatrix parity).
38
+ *
39
+ * Example: columnLabel=farm_short, rowField=timestamp
40
+ * → one row per timestamp, one column per farm_short value.
41
+ */
42
+ export interface PivotByLabelTransform {
43
+ kind: 'PivotByLabel';
44
+ spec: TransformCommonSpec & {
45
+ /** Label/column that becomes dynamic column headers (e.g. farm_short). */
46
+ columnLabel: string;
47
+ /** Field for row identity (default: timestamp). */
48
+ rowField?: string;
49
+ /** Value field name (default: value). */
50
+ valueField?: string;
51
+ /** Name of the row column after pivot (default: rowField). */
52
+ rowColumnName?: string;
53
+ };
54
+ }
55
+ export type Transform = JoinByColumnValueTransform | MergeColumnsTransform | MergeIndexedColumnsTransform | MergeSeriesTransform | ExtractColumnFieldsTransform | PivotByLabelTransform;
36
56
  export declare const TRANSFORM_TEXT: {
37
57
  JoinByColumnValue: string;
38
58
  MergeColumns: string;
39
59
  MergeIndexedColumns: string;
40
60
  MergeSeries: string;
41
61
  ExtractColumnFields: string;
62
+ PivotByLabel: string;
42
63
  };
43
64
  //# sourceMappingURL=transforms.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transforms.d.ts","sourceRoot":"","sources":["../../src/model/transforms.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,mBAAmB,GAAG;QAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;CACH;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,qBAAqB,CAAC;IAC5B,IAAI,EAAE,mBA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kBAAkB,GAAG,eAAe,CAAC;QAChE,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,mBAAmB,GAAG;QAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,qBAAqB,CAAC;IAC5B,IAAI,EAAE,mBAAmB,GAAG;QAC1B,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,mBAAmB,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,mBAAmB,GAAG;QAC1B,0EAA0E;QAC1E,WAAW,EAAE,MAAM,CAAC;QACpB,mDAAmD;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,yCAAyC;QACzC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,8DAA8D;QAC9D,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAED,MAAM,MAAM,SAAS,GACjB,0BAA0B,GAC1B,qBAAqB,GACrB,4BAA4B,GAC5B,oBAAoB,GACpB,4BAA4B,GAC5B,qBAAqB,CAAC;AAG1B,eAAO,MAAM,cAAc;IACzB,iBAAiB;IACjB,YAAY;IACZ,mBAAmB;IACnB,WAAW;IACX,mBAAmB;IACnB,YAAY;CACb,CAAC"}
@@ -16,7 +16,8 @@ export const TRANSFORM_TEXT = {
16
16
  MergeColumns: 'Merge columns',
17
17
  MergeIndexedColumns: 'Merge indexed columns',
18
18
  MergeSeries: 'Merge series',
19
- ExtractColumnFields: 'Extract column fields'
19
+ ExtractColumnFields: 'Extract column fields',
20
+ PivotByLabel: 'Pivot by label'
20
21
  };
21
22
 
22
23
  //# sourceMappingURL=transforms.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/transforms.ts"],"sourcesContent":["// Copyright 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 TransformCommonSpec {\n disabled?: boolean;\n}\n\nexport interface JoinByColumnValueTransform {\n kind: 'JoinByColumnValue';\n spec: TransformCommonSpec & {\n columns: string[];\n };\n}\n\nexport interface ExtractColumnFieldsTransform {\n kind: 'ExtractColumnFields';\n spec: TransformCommonSpec & {\n column: string;\n format: 'JSON' | 'Regex' | 'SplitByDelimiter' | 'KeyValuePairs';\n matcher?: string;\n };\n}\n\nexport interface MergeColumnsTransform {\n kind: 'MergeColumns';\n spec: TransformCommonSpec & {\n columns: string[];\n name: string;\n };\n}\n\nexport interface MergeIndexedColumnsTransform {\n kind: 'MergeIndexedColumns';\n spec: TransformCommonSpec & {\n column: string;\n };\n}\n\nexport interface MergeSeriesTransform {\n kind: 'MergeSeries';\n spec: TransformCommonSpec;\n}\n\nexport type Transform =\n | JoinByColumnValueTransform\n | MergeColumnsTransform\n | MergeIndexedColumnsTransform\n | MergeSeriesTransform\n | ExtractColumnFieldsTransform;\n\n// Can be moved somewhere else\nexport const TRANSFORM_TEXT = {\n JoinByColumnValue: 'Join by column value',\n MergeColumns: 'Merge columns',\n MergeIndexedColumns: 'Merge indexed columns',\n MergeSeries: 'Merge series',\n ExtractColumnFields: 'Extract column fields',\n};\n"],"names":["TRANSFORM_TEXT","JoinByColumnValue","MergeColumns","MergeIndexedColumns","MergeSeries","ExtractColumnFields"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAiDjC,8BAA8B;AAC9B,OAAO,MAAMA,iBAAiB;IAC5BC,mBAAmB;IACnBC,cAAc;IACdC,qBAAqB;IACrBC,aAAa;IACbC,qBAAqB;AACvB,EAAE"}
1
+ {"version":3,"sources":["../../src/model/transforms.ts"],"sourcesContent":["// Copyright 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 TransformCommonSpec {\n disabled?: boolean;\n}\n\nexport interface JoinByColumnValueTransform {\n kind: 'JoinByColumnValue';\n spec: TransformCommonSpec & {\n columns: string[];\n };\n}\n\nexport interface ExtractColumnFieldsTransform {\n kind: 'ExtractColumnFields';\n spec: TransformCommonSpec & {\n column: string;\n format: 'JSON' | 'Regex' | 'SplitByDelimiter' | 'KeyValuePairs';\n matcher?: string;\n };\n}\n\nexport interface MergeColumnsTransform {\n kind: 'MergeColumns';\n spec: TransformCommonSpec & {\n columns: string[];\n name: string;\n };\n}\n\nexport interface MergeIndexedColumnsTransform {\n kind: 'MergeIndexedColumns';\n spec: TransformCommonSpec & {\n column: string;\n };\n}\n\nexport interface MergeSeriesTransform {\n kind: 'MergeSeries';\n spec: TransformCommonSpec;\n}\n\n/**\n * Pivot multi-series table rows into a time × label matrix\n * (Grafana groupingToMatrix parity).\n *\n * Example: columnLabel=farm_short, rowField=timestamp\n * → one row per timestamp, one column per farm_short value.\n */\nexport interface PivotByLabelTransform {\n kind: 'PivotByLabel';\n spec: TransformCommonSpec & {\n /** Label/column that becomes dynamic column headers (e.g. farm_short). */\n columnLabel: string;\n /** Field for row identity (default: timestamp). */\n rowField?: string;\n /** Value field name (default: value). */\n valueField?: string;\n /** Name of the row column after pivot (default: rowField). */\n rowColumnName?: string;\n };\n}\n\nexport type Transform =\n | JoinByColumnValueTransform\n | MergeColumnsTransform\n | MergeIndexedColumnsTransform\n | MergeSeriesTransform\n | ExtractColumnFieldsTransform\n | PivotByLabelTransform;\n\n// Can be moved somewhere else\nexport const TRANSFORM_TEXT = {\n JoinByColumnValue: 'Join by column value',\n MergeColumns: 'Merge columns',\n MergeIndexedColumns: 'Merge indexed columns',\n MergeSeries: 'Merge series',\n ExtractColumnFields: 'Extract column fields',\n PivotByLabel: 'Pivot by label',\n};\n"],"names":["TRANSFORM_TEXT","JoinByColumnValue","MergeColumns","MergeIndexedColumns","MergeSeries","ExtractColumnFields","PivotByLabel"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAuEjC,8BAA8B;AAC9B,OAAO,MAAMA,iBAAiB;IAC5BC,mBAAmB;IACnBC,cAAc;IACdC,qBAAqB;IACrBC,aAAa;IACbC,qBAAqB;IACrBC,cAAc;AAChB,EAAE"}
@@ -1,6 +1,7 @@
1
1
  import type { BitsFormatOptions } from './bits';
2
2
  import type { BytesFormatOptions } from './bytes';
3
3
  import type { CurrencyFormatOptions } from './currency';
4
+ import type { WithCustomLabel } from './custom';
4
5
  import type { DateFormatOptions } from './date';
5
6
  import type { DecimalFormatOptions } from './decimal';
6
7
  import type { PercentFormatOptions } from './percent';
@@ -79,7 +80,8 @@ export declare const UNIT_CONFIG: {
79
80
  readonly "writes/sec": UnitConfig;
80
81
  readonly years: UnitConfig;
81
82
  };
82
- export type FormatOptions = TimeFormatOptions | PercentFormatOptions | DecimalFormatOptions | BytesFormatOptions | BitsFormatOptions | ThroughputFormatOptions | CurrencyFormatOptions | TemperatureFormatOptions | DateFormatOptions;
83
+ /** Standard unit options plus optional display override (customLabel). */
84
+ export type FormatOptions = (TimeFormatOptions | PercentFormatOptions | DecimalFormatOptions | BytesFormatOptions | BitsFormatOptions | ThroughputFormatOptions | CurrencyFormatOptions | TemperatureFormatOptions | DateFormatOptions) & WithCustomLabel;
83
85
  type HasDecimalPlaces<UnitOpt> = UnitOpt extends {
84
86
  decimalPlaces?: number;
85
87
  } ? UnitOpt : never;
@@ -90,16 +92,16 @@ export declare function formatValue(value: number, formatOptions?: FormatOptions
90
92
  export declare function getUnitConfig(formatOptions: FormatOptions): UnitConfig;
91
93
  export declare function getUnitGroup(formatOptions: FormatOptions): UnitGroup;
92
94
  export declare function getUnitGroupConfig(formatOptions: FormatOptions): UnitGroupConfig;
93
- export declare function isTimeUnit(formatOptions: FormatOptions): formatOptions is TimeFormatOptions;
94
- export declare function isPercentUnit(formatOptions: FormatOptions): formatOptions is PercentFormatOptions;
95
- export declare function isDecimalUnit(formatOptions: FormatOptions): formatOptions is DecimalFormatOptions;
96
- export declare function isBytesUnit(formatOptions: FormatOptions): formatOptions is BytesFormatOptions;
97
- export declare function isBitsUnit(formatOptions: FormatOptions): formatOptions is BitsFormatOptions;
95
+ export declare function isTimeUnit(formatOptions: FormatOptions): formatOptions is TimeFormatOptions & WithCustomLabel;
96
+ export declare function isPercentUnit(formatOptions: FormatOptions): formatOptions is PercentFormatOptions & WithCustomLabel;
97
+ export declare function isDecimalUnit(formatOptions: FormatOptions): formatOptions is DecimalFormatOptions & WithCustomLabel;
98
+ export declare function isBytesUnit(formatOptions: FormatOptions): formatOptions is BytesFormatOptions & WithCustomLabel;
99
+ export declare function isBitsUnit(formatOptions: FormatOptions): formatOptions is BitsFormatOptions & WithCustomLabel;
98
100
  export declare function isUnitWithDecimalPlaces(formatOptions: FormatOptions): formatOptions is HasDecimalPlaces<FormatOptions>;
99
101
  export declare function isUnitWithShortValues(formatOptions: FormatOptions): formatOptions is HasShortValues<FormatOptions>;
100
- export declare function isThroughputUnit(formatOptions: FormatOptions): formatOptions is ThroughputFormatOptions;
101
- export declare function isCurrencyUnit(formatOptions: FormatOptions): formatOptions is CurrencyFormatOptions;
102
- export declare function isDateUnit(formatOptions: FormatOptions): formatOptions is DateFormatOptions;
103
- export declare function isTemperatureUnit(formatOptions: FormatOptions): formatOptions is TemperatureFormatOptions;
102
+ export declare function isThroughputUnit(formatOptions: FormatOptions): formatOptions is ThroughputFormatOptions & WithCustomLabel;
103
+ export declare function isCurrencyUnit(formatOptions: FormatOptions): formatOptions is CurrencyFormatOptions & WithCustomLabel;
104
+ export declare function isDateUnit(formatOptions: FormatOptions): formatOptions is DateFormatOptions & WithCustomLabel;
105
+ export declare function isTemperatureUnit(formatOptions: FormatOptions): formatOptions is TemperatureFormatOptions & WithCustomLabel;
104
106
  export {};
105
107
  //# sourceMappingURL=units.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/model/units.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,KAAK,EAAE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AgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,oBAAoB,GAAG,eAAe,CAEnH;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,oBAAoB,GAAG,eAAe,CAEnH;AAED,wBAAgB,WAAW,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,kBAAkB,GAAG,eAAe,CAE/G;AAED,wBAAgB,UAAU,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,iBAAiB,GAAG,eAAe,CAE7G;AAED,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,aAAa,GAC3B,aAAa,IAAI,gBAAgB,CAAC,aAAa,CAAC,CAIlD;AAED,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,cAAc,CAAC,aAAa,CAAC,CAIlH;AAED,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,aAAa,GAC3B,aAAa,IAAI,uBAAuB,GAAG,eAAe,CAE5D;AAED,wBAAgB,cAAc,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,qBAAqB,GAAG,eAAe,CAErH;AAED,wBAAgB,UAAU,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,iBAAiB,GAAG,eAAe,CAE7G;AAED,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,aAAa,GAC3B,aAAa,IAAI,wBAAwB,GAAG,eAAe,CAE7D"}
@@ -13,6 +13,7 @@
13
13
  import { formatBits, BITS_GROUP_CONFIG, BITS_UNIT_CONFIG } from "./bits.js";
14
14
  import { formatBytes, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG } from "./bytes.js";
15
15
  import { formatCurrency, CURRENCY_GROUP_CONFIG, CURRENCY_UNIT_CONFIG } from "./currency.js";
16
+ import { applyCustomLabel, supportsCustomLabel } from "./custom.js";
16
17
  import { formatDate, DATE_GROUP_CONFIG, DATE_UNIT_CONFIG } from "./date.js";
17
18
  import { formatDecimal, DECIMAL_GROUP_CONFIG, DECIMAL_UNIT_CONFIG } from "./decimal.js";
18
19
  import { formatPercent, PERCENT_GROUP_CONFIG, PERCENT_UNIT_CONFIG } from "./percent.js";
@@ -51,39 +52,43 @@ export function formatValue(value, formatOptions) {
51
52
  if (!formatOptions) {
52
53
  return value.toString();
53
54
  }
55
+ let formatted;
54
56
  if (isBytesUnit(formatOptions)) {
55
- return formatBytes(value, formatOptions);
57
+ formatted = formatBytes(value, formatOptions);
58
+ } else if (isBitsUnit(formatOptions)) {
59
+ formatted = formatBits(value, formatOptions);
60
+ } else if (isDecimalUnit(formatOptions)) {
61
+ formatted = formatDecimal(value, formatOptions);
62
+ } else if (isPercentUnit(formatOptions)) {
63
+ formatted = formatPercent(value, formatOptions);
64
+ } else if (isTimeUnit(formatOptions)) {
65
+ formatted = formatTime(value, formatOptions);
66
+ } else if (isThroughputUnit(formatOptions)) {
67
+ formatted = formatThroughput(value, formatOptions);
68
+ } else if (isCurrencyUnit(formatOptions)) {
69
+ formatted = formatCurrency(value, formatOptions);
70
+ } else if (isDateUnit(formatOptions)) {
71
+ formatted = formatDate(value, formatOptions);
72
+ } else if (isTemperatureUnit(formatOptions)) {
73
+ formatted = formatTemperature(value, formatOptions);
74
+ } else {
75
+ const exhaustive = formatOptions;
76
+ throw new Error(`Unknown unit options ${exhaustive}`);
56
77
  }
57
- if (isBitsUnit(formatOptions)) {
58
- return formatBits(value, formatOptions);
59
- }
60
- if (isDecimalUnit(formatOptions)) {
61
- return formatDecimal(value, formatOptions);
62
- }
63
- if (isPercentUnit(formatOptions)) {
64
- return formatPercent(value, formatOptions);
65
- }
66
- if (isTimeUnit(formatOptions)) {
67
- return formatTime(value, formatOptions);
68
- }
69
- if (isThroughputUnit(formatOptions)) {
70
- return formatThroughput(value, formatOptions);
71
- }
72
- if (isCurrencyUnit(formatOptions)) {
73
- return formatCurrency(value, formatOptions);
74
- }
75
- if (isDateUnit(formatOptions)) {
76
- return formatDate(value, formatOptions);
77
- }
78
- if (isTemperatureUnit(formatOptions)) {
79
- return formatTemperature(value, formatOptions);
80
- }
81
- const exhaustive = formatOptions;
82
- throw new Error(`Unknown unit options ${exhaustive}`);
78
+ return applyCustomLabel(formatted, formatOptions.customLabel, formatOptions.unit);
83
79
  }
84
80
  export function getUnitConfig(formatOptions) {
85
81
  const unit = formatOptions.unit ?? 'decimal';
86
- return UNIT_CONFIG[unit];
82
+ const config = UNIT_CONFIG[unit];
83
+ const customLabel = formatOptions.customLabel?.trim();
84
+ // Only override display name when customLabel is supported for this unit key.
85
+ if (customLabel && supportsCustomLabel(unit)) {
86
+ return {
87
+ ...config,
88
+ label: customLabel
89
+ };
90
+ }
91
+ return config;
87
92
  }
88
93
  export function getUnitGroup(formatOptions) {
89
94
  return getUnitConfig(formatOptions).group ?? 'Decimal';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/units.ts"],"sourcesContent":["// Copyright 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 type { BitsFormatOptions } from './bits';\nimport { formatBits, BITS_GROUP_CONFIG, BITS_UNIT_CONFIG } from './bits';\nimport type { BytesFormatOptions } from './bytes';\nimport { formatBytes, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG } from './bytes';\nimport type { CurrencyFormatOptions } from './currency';\nimport { formatCurrency, CURRENCY_GROUP_CONFIG, CURRENCY_UNIT_CONFIG } from './currency';\nimport type { DateFormatOptions } from './date';\nimport { formatDate, DATE_GROUP_CONFIG, DATE_UNIT_CONFIG } from './date';\nimport type { DecimalFormatOptions } from './decimal';\nimport { formatDecimal, DECIMAL_GROUP_CONFIG, DECIMAL_UNIT_CONFIG } from './decimal';\nimport type { PercentFormatOptions } from './percent';\nimport { formatPercent, PERCENT_GROUP_CONFIG, PERCENT_UNIT_CONFIG } from './percent';\nimport type { TemperatureFormatOptions } from './temperature';\nimport { TEMPERATURE_GROUP_CONFIG, formatTemperature, TEMPERATURE_UNIT_CONFIG } from './temperature';\nimport type { ThroughputFormatOptions } from './throughput';\nimport { formatThroughput, THROUGHPUT_GROUP_CONFIG, THROUGHPUT_UNIT_CONFIG } from './throughput';\nimport type { TimeFormatOptions } from './time';\nimport { formatTime, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';\nimport type { UnitGroup, UnitGroupConfig, UnitConfig } from './types';\n\n/**\n * Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.\n * Prefer Intl.NumbeFormat because it covers most use cases and will continue to be supported with time.\n *\n * To format bytes, we also make use of the `numbro` package,\n * because it can handle adding units like KB, MB, GB, etc. correctly.\n */\n\nexport const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>> = {\n Time: TIME_GROUP_CONFIG,\n Percent: PERCENT_GROUP_CONFIG,\n Decimal: DECIMAL_GROUP_CONFIG,\n Bytes: BYTES_GROUP_CONFIG,\n Bits: BITS_GROUP_CONFIG,\n Throughput: THROUGHPUT_GROUP_CONFIG,\n Currency: CURRENCY_GROUP_CONFIG,\n Temperature: TEMPERATURE_GROUP_CONFIG,\n Date: DATE_GROUP_CONFIG,\n};\nexport const UNIT_CONFIG = {\n ...TIME_UNIT_CONFIG,\n ...PERCENT_UNIT_CONFIG,\n ...DECIMAL_UNIT_CONFIG,\n ...BYTES_UNIT_CONFIG,\n ...BITS_UNIT_CONFIG,\n ...THROUGHPUT_UNIT_CONFIG,\n ...CURRENCY_UNIT_CONFIG,\n ...TEMPERATURE_UNIT_CONFIG,\n ...DATE_UNIT_CONFIG,\n} as const;\n\nexport type FormatOptions =\n | TimeFormatOptions\n | PercentFormatOptions\n | DecimalFormatOptions\n | BytesFormatOptions\n | BitsFormatOptions\n | ThroughputFormatOptions\n | CurrencyFormatOptions\n | TemperatureFormatOptions\n | DateFormatOptions;\n\ntype HasDecimalPlaces<UnitOpt> = UnitOpt extends { decimalPlaces?: number } ? UnitOpt : never;\ntype HasShortValues<UnitOpt> = UnitOpt extends { shortValues?: boolean } ? UnitOpt : never;\n\nexport function formatValue(value: number, formatOptions?: FormatOptions): string {\n if (!formatOptions) {\n return value.toString();\n }\n\n if (isBytesUnit(formatOptions)) {\n return formatBytes(value, formatOptions);\n }\n\n if (isBitsUnit(formatOptions)) {\n return formatBits(value, formatOptions);\n }\n\n if (isDecimalUnit(formatOptions)) {\n return formatDecimal(value, formatOptions);\n }\n\n if (isPercentUnit(formatOptions)) {\n return formatPercent(value, formatOptions);\n }\n\n if (isTimeUnit(formatOptions)) {\n return formatTime(value, formatOptions);\n }\n\n if (isThroughputUnit(formatOptions)) {\n return formatThroughput(value, formatOptions);\n }\n\n if (isCurrencyUnit(formatOptions)) {\n return formatCurrency(value, formatOptions);\n }\n\n if (isDateUnit(formatOptions)) {\n return formatDate(value, formatOptions);\n }\n\n if (isTemperatureUnit(formatOptions)) {\n return formatTemperature(value, formatOptions);\n }\n\n const exhaustive: never = formatOptions;\n throw new Error(`Unknown unit options ${exhaustive}`);\n}\n\nexport function getUnitConfig(formatOptions: FormatOptions): UnitConfig {\n const unit = formatOptions.unit ?? 'decimal';\n return UNIT_CONFIG[unit];\n}\n\nexport function getUnitGroup(formatOptions: FormatOptions): UnitGroup {\n return getUnitConfig(formatOptions).group ?? 'Decimal';\n}\n\nexport function getUnitGroupConfig(formatOptions: FormatOptions): UnitGroupConfig {\n const unitConfig = getUnitConfig(formatOptions);\n return UNIT_GROUP_CONFIG[unitConfig.group ?? 'Decimal'];\n}\n\n// Type guards\nexport function isTimeUnit(formatOptions: FormatOptions): formatOptions is TimeFormatOptions {\n return getUnitGroup(formatOptions) === 'Time';\n}\n\nexport function isPercentUnit(formatOptions: FormatOptions): formatOptions is PercentFormatOptions {\n return getUnitGroup(formatOptions) === 'Percent';\n}\n\nexport function isDecimalUnit(formatOptions: FormatOptions): formatOptions is DecimalFormatOptions {\n return getUnitGroup(formatOptions) === 'Decimal';\n}\n\nexport function isBytesUnit(formatOptions: FormatOptions): formatOptions is BytesFormatOptions {\n return getUnitGroup(formatOptions) === 'Bytes';\n}\n\nexport function isBitsUnit(formatOptions: FormatOptions): formatOptions is BitsFormatOptions {\n return getUnitGroup(formatOptions) === 'Bits';\n}\n\nexport function isUnitWithDecimalPlaces(\n formatOptions: FormatOptions,\n): formatOptions is HasDecimalPlaces<FormatOptions> {\n const groupConfig = getUnitGroupConfig(formatOptions);\n\n return !!groupConfig.decimalPlaces;\n}\n\nexport function isUnitWithShortValues(formatOptions: FormatOptions): formatOptions is HasShortValues<FormatOptions> {\n const groupConfig = getUnitGroupConfig(formatOptions);\n\n return !!groupConfig.shortValues;\n}\n\nexport function isThroughputUnit(formatOptions: FormatOptions): formatOptions is ThroughputFormatOptions {\n return getUnitGroup(formatOptions) === 'Throughput';\n}\n\nexport function isCurrencyUnit(formatOptions: FormatOptions): formatOptions is CurrencyFormatOptions {\n return getUnitGroup(formatOptions) === 'Currency';\n}\n\nexport function isDateUnit(formatOptions: FormatOptions): formatOptions is DateFormatOptions {\n return getUnitGroup(formatOptions) === 'Date';\n}\n\nexport function isTemperatureUnit(formatOptions: FormatOptions): formatOptions is TemperatureFormatOptions {\n return getUnitGroup(formatOptions) === 'Temperature';\n}\n"],"names":["formatBits","BITS_GROUP_CONFIG","BITS_UNIT_CONFIG","formatBytes","BYTES_GROUP_CONFIG","BYTES_UNIT_CONFIG","formatCurrency","CURRENCY_GROUP_CONFIG","CURRENCY_UNIT_CONFIG","formatDate","DATE_GROUP_CONFIG","DATE_UNIT_CONFIG","formatDecimal","DECIMAL_GROUP_CONFIG","DECIMAL_UNIT_CONFIG","formatPercent","PERCENT_GROUP_CONFIG","PERCENT_UNIT_CONFIG","TEMPERATURE_GROUP_CONFIG","formatTemperature","TEMPERATURE_UNIT_CONFIG","formatThroughput","THROUGHPUT_GROUP_CONFIG","THROUGHPUT_UNIT_CONFIG","formatTime","TIME_GROUP_CONFIG","TIME_UNIT_CONFIG","UNIT_GROUP_CONFIG","Time","Percent","Decimal","Bytes","Bits","Throughput","Currency","Temperature","Date","UNIT_CONFIG","formatValue","value","formatOptions","toString","isBytesUnit","isBitsUnit","isDecimalUnit","isPercentUnit","isTimeUnit","isThroughputUnit","isCurrencyUnit","isDateUnit","isTemperatureUnit","exhaustive","Error","getUnitConfig","unit","getUnitGroup","group","getUnitGroupConfig","unitConfig","isUnitWithDecimalPlaces","groupConfig","decimalPlaces","isUnitWithShortValues","shortValues"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,UAAU,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,YAAS;AAEzE,SAASC,WAAW,EAAEC,kBAAkB,EAAEC,iBAAiB,QAAQ,aAAU;AAE7E,SAASC,cAAc,EAAEC,qBAAqB,EAAEC,oBAAoB,QAAQ,gBAAa;AAEzF,SAASC,UAAU,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,YAAS;AAEzE,SAASC,aAAa,EAAEC,oBAAoB,EAAEC,mBAAmB,QAAQ,eAAY;AAErF,SAASC,aAAa,EAAEC,oBAAoB,EAAEC,mBAAmB,QAAQ,eAAY;AAErF,SAASC,wBAAwB,EAAEC,iBAAiB,EAAEC,uBAAuB,QAAQ,mBAAgB;AAErG,SAASC,gBAAgB,EAAEC,uBAAuB,EAAEC,sBAAsB,QAAQ,kBAAe;AAEjG,SAASC,UAAU,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,YAAS;AAGzE;;;;;;CAMC,GAED,OAAO,MAAMC,o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AAcc,IAAI,IAAI;IACnC,OAAOjB,WAAW,CAACiB,KAAK;AAC1B;AAEA,OAAO,SAASC,aAAaf,aAA4B;IACvD,OAAOa,cAAcb,eAAegB,KAAK,IAAI;AAC/C;AAEA,OAAO,SAASC,mBAAmBjB,aAA4B;IAC7D,MAAMkB,aAAaL,cAAcb;IACjC,OAAOb,iBAAiB,CAAC+B,WAAWF,KAAK,IAAI,UAAU;AACzD;AAEA,cAAc;AACd,OAAO,SAASV,WAAWN,aAA4B;IACrD,OAAOe,aAAaf,mBAAmB;AACzC;AAEA,OAAO,SAASK,cAAcL,aAA4B;IACxD,OAAOe,aAAaf,mBAAmB;AACzC;AAEA,OAAO,SAASI,cAAcJ,aAA4B;IACxD,OAAOe,aAAaf,mBAAmB;AACzC;AAEA,OAAO,SAASE,YAAYF,aAA4B;IACtD,OAAOe,aAAaf,mBAAmB;AACzC;AAEA,OAAO,SAASG,WAAWH,aAA4B;IACrD,OAAOe,aAAaf,mBAAmB;AACzC;AAEA,OAAO,SAASmB,wBACdnB,aAA4B;IAE5B,MAAMoB,cAAcH,mBAAmBjB;IAEvC,OAAO,CAAC,CAACoB,YAAYC,aAAa;AACpC;AAEA,OAAO,SAASC,sBAAsBtB,aAA4B;IAChE,MAAMoB,cAAcH,mBAAmBjB;IAEvC,OAAO,CAAC,CAACoB,YAAYG,WAAW;AAClC;AAEA,OAAO,SAAShB,iBAAiBP,aAA4B;IAC3D,OAAOe,aAAaf,mBAAmB;AACzC;AAEA,OAAO,SAASQ,eAAeR,aAA4B;IACzD,OAAOe,aAAaf,mBAAmB;AACzC;AAEA,OAAO,SAASS,WAAWT,aAA4B;IACrD,OAAOe,aAAaf,mBAAmB;AACzC;AAEA,OAAO,SAASU,kBAAkBV,aAA4B;IAC5D,OAAOe,aAAaf,mBAAmB;AACzC"}
1
+ {"version":3,"sources":["../../src/model/units.ts"],"sourcesContent":["// Copyright 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 type { BitsFormatOptions } from './bits';\nimport { formatBits, BITS_GROUP_CONFIG, BITS_UNIT_CONFIG } from './bits';\nimport type { BytesFormatOptions } from './bytes';\nimport { formatBytes, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG } from './bytes';\nimport type { CurrencyFormatOptions } from './currency';\nimport { formatCurrency, CURRENCY_GROUP_CONFIG, CURRENCY_UNIT_CONFIG } from './currency';\nimport type { WithCustomLabel } from './custom';\nimport { applyCustomLabel, supportsCustomLabel } from './custom';\nimport type { DateFormatOptions } from './date';\nimport { formatDate, DATE_GROUP_CONFIG, DATE_UNIT_CONFIG } from './date';\nimport type { DecimalFormatOptions } from './decimal';\nimport { formatDecimal, DECIMAL_GROUP_CONFIG, DECIMAL_UNIT_CONFIG } from './decimal';\nimport type { PercentFormatOptions } from './percent';\nimport { formatPercent, PERCENT_GROUP_CONFIG, PERCENT_UNIT_CONFIG } from './percent';\nimport type { TemperatureFormatOptions } from './temperature';\nimport { TEMPERATURE_GROUP_CONFIG, formatTemperature, TEMPERATURE_UNIT_CONFIG } from './temperature';\nimport type { ThroughputFormatOptions } from './throughput';\nimport { formatThroughput, THROUGHPUT_GROUP_CONFIG, THROUGHPUT_UNIT_CONFIG } from './throughput';\nimport type { TimeFormatOptions } from './time';\nimport { formatTime, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';\nimport type { UnitGroup, UnitGroupConfig, UnitConfig } from './types';\n\n/**\n * Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.\n * Prefer Intl.NumbeFormat because it covers most use cases and will continue to be supported with time.\n *\n * To format bytes, we also make use of the `numbro` package,\n * because it can handle adding units like KB, MB, GB, etc. correctly.\n */\n\nexport const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>> = {\n Time: TIME_GROUP_CONFIG,\n Percent: PERCENT_GROUP_CONFIG,\n Decimal: DECIMAL_GROUP_CONFIG,\n Bytes: BYTES_GROUP_CONFIG,\n Bits: BITS_GROUP_CONFIG,\n Throughput: THROUGHPUT_GROUP_CONFIG,\n Currency: CURRENCY_GROUP_CONFIG,\n Temperature: TEMPERATURE_GROUP_CONFIG,\n Date: DATE_GROUP_CONFIG,\n};\nexport const UNIT_CONFIG = {\n ...TIME_UNIT_CONFIG,\n ...PERCENT_UNIT_CONFIG,\n ...DECIMAL_UNIT_CONFIG,\n ...BYTES_UNIT_CONFIG,\n ...BITS_UNIT_CONFIG,\n ...THROUGHPUT_UNIT_CONFIG,\n ...CURRENCY_UNIT_CONFIG,\n ...TEMPERATURE_UNIT_CONFIG,\n ...DATE_UNIT_CONFIG,\n} as const;\n\n/** Standard unit options plus optional display override (customLabel). */\nexport type FormatOptions = (\n | TimeFormatOptions\n | PercentFormatOptions\n | DecimalFormatOptions\n | BytesFormatOptions\n | BitsFormatOptions\n | ThroughputFormatOptions\n | CurrencyFormatOptions\n | TemperatureFormatOptions\n | DateFormatOptions\n) &\n WithCustomLabel;\n\ntype HasDecimalPlaces<UnitOpt> = UnitOpt extends { decimalPlaces?: number } ? UnitOpt : never;\ntype HasShortValues<UnitOpt> = UnitOpt extends { shortValues?: boolean } ? UnitOpt : never;\n\nexport function formatValue(value: number, formatOptions?: FormatOptions): string {\n if (!formatOptions) {\n return value.toString();\n }\n\n let formatted: string;\n if (isBytesUnit(formatOptions)) {\n formatted = formatBytes(value, formatOptions);\n } else if (isBitsUnit(formatOptions)) {\n formatted = formatBits(value, formatOptions);\n } else if (isDecimalUnit(formatOptions)) {\n formatted = formatDecimal(value, formatOptions);\n } else if (isPercentUnit(formatOptions)) {\n formatted = formatPercent(value, formatOptions);\n } else if (isTimeUnit(formatOptions)) {\n formatted = formatTime(value, formatOptions);\n } else if (isThroughputUnit(formatOptions)) {\n formatted = formatThroughput(value, formatOptions);\n } else if (isCurrencyUnit(formatOptions)) {\n formatted = formatCurrency(value, formatOptions);\n } else if (isDateUnit(formatOptions)) {\n formatted = formatDate(value, formatOptions);\n } else if (isTemperatureUnit(formatOptions)) {\n formatted = formatTemperature(value, formatOptions);\n } else {\n const exhaustive: never = formatOptions;\n throw new Error(`Unknown unit options ${exhaustive}`);\n }\n\n return applyCustomLabel(formatted, formatOptions.customLabel, formatOptions.unit);\n}\n\nexport function getUnitConfig(formatOptions: FormatOptions): UnitConfig {\n const unit = formatOptions.unit ?? 'decimal';\n const config = UNIT_CONFIG[unit];\n const customLabel = formatOptions.customLabel?.trim();\n // Only override display name when customLabel is supported for this unit key.\n if (customLabel && supportsCustomLabel(unit)) {\n return { ...config, label: customLabel };\n }\n return config;\n}\n\nexport function getUnitGroup(formatOptions: FormatOptions): UnitGroup {\n return getUnitConfig(formatOptions).group ?? 'Decimal';\n}\n\nexport function getUnitGroupConfig(formatOptions: FormatOptions): UnitGroupConfig {\n const unitConfig = getUnitConfig(formatOptions);\n return UNIT_GROUP_CONFIG[unitConfig.group ?? 'Decimal'];\n}\n\n// Type guards\nexport function isTimeUnit(formatOptions: FormatOptions): formatOptions is TimeFormatOptions & WithCustomLabel {\n return getUnitGroup(formatOptions) === 'Time';\n}\n\nexport function isPercentUnit(formatOptions: FormatOptions): formatOptions is PercentFormatOptions & WithCustomLabel {\n return getUnitGroup(formatOptions) === 'Percent';\n}\n\nexport function isDecimalUnit(formatOptions: FormatOptions): formatOptions is DecimalFormatOptions & WithCustomLabel {\n return getUnitGroup(formatOptions) === 'Decimal';\n}\n\nexport function isBytesUnit(formatOptions: FormatOptions): formatOptions is BytesFormatOptions & WithCustomLabel {\n return getUnitGroup(formatOptions) === 'Bytes';\n}\n\nexport function isBitsUnit(formatOptions: FormatOptions): formatOptions is BitsFormatOptions & WithCustomLabel {\n return getUnitGroup(formatOptions) === 'Bits';\n}\n\nexport function isUnitWithDecimalPlaces(\n formatOptions: FormatOptions,\n): formatOptions is HasDecimalPlaces<FormatOptions> {\n const groupConfig = getUnitGroupConfig(formatOptions);\n\n return !!groupConfig.decimalPlaces;\n}\n\nexport function isUnitWithShortValues(formatOptions: FormatOptions): formatOptions is HasShortValues<FormatOptions> {\n const groupConfig = getUnitGroupConfig(formatOptions);\n\n return !!groupConfig.shortValues;\n}\n\nexport function isThroughputUnit(\n formatOptions: FormatOptions,\n): formatOptions is ThroughputFormatOptions & WithCustomLabel {\n return getUnitGroup(formatOptions) === 'Throughput';\n}\n\nexport function isCurrencyUnit(formatOptions: FormatOptions): formatOptions is CurrencyFormatOptions & WithCustomLabel {\n return getUnitGroup(formatOptions) === 'Currency';\n}\n\nexport function isDateUnit(formatOptions: FormatOptions): formatOptions is DateFormatOptions & WithCustomLabel {\n return getUnitGroup(formatOptions) === 'Date';\n}\n\nexport function isTemperatureUnit(\n formatOptions: FormatOptions,\n): formatOptions is TemperatureFormatOptions & WithCustomLabel {\n return getUnitGroup(formatOptions) === 'Temperature';\n}\n"],"names":["formatBits","BITS_GROUP_CONFIG","BITS_UNIT_CONFIG","formatBytes","BYTES_GROUP_CONFIG","BYTES_UNIT_CONFIG","formatCurrency","CURRENCY_GROUP_CONFIG","CURRENCY_UNIT_CONFIG","applyCustomLabel","supportsCustomLabel","formatDate","DATE_GROUP_CONFIG","DATE_UNIT_CONFIG","formatDecimal","DECIMAL_GROUP_CONFIG","DECIMAL_UNIT_CONFIG","formatPercent","PERCENT_GROUP_CONFIG","PERCENT_UNIT_CONFIG","TEMPERATURE_GROUP_CONFIG","formatTemperature","TEMPERATURE_UNIT_CONFIG","formatThroughput","THROUGHPUT_GROUP_CONFIG","THROUGHPUT_UNIT_CONFIG","formatTime","TIME_GROUP_CONFIG","TIME_UNIT_CONFIG","UNIT_GROUP_CONFIG","Time","Percent","Decimal","Bytes","Bits","Throughput","Currency","Temperature","Date","UNIT_CONFIG","formatValue","value","formatOptions","toString","formatted","isBytesUnit","isBitsUnit","isDecimalUnit","isPercentUnit","isTimeUnit","isThroughputUnit","isCurrencyUnit","isDateUnit","isTemperatureUnit","exhaustive","Error","customLabel","unit","getUnitConfig","config","trim","label","getUnitGroup","group","getUnitGroupConfig","unitConfig","isUnitWithDecimalPlaces","groupConfig","decimalPlaces","isUnitWithShortValues","shortValues"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,UAAU,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,YAAS;AAEzE,SAASC,WAAW,EAAEC,kBAAkB,EAAEC,iBAAiB,QAAQ,aAAU;AAE7E,SAASC,cAAc,EAAEC,qBAAqB,EAAEC,oBAAoB,QAAQ,gBAAa;AAEzF,SAASC,gBAAgB,EAAEC,mBAAmB,QAAQ,cAAW;AAEjE,SAASC,UAAU,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,YAAS;AAEzE,SAASC,aAAa,EAAEC,oBAAoB,EAAEC,mBAAmB,QAAQ,eAAY;AAErF,SAASC,aAAa,EAAEC,oBAAoB,EAAEC,mBAAmB,QAAQ,eAAY;AAErF,SAASC,wBAAwB,EAAEC,iBAAiB,EAAEC,uBAAuB,QAAQ,mBAAgB;AAErG,SAASC,gBAAgB,EAAEC,uBAAuB,EAAEC,sBAAsB,QAAQ,kBAAe;AAEjG,SAASC,UAAU,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,YAAS;AAGzE;;;;;;CAMC,GAED,OAAO,MAAMC,oBAAkE;IAC7EC,MAAMH;IACNI,SAASb;IACTc,SAASjB;IACTkB,OAAO7B;IACP8B,MAAMjC;IACNkC,YAAYX;IACZY,UAAU7B;IACV8B,aAAajB;IACbkB,MAAM1B;AACR,EAAE;A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;AACzC"}
@@ -2,10 +2,8 @@ export * from './axis';
2
2
  export * from './browser-storage';
3
3
  export * from './chart-actions';
4
4
  export * from './combine-sx';
5
- export * from './component-ids';
6
5
  export * from './data-field-interpolation';
7
6
  export * from './format';
8
- export * from './memo';
9
7
  export * from './request-interpolation';
10
8
  export * from './selection-interpolation';
11
9
  export * from './theme-gen';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,UAAU,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
@@ -14,10 +14,8 @@ export * from "./axis.js";
14
14
  export * from "./browser-storage.js";
15
15
  export * from "./chart-actions.js";
16
16
  export * from "./combine-sx.js";
17
- export * from "./component-ids.js";
18
17
  export * from "./data-field-interpolation.js";
19
18
  export * from "./format.js";
20
- export * from "./memo.js";
21
19
  export * from "./request-interpolation.js";
22
20
  export * from "./selection-interpolation.js";
23
21
  export * from "./theme-gen.js";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 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 './axis';\nexport * from './browser-storage';\nexport * from './chart-actions';\nexport * from './combine-sx';\nexport * from './component-ids';\nexport * from './data-field-interpolation';\nexport * from './format';\nexport * from './memo';\nexport * from './request-interpolation';\nexport * from './selection-interpolation';\nexport * from './theme-gen';\nexport * from './variable-interpolation';\nexport * from './value-mapping';\nexport * from './regexp';\nexport * from './transform-data';\nexport * from './time-series-data';\nexport * from './trace-data';\nexport * from './types';\nexport * from './text';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,YAAS;AACvB,cAAc,uBAAoB;AAClC,cAAc,qBAAkB;AAChC,cAAc,kBAAe;AAC7B,cAAc,qBAAkB;AAChC,cAAc,gCAA6B;AAC3C,cAAc,cAAW;AACzB,cAAc,YAAS;AACvB,cAAc,6BAA0B;AACxC,cAAc,+BAA4B;AAC1C,cAAc,iBAAc;AAC5B,cAAc,8BAA2B;AACzC,cAAc,qBAAkB;AAChC,cAAc,cAAW;AACzB,cAAc,sBAAmB;AACjC,cAAc,wBAAqB;AACnC,cAAc,kBAAe;AAC7B,cAAc,aAAU;AACxB,cAAc,YAAS"}
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 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 './axis';\nexport * from './browser-storage';\nexport * from './chart-actions';\nexport * from './combine-sx';\nexport * from './data-field-interpolation';\nexport * from './format';\nexport * from './request-interpolation';\nexport * from './selection-interpolation';\nexport * from './theme-gen';\nexport * from './variable-interpolation';\nexport * from './value-mapping';\nexport * from './regexp';\nexport * from './transform-data';\nexport * from './time-series-data';\nexport * from './trace-data';\nexport * from './types';\nexport * from './text';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,YAAS;AACvB,cAAc,uBAAoB;AAClC,cAAc,qBAAkB;AAChC,cAAc,kBAAe;AAC7B,cAAc,gCAA6B;AAC3C,cAAc,cAAW;AACzB,cAAc,6BAA0B;AACxC,cAAc,+BAA4B;AAC1C,cAAc,iBAAc;AAC5B,cAAc,8BAA2B;AACzC,cAAc,qBAAkB;AAChC,cAAc,cAAW;AACzB,cAAc,sBAAmB;AACjC,cAAc,wBAAqB;AACnC,cAAc,kBAAe;AAC7B,cAAc,aAAU;AACxB,cAAc,YAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,QAAQ,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAY9E;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,QAAQ,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAYtF"}
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAenD,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,QAAQ,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAE9E;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,QAAQ,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAGtF"}
@@ -10,30 +10,26 @@
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
+ function getDisplayName(spec) {
14
+ if (typeof spec !== 'object' || spec === null || !('display' in spec)) return undefined;
15
+ const { display } = spec;
16
+ if (typeof display !== 'object' || display === null || !('name' in display)) return undefined;
17
+ return typeof display.name === 'string' && display.name ? display.name : undefined;
18
+ }
19
+ function getSpecDisplayName(spec) {
20
+ // Variables wrap their display settings in a nested spec.
21
+ const nestedSpec = typeof spec === 'object' && spec !== null && 'spec' in spec ? spec.spec : undefined;
22
+ return getDisplayName(nestedSpec) ?? getDisplayName(spec);
23
+ }
13
24
  export function getResourceDisplayName(resource) {
14
- // Variables
15
- if (resource.spec?.spec?.display?.name) {
16
- return resource.spec.spec.display.name;
17
- }
18
- // Other resources with display
19
- if (resource.spec?.display?.name) {
20
- return resource.spec.display.name;
21
- }
22
- return resource.metadata.name;
25
+ return getSpecDisplayName(resource.spec) ?? resource.metadata.name;
23
26
  }
24
27
  /**
25
28
  * If the resource has a display name, return the resource display name with the resource name too
26
29
  * Else, only return the resource name
27
30
  */ export function getResourceExtendedDisplayName(resource) {
28
- // Variables
29
- if (resource.spec?.spec?.display?.name) {
30
- return `${resource.spec.spec.display.name} (ID: ${resource.metadata.name})`;
31
- }
32
- // Other resources with display
33
- if (resource.spec?.display?.name) {
34
- return `${resource.spec.display.name} (ID: ${resource.metadata.name})`;
35
- }
36
- return resource.metadata.name;
31
+ const displayName = getSpecDisplayName(resource.spec);
32
+ return displayName ? `${displayName} (ID: ${resource.metadata.name})` : resource.metadata.name;
37
33
  }
38
34
 
39
35
  //# sourceMappingURL=text.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/text.ts"],"sourcesContent":["// Copyright 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 type { Resource } from '@perses-dev/client';\n\nexport function getResourceDisplayName<T extends Resource>(resource: T): string {\n // Variables\n if (resource.spec?.spec?.display?.name) {\n return resource.spec.spec.display.name;\n }\n\n // Other resources with display\n if (resource.spec?.display?.name) {\n return resource.spec.display.name;\n }\n\n return resource.metadata.name;\n}\n\n/**\n * If the resource has a display name, return the resource display name with the resource name too\n * Else, only return the resource name\n */\nexport function getResourceExtendedDisplayName<T extends Resource>(resource: T): string {\n // Variables\n if (resource.spec?.spec?.display?.name) {\n return `${resource.spec.spec.display.name} (ID: ${resource.metadata.name})`;\n }\n\n // Other resources with display\n if (resource.spec?.display?.name) {\n return `${resource.spec.display.name} (ID: ${resource.metadata.name})`;\n }\n\n return resource.metadata.name;\n}\n"],"names":["getResourceDisplayName","resource","spec","display","name","metadata","getResourceExtendedDisplayName"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,SAASA,uBAA2CC,QAAW;IACpE,YAAY;IACZ,IAAIA,SAASC,IAAI,EAAEA,MAAMC,SAASC,MAAM;QACtC,OAAOH,SAASC,IAAI,CAACA,IAAI,CAACC,OAAO,CAACC,IAAI;IACxC;IAEA,+BAA+B;IAC/B,IAAIH,SAASC,IAAI,EAAEC,SAASC,MAAM;QAChC,OAAOH,SAASC,IAAI,CAACC,OAAO,CAACC,IAAI;IACnC;IAEA,OAAOH,SAASI,QAAQ,CAACD,IAAI;AAC/B;AAEA;;;CAGC,GACD,OAAO,SAASE,+BAAmDL,QAAW;IAC5E,YAAY;IACZ,IAAIA,SAASC,IAAI,EAAEA,MAAMC,SAASC,MAAM;QACtC,OAAO,GAAGH,SAASC,IAAI,CAACA,IAAI,CAACC,OAAO,CAACC,IAAI,CAAC,MAAM,EAAEH,SAASI,QAAQ,CAACD,IAAI,CAAC,CAAC,CAAC;IAC7E;IAEA,+BAA+B;IAC/B,IAAIH,SAASC,IAAI,EAAEC,SAASC,MAAM;QAChC,OAAO,GAAGH,SAASC,IAAI,CAACC,OAAO,CAACC,IAAI,CAAC,MAAM,EAAEH,SAASI,QAAQ,CAACD,IAAI,CAAC,CAAC,CAAC;IACxE;IAEA,OAAOH,SAASI,QAAQ,CAACD,IAAI;AAC/B"}
1
+ {"version":3,"sources":["../../src/utils/text.ts"],"sourcesContent":["// Copyright 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 type { Resource } from '@perses-dev/client';\n\nfunction getDisplayName(spec: unknown): string | undefined {\n if (typeof spec !== 'object' || spec === null || !('display' in spec)) return undefined;\n const { display } = spec;\n if (typeof display !== 'object' || display === null || !('name' in display)) return undefined;\n return typeof display.name === 'string' && display.name ? display.name : undefined;\n}\n\nfunction getSpecDisplayName(spec: unknown): string | undefined {\n // Variables wrap their display settings in a nested spec.\n const nestedSpec = typeof spec === 'object' && spec !== null && 'spec' in spec ? spec.spec : undefined;\n return getDisplayName(nestedSpec) ?? getDisplayName(spec);\n}\n\nexport function getResourceDisplayName<T extends Resource>(resource: T): string {\n return getSpecDisplayName(resource.spec) ?? resource.metadata.name;\n}\n\n/**\n * If the resource has a display name, return the resource display name with the resource name too\n * Else, only return the resource name\n */\nexport function getResourceExtendedDisplayName<T extends Resource>(resource: T): string {\n const displayName = getSpecDisplayName(resource.spec);\n return displayName ? `${displayName} (ID: ${resource.metadata.name})` : resource.metadata.name;\n}\n"],"names":["getDisplayName","spec","undefined","display","name","getSpecDisplayName","nestedSpec","getResourceDisplayName","resource","metadata","getResourceExtendedDisplayName","displayName"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,eAAeC,IAAa;IACnC,IAAI,OAAOA,SAAS,YAAYA,SAAS,QAAQ,CAAE,CAAA,aAAaA,IAAG,GAAI,OAAOC;IAC9E,MAAM,EAAEC,OAAO,EAAE,GAAGF;IACpB,IAAI,OAAOE,YAAY,YAAYA,YAAY,QAAQ,CAAE,CAAA,UAAUA,OAAM,GAAI,OAAOD;IACpF,OAAO,OAAOC,QAAQC,IAAI,KAAK,YAAYD,QAAQC,IAAI,GAAGD,QAAQC,IAAI,GAAGF;AAC3E;AAEA,SAASG,mBAAmBJ,IAAa;IACvC,0DAA0D;IAC1D,MAAMK,aAAa,OAAOL,SAAS,YAAYA,SAAS,QAAQ,UAAUA,OAAOA,KAAKA,IAAI,GAAGC;IAC7F,OAAOF,eAAeM,eAAeN,eAAeC;AACtD;AAEA,OAAO,SAASM,uBAA2CC,QAAW;IACpE,OAAOH,mBAAmBG,SAASP,IAAI,KAAKO,SAASC,QAAQ,CAACL,IAAI;AACpE;AAEA;;;CAGC,GACD,OAAO,SAASM,+BAAmDF,QAAW;IAC5E,MAAMG,cAAcN,mBAAmBG,SAASP,IAAI;IACpD,OAAOU,cAAc,GAAGA,YAAY,MAAM,EAAEH,SAASC,QAAQ,CAACL,IAAI,CAAC,CAAC,CAAC,GAAGI,SAASC,QAAQ,CAACL,IAAI;AAChG"}
@@ -3,5 +3,10 @@ export declare function applyJoinTransform(data: Array<Record<string, unknown>>,
3
3
  export declare function applyMergeColumnsTransform(data: Array<Record<string, unknown>>, selectedColumns: string[], outputName: string): Array<Record<string, unknown>>;
4
4
  export declare function applyMergeIndexedColumnsTransform(data: Array<Record<string, unknown>>, column: string): Array<Record<string, unknown>>;
5
5
  export declare function applyMergeSeriesTransform(data: Array<Record<string, unknown>>): Array<Record<string, unknown>>;
6
+ /**
7
+ * Pivot: rows grouped by rowField, dynamic columns from columnLabel values.
8
+ * Last value wins on duplicate (time, label).
9
+ */
10
+ export declare function applyPivotByLabelTransform(data: Array<Record<string, unknown>>, columnLabel: string, rowField?: string, valueField?: string, rowColumnName?: string): Array<Record<string, unknown>>;
6
11
  export declare function transformData(data: Array<Record<string, unknown>>, transforms: Transform[]): Array<Record<string, unknown>>;
7
12
  //# sourceMappingURL=transform-data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transform-data.d.ts","sourceRoot":"","sources":["../../src/utils/transform-data.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAqB1C,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,OAAO,EAAE,MAAM,EAAE,GAChB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAsBhC;AA0BD,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,eAAe,EAAE,MAAM,EAAE,EACzB,UAAU,EAAE,MAAM,GACjB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAuBhC;AA0BD,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,MAAM,EAAE,MAAM,GACb,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAwBhC;AAmBD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAmB9G;AAKD,wBAAgB,aAAa,CAC3B,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,UAAU,EAAE,SAAS,EAAE,GACtB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA2ChC"}
1
+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M,EAAE,OAAO,CAAC,CAAC,EACpC,UAAU,EAAE,SAAS,EAAE,GACtB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAgEhC"}
@@ -165,13 +165,99 @@
165
165
  result = applyJoinTransform(result, labelColumns);
166
166
  return result;
167
167
  }
168
+ /** Treat empty string like omitted (editor / CUE can emit ""). */ function nonEmpty(s, fallback) {
169
+ return s?.trim() || fallback;
170
+ }
171
+ /** Resolve column key including MergeSeries suffixes ("value #2"). */ function resolvePivotKey(row, base) {
172
+ if (Object.hasOwn(row, base)) return base;
173
+ return Object.keys(row).find((k)=>k === base || k.startsWith(base + ' #') || k.startsWith(base + '#'));
174
+ }
175
+ /**
176
+ * Pivot: rows grouped by rowField, dynamic columns from columnLabel values.
177
+ * Last value wins on duplicate (time, label).
178
+ */ export function applyPivotByLabelTransform(data, columnLabel, rowField = 'timestamp', valueField = 'value', rowColumnName) {
179
+ if (!columnLabel || data.length === 0) {
180
+ return data;
181
+ }
182
+ const rowFieldName = nonEmpty(rowField, 'timestamp');
183
+ const valueFieldName = nonEmpty(valueField, 'value');
184
+ const rowCol = nonEmpty(rowColumnName, rowFieldName);
185
+ const labelSet = new Set();
186
+ const groups = new Map();
187
+ for (const row of data){
188
+ const rowKeyName = resolvePivotKey(row, rowFieldName);
189
+ const labelKeyName = resolvePivotKey(row, columnLabel);
190
+ const valueKeyName = resolvePivotKey(row, valueFieldName);
191
+ if (rowKeyName === undefined || labelKeyName === undefined) {
192
+ continue;
193
+ }
194
+ const rowKey = row[rowKeyName];
195
+ const label = row[labelKeyName];
196
+ if (rowKey === undefined || rowKey === null || label === undefined || label === null) {
197
+ continue;
198
+ }
199
+ // Avoid clobbering the row identity column when a series label equals rowCol.
200
+ // Skip blank labels (empty string / whitespace-only) — not meaningful column headers.
201
+ let labelStr = String(label).trim();
202
+ if (!labelStr) {
203
+ continue;
204
+ }
205
+ if (labelStr === rowCol) {
206
+ labelStr = `${labelStr} (value)`;
207
+ }
208
+ labelSet.add(labelStr);
209
+ const groupId = String(rowKey);
210
+ let out = groups.get(groupId);
211
+ if (!out) {
212
+ out = {
213
+ [rowCol]: rowKey
214
+ };
215
+ groups.set(groupId, out);
216
+ }
217
+ if (valueKeyName !== undefined) {
218
+ out[labelStr] = row[valueKeyName];
219
+ }
220
+ }
221
+ // Fresh copy from Set — mutate with sort() (no need for toSorted extra copy).
222
+ const labels = [
223
+ ...labelSet
224
+ ];
225
+ labels.sort((a, b)=>a.localeCompare(b));
226
+ const entries = [
227
+ ...groups.entries()
228
+ ];
229
+ entries.sort((a, b)=>{
230
+ const va = a[1][rowCol];
231
+ const vb = b[1][rowCol];
232
+ if (typeof va === 'number' && typeof vb === 'number') {
233
+ return vb - va;
234
+ }
235
+ return String(vb).localeCompare(String(va));
236
+ });
237
+ return entries.map(([, row])=>{
238
+ const ordered = {
239
+ [rowCol]: row[rowCol]
240
+ };
241
+ for (const lab of labels){
242
+ if (Object.hasOwn(row, lab)) {
243
+ ordered[lab] = row[lab];
244
+ }
245
+ }
246
+ return ordered;
247
+ });
248
+ }
168
249
  /*
169
250
  * Transforms query data with the given transforms
170
251
  */ export function transformData(data, transforms) {
171
252
  let result = data;
253
+ // Only skip final alpha sort when the last *enabled* transform is PivotByLabel
254
+ // (pivot already orders: row column first, then labels). Intermediate pivots must
255
+ // not leave skipAlphaSort stuck true for later transforms.
256
+ let lastEnabledKind;
172
257
  // Apply transforms by their orders
173
258
  for (const transform of transforms ?? []){
174
259
  if (transform.spec.disabled) continue;
260
+ lastEnabledKind = transform.kind;
175
261
  switch(transform.kind){
176
262
  case 'JoinByColumnValue':
177
263
  {
@@ -199,8 +285,18 @@
199
285
  result = applyMergeSeriesTransform(result);
200
286
  break;
201
287
  }
288
+ case 'PivotByLabel':
289
+ {
290
+ if (transform.spec.columnLabel) {
291
+ result = applyPivotByLabelTransform(result, transform.spec.columnLabel, nonEmpty(transform.spec.rowField, 'timestamp'), nonEmpty(transform.spec.valueField, 'value'), transform.spec.rowColumnName);
292
+ }
293
+ break;
294
+ }
202
295
  }
203
296
  }
297
+ if (lastEnabledKind === 'PivotByLabel') {
298
+ return result;
299
+ }
204
300
  // Ordering data column alphabetically
205
301
  result = result.map((row)=>{
206
302
  return Object.keys(row).toSorted().reduce((obj, key)=>{