@perses-dev/components 0.0.0-snapshot-color-palette-gen-test-0ebddd6 → 0.0.0-snapshot-saving-defaults-refinements-1b25cec
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/ContentWithLegend/ContentWithLegend.d.ts +11 -0
- package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -0
- package/dist/ContentWithLegend/ContentWithLegend.js +65 -0
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -0
- package/dist/ContentWithLegend/index.d.ts +2 -0
- package/dist/ContentWithLegend/index.d.ts.map +1 -0
- package/dist/ContentWithLegend/index.js +15 -0
- package/dist/ContentWithLegend/index.js.map +1 -0
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +68 -0
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -0
- package/dist/ContentWithLegend/model/content-with-legend-model.js +90 -0
- package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -0
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js +7 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +9 -1
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/Legend/CompactLegend.d.ts +6 -4
- package/dist/Legend/CompactLegend.d.ts.map +1 -1
- package/dist/Legend/CompactLegend.js +4 -1
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.d.ts +11 -9
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +70 -21
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts +5 -8
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +17 -103
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +8 -8
- package/dist/Legend/ListLegendItem.d.ts.map +1 -1
- package/dist/Legend/ListLegendItem.js +9 -12
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/Legend/TableLegend.d.ts +12 -0
- package/dist/Legend/TableLegend.d.ts.map +1 -0
- package/dist/Legend/TableLegend.js +61 -0
- package/dist/Legend/TableLegend.js.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js +35 -3
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts +2 -1
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +83 -36
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +23 -15
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/Table/InnerTable.d.ts +9 -0
- package/dist/Table/InnerTable.d.ts.map +1 -0
- package/dist/Table/InnerTable.js +38 -0
- package/dist/Table/InnerTable.js.map +1 -0
- package/dist/Table/Table.d.ts +10 -0
- package/dist/Table/Table.d.ts.map +1 -0
- package/dist/Table/Table.js +101 -0
- package/dist/Table/Table.js.map +1 -0
- package/dist/Table/TableBody.d.ts +6 -0
- package/dist/Table/TableBody.d.ts.map +1 -0
- package/dist/Table/TableBody.js +23 -0
- package/dist/Table/TableBody.js.map +1 -0
- package/dist/Table/TableCell.d.ts +18 -0
- package/dist/Table/TableCell.d.ts.map +1 -0
- package/dist/Table/TableCell.js +91 -0
- package/dist/Table/TableCell.js.map +1 -0
- package/dist/Table/TableCheckbox.d.ts +9 -0
- package/dist/Table/TableCheckbox.d.ts.map +1 -0
- package/dist/Table/TableCheckbox.js +49 -0
- package/dist/Table/TableCheckbox.js.map +1 -0
- package/dist/Table/TableHead.d.ts +6 -0
- package/dist/Table/TableHead.d.ts.map +1 -0
- package/dist/Table/TableHead.js +23 -0
- package/dist/Table/TableHead.js.map +1 -0
- package/dist/Table/TableRow.d.ts +9 -0
- package/dist/Table/TableRow.d.ts.map +1 -0
- package/dist/Table/TableRow.js +29 -0
- package/dist/Table/TableRow.js.map +1 -0
- package/dist/Table/VirtualizedTable.d.ts +11 -0
- package/dist/Table/VirtualizedTable.d.ts.map +1 -0
- package/dist/Table/VirtualizedTable.js +152 -0
- package/dist/Table/VirtualizedTable.js.map +1 -0
- package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
- package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
- package/dist/Table/VirtualizedTableContainer.js +24 -0
- package/dist/Table/VirtualizedTableContainer.js.map +1 -0
- package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
- package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
- package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
- package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
- package/dist/Table/index.d.ts +4 -0
- package/dist/Table/index.d.ts.map +1 -0
- package/dist/Table/index.js +16 -0
- package/dist/Table/index.js.map +1 -0
- package/dist/Table/model/table-model.d.ts +83 -0
- package/dist/Table/model/table-model.d.ts.map +1 -0
- package/dist/Table/model/table-model.js +73 -0
- package/dist/Table/model/table-model.js.map +1 -0
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +5 -4
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +50 -22
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts +3 -3
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +28 -67
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +12 -0
- package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/TooltipHeader.js +160 -0
- package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -0
- package/dist/TimeSeriesTooltip/index.d.ts +2 -1
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +2 -1
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +17 -13
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +11 -2
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +9 -17
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
- package/dist/UnitSelector/UnitSelector.js +40 -17
- package/dist/UnitSelector/UnitSelector.js.map +1 -1
- package/dist/YAxisLabel.d.ts.map +1 -1
- package/dist/YAxisLabel.js +1 -0
- package/dist/YAxisLabel.js.map +1 -1
- package/dist/cjs/ContentWithLegend/ContentWithLegend.js +70 -0
- package/dist/cjs/ContentWithLegend/index.js +28 -0
- package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +100 -0
- package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +7 -1
- package/dist/cjs/EChart/EChart.js +9 -1
- package/dist/cjs/Legend/CompactLegend.js +4 -1
- package/dist/cjs/Legend/Legend.js +70 -21
- package/dist/cjs/Legend/ListLegend.js +17 -103
- package/dist/cjs/Legend/ListLegendItem.js +8 -11
- package/dist/cjs/Legend/TableLegend.js +67 -0
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +34 -2
- package/dist/cjs/LineChart/LineChart.js +83 -36
- package/dist/cjs/StatChart/StatChart.js +23 -15
- package/dist/cjs/Table/InnerTable.js +44 -0
- package/dist/cjs/Table/Table.js +102 -0
- package/dist/cjs/Table/TableBody.js +29 -0
- package/dist/cjs/Table/TableCell.js +97 -0
- package/dist/cjs/Table/TableCheckbox.js +55 -0
- package/dist/cjs/Table/TableHead.js +29 -0
- package/dist/cjs/Table/TableRow.js +35 -0
- package/dist/cjs/Table/VirtualizedTable.js +155 -0
- package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
- package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
- package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
- package/dist/cjs/Table/index.js +33 -0
- package/dist/cjs/Table/model/table-model.js +80 -0
- package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
- package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +54 -21
- package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +26 -65
- package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +171 -0
- package/dist/cjs/TimeSeriesTooltip/index.js +2 -1
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
- package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +17 -3
- package/dist/cjs/TimeSeriesTooltip/utils.js +8 -16
- package/dist/cjs/UnitSelector/UnitSelector.js +39 -16
- package/dist/cjs/YAxisLabel.js +1 -0
- package/dist/cjs/context/SnackbarProvider.js +66 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/model/legend.js +37 -2
- package/dist/cjs/model/units/bytes.js +25 -21
- package/dist/cjs/model/units/constants.js +3 -3
- package/dist/cjs/model/units/decimal.js +22 -19
- package/dist/cjs/model/units/percent.js +20 -11
- package/dist/cjs/model/units/time.js +26 -22
- package/dist/cjs/model/units/units.js +2 -2
- package/dist/cjs/model/units/utils.js +42 -0
- package/dist/cjs/theme/palette/grey.js +6 -2
- package/dist/cjs/utils/theme-gen.js +8 -13
- package/dist/context/SnackbarProvider.d.ts +23 -0
- package/dist/context/SnackbarProvider.d.ts.map +1 -0
- package/dist/context/SnackbarProvider.js +59 -0
- package/dist/context/SnackbarProvider.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/model/legend.d.ts +19 -5
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +31 -1
- package/dist/model/legend.js.map +1 -1
- package/dist/model/units/bytes.d.ts +1 -1
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +26 -22
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/constants.d.ts +1 -1
- package/dist/model/units/constants.js +1 -1
- package/dist/model/units/constants.js.map +1 -1
- package/dist/model/units/decimal.d.ts +2 -2
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +22 -19
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/percent.d.ts +2 -2
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +20 -11
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/time.d.ts +2 -2
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +26 -22
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/types.d.ts +9 -0
- package/dist/model/units/types.d.ts.map +1 -1
- package/dist/model/units/types.js.map +1 -1
- package/dist/model/units/units.js +2 -2
- package/dist/model/units/units.js.map +1 -1
- 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/theme/palette/grey.d.ts.map +1 -1
- package/dist/theme/palette/grey.js +6 -2
- package/dist/theme/palette/grey.js.map +1 -1
- package/dist/utils/theme-gen.d.ts.map +1 -1
- package/dist/utils/theme-gen.js +8 -13
- package/dist/utils/theme-gen.js.map +1 -1
- package/package.json +6 -6
- package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
- package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/focused-series.js +0 -111
- package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
- package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -117
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/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 './ColorPicker';\nexport * from './DateTimeRangePicker';\nexport * from './Dialog';\nexport * from './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './GaugeChart';\nexport * from './InfoTooltip';\nexport * from './JSONEditor';\nexport * from './Legend';\nexport * from './LegendOptionsEditor';\nexport * from './LineChart';\nexport * from './OptionsEditorLayout';\nexport * from './StatChart';\nexport * from './ThresholdsEditor';\nexport * from './TimeSeriesTooltip';\nexport * from './UnitSelector';\nexport * from './YAxisLabel';\nexport * from './context/ChartsThemeProvider';\nexport * from './context/TimeZoneProvider';\nexport * from './utils';\nexport * from './model';\nexport * from './test-utils';\nexport * from './theme';\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,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/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 './ColorPicker';\nexport * from './ContentWithLegend';\nexport * from './DateTimeRangePicker';\nexport * from './Dialog';\nexport * from './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './GaugeChart';\nexport * from './InfoTooltip';\nexport * from './JSONEditor';\nexport * from './Legend';\nexport * from './LegendOptionsEditor';\nexport * from './LineChart';\nexport * from './OptionsEditorLayout';\nexport * from './StatChart';\nexport * from './Table';\nexport * from './ThresholdsEditor';\nexport * from './TimeSeriesTooltip';\nexport * from './UnitSelector';\nexport * from './YAxisLabel';\nexport * from './context/ChartsThemeProvider';\nexport * from './context/TimeZoneProvider';\nexport * from './context/SnackbarProvider';\nexport * from './utils';\nexport * from './model';\nexport * from './test-utils';\nexport * from './theme';\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,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
package/dist/model/legend.d.ts
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import { MouseEventHandler } from 'react';
|
|
2
2
|
export declare const legendPositions: readonly ["Bottom", "Right"];
|
|
3
3
|
export declare type LegendPositions = (typeof legendPositions)[number];
|
|
4
|
+
export declare const legendModes: readonly ["List", "Table"];
|
|
5
|
+
export declare type LegendMode = (typeof legendModes)[number];
|
|
4
6
|
export interface LegendOptions {
|
|
5
7
|
position: LegendPositions;
|
|
8
|
+
mode?: LegendMode;
|
|
6
9
|
}
|
|
7
10
|
export interface LegendItem {
|
|
8
11
|
id: string;
|
|
9
12
|
label: string;
|
|
10
|
-
isSelected: boolean;
|
|
11
13
|
color: string;
|
|
12
|
-
onClick
|
|
14
|
+
onClick?: MouseEventHandler<HTMLElement>;
|
|
13
15
|
}
|
|
14
|
-
export declare type
|
|
16
|
+
export declare type LegendSingleSelectConfig = {
|
|
15
17
|
label: string;
|
|
16
18
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
/**
|
|
20
|
+
* State of selected items in the legend.
|
|
21
|
+
* - When "ALL", all legend items are selected, but not visually highlighted.
|
|
22
|
+
* - Otherwise, it is a Record that associates legend item ids with a boolean
|
|
23
|
+
* value. When the associated entry for a legend item is `true`, that item
|
|
24
|
+
* will be treated as selected and visually highlighted.
|
|
25
|
+
*/
|
|
26
|
+
export declare type SelectedLegendItemState = Record<LegendItem['id'], boolean> | 'ALL';
|
|
27
|
+
export declare const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendSingleSelectConfig>>;
|
|
28
|
+
export declare const LEGEND_MODE_CONFIG: Readonly<Record<LegendMode, LegendSingleSelectConfig>>;
|
|
29
|
+
export declare const DEFAULT_LEGEND: Required<LegendOptions>;
|
|
19
30
|
export declare function getLegendPosition(position?: LegendPositions): "Bottom" | "Right";
|
|
20
31
|
export declare function isValidLegendPosition(position: LegendPositions): boolean;
|
|
32
|
+
export declare function isValidLegendMode(mode: LegendMode): boolean;
|
|
33
|
+
export declare function getLegendMode(mode?: LegendMode): "List" | "Table";
|
|
21
34
|
export declare function validateLegendSpec(legend?: LegendOptions): boolean;
|
|
35
|
+
export declare function isLegendItemVisuallySelected(item: LegendItem, selectedItems: SelectedLegendItemState): boolean;
|
|
22
36
|
//# sourceMappingURL=legend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,eAAO,MAAM,eAAe,8BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,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,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;CAC1C;AAED,oBAAY,wBAAwB,GAAG;IACrC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;GAMG;AACH,oBAAY,uBAAuB,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;AAEhF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,wBAAwB,CAAC,CAG/F,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAGrF,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,aAAa,CAGlD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,eAAe,sBAQ3D;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,WAE9D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,WAEjD;AAED,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,UAAU,oBAM9C;AAED,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,aAAa,WAaxD;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,uBAAuB,WAIpG"}
|
package/dist/model/legend.js
CHANGED
|
@@ -14,6 +14,10 @@ export const legendPositions = [
|
|
|
14
14
|
'Bottom',
|
|
15
15
|
'Right'
|
|
16
16
|
];
|
|
17
|
+
export const legendModes = [
|
|
18
|
+
'List',
|
|
19
|
+
'Table'
|
|
20
|
+
];
|
|
17
21
|
export const LEGEND_POSITIONS_CONFIG = {
|
|
18
22
|
Bottom: {
|
|
19
23
|
label: 'Bottom'
|
|
@@ -22,8 +26,17 @@ export const LEGEND_POSITIONS_CONFIG = {
|
|
|
22
26
|
label: 'Right'
|
|
23
27
|
}
|
|
24
28
|
};
|
|
29
|
+
export const LEGEND_MODE_CONFIG = {
|
|
30
|
+
List: {
|
|
31
|
+
label: 'List'
|
|
32
|
+
},
|
|
33
|
+
Table: {
|
|
34
|
+
label: 'Table'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
25
37
|
export const DEFAULT_LEGEND = {
|
|
26
|
-
position: 'Bottom'
|
|
38
|
+
position: 'Bottom',
|
|
39
|
+
mode: 'List'
|
|
27
40
|
};
|
|
28
41
|
export function getLegendPosition(position) {
|
|
29
42
|
if (position === undefined) {
|
|
@@ -37,6 +50,15 @@ export function getLegendPosition(position) {
|
|
|
37
50
|
export function isValidLegendPosition(position) {
|
|
38
51
|
return legendPositions.includes(position);
|
|
39
52
|
}
|
|
53
|
+
export function isValidLegendMode(mode) {
|
|
54
|
+
return legendModes.includes(mode);
|
|
55
|
+
}
|
|
56
|
+
export function getLegendMode(mode) {
|
|
57
|
+
if (!mode || !isValidLegendMode(mode)) {
|
|
58
|
+
return DEFAULT_LEGEND.mode;
|
|
59
|
+
}
|
|
60
|
+
return mode;
|
|
61
|
+
}
|
|
40
62
|
export function validateLegendSpec(legend) {
|
|
41
63
|
if (legend === undefined) {
|
|
42
64
|
// undefined is valid since this is how legend is hidden by default
|
|
@@ -45,7 +67,15 @@ export function validateLegendSpec(legend) {
|
|
|
45
67
|
if (!isValidLegendPosition(legend.position)) {
|
|
46
68
|
return false;
|
|
47
69
|
}
|
|
70
|
+
if (legend.mode && !isValidLegendMode(legend.mode)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
48
73
|
return true;
|
|
49
74
|
}
|
|
75
|
+
export function isLegendItemVisuallySelected(item, selectedItems) {
|
|
76
|
+
// In the "ALL" case, technically all legend items are selected, but we do
|
|
77
|
+
// not render them differently.
|
|
78
|
+
return selectedItems !== 'ALL' && !!selectedItems[item.id];
|
|
79
|
+
}
|
|
50
80
|
|
|
51
81
|
//# 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\nimport { MouseEventHandler } from 'react';\n\nexport const legendPositions = ['Bottom', 'Right'] as const;\
|
|
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\nimport { MouseEventHandler } from 'react';\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 interface LegendOptions {\n position: LegendPositions;\n mode?: LegendMode;\n}\n\nexport interface LegendItem {\n id: string;\n label: string;\n color: string;\n onClick?: MouseEventHandler<HTMLElement>;\n}\n\nexport type LegendSingleSelectConfig = {\n label: string;\n};\n\n/**\n * State of selected items in the legend.\n * - When \"ALL\", all legend items are selected, but not visually highlighted.\n * - Otherwise, it is a Record that associates legend item ids with a boolean\n * value. When the associated entry for a legend item is `true`, that item\n * will be treated as selected and visually highlighted.\n */\nexport type SelectedLegendItemState = Record<LegendItem['id'], boolean> | 'ALL';\n\nexport const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendSingleSelectConfig>> = {\n Bottom: { label: 'Bottom' },\n Right: { label: 'Right' },\n};\n\nexport const LEGEND_MODE_CONFIG: Readonly<Record<LegendMode, LegendSingleSelectConfig>> = {\n List: { label: 'List' },\n Table: { label: 'Table' },\n};\n\nexport const DEFAULT_LEGEND: Required<LegendOptions> = {\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 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 getLegendMode(mode?: LegendMode) {\n if (!mode || !isValidLegendMode(mode)) {\n return DEFAULT_LEGEND.mode;\n }\n\n return mode;\n}\n\nexport function validateLegendSpec(legend?: LegendOptions) {\n if (legend === undefined) {\n // undefined is valid since this is how legend is hidden by default\n return true;\n }\n if (!isValidLegendPosition(legend.position)) {\n return false;\n }\n if (legend.mode && !isValidLegendMode(legend.mode)) {\n return false;\n }\n\n return true;\n}\n\nexport function isLegendItemVisuallySelected(item: LegendItem, selectedItems: SelectedLegendItemState) {\n // In the \"ALL\" case, technically all legend items are selected, but we do\n // not render them differently.\n return selectedItems !== 'ALL' && !!selectedItems[item.id];\n}\n"],"names":["legendPositions","legendModes","LEGEND_POSITIONS_CONFIG","Bottom","label","Right","LEGEND_MODE_CONFIG","List","Table","DEFAULT_LEGEND","position","mode","getLegendPosition","undefined","isValidLegendPosition","includes","isValidLegendMode","getLegendMode","validateLegendSpec","legend","isLegendItemVisuallySelected","item","selectedItems","id"],"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;IAAC,QAAQ;IAAE,OAAO;CAAC,AAAS,CAAC;AAG5D,OAAO,MAAMC,WAAW,GAAG;IAAC,MAAM;IAAE,OAAO;CAAC,AAAS,CAAC;AA4BtD,OAAO,MAAMC,uBAAuB,GAAgE;IAClGC,MAAM,EAAE;QAAEC,KAAK,EAAE,QAAQ;KAAE;IAC3BC,KAAK,EAAE;QAAED,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAME,kBAAkB,GAA2D;IACxFC,IAAI,EAAE;QAAEH,KAAK,EAAE,MAAM;KAAE;IACvBI,KAAK,EAAE;QAAEJ,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAMK,cAAc,GAA4B;IACrDC,QAAQ,EAAE,QAAQ;IAClBC,IAAI,EAAE,MAAM;CACb,CAAC;AAEF,OAAO,SAASC,iBAAiB,CAACF,QAA0B,EAAE;IAC5D,IAAIA,QAAQ,KAAKG,SAAS,EAAE;QAC1B,OAAOJ,cAAc,CAACC,QAAQ,CAAC;IACjC,CAAC;IACD,IAAII,qBAAqB,CAACJ,QAAQ,CAAC,EAAE;QACnC,OAAOA,QAAQ,CAAC;IAClB,CAAC;IACD,OAAOD,cAAc,CAACC,QAAQ,CAAC;AACjC,CAAC;AAED,OAAO,SAASI,qBAAqB,CAACJ,QAAyB,EAAE;IAC/D,OAAO,AAACV,eAAe,CAAuBe,QAAQ,CAACL,QAAQ,CAAC,CAAC;AACnE,CAAC;AAED,OAAO,SAASM,iBAAiB,CAACL,IAAgB,EAAE;IAClD,OAAO,AAACV,WAAW,CAAuBc,QAAQ,CAACJ,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED,OAAO,SAASM,aAAa,CAACN,IAAiB,EAAE;IAC/C,IAAI,CAACA,IAAI,IAAI,CAACK,iBAAiB,CAACL,IAAI,CAAC,EAAE;QACrC,OAAOF,cAAc,CAACE,IAAI,CAAC;IAC7B,CAAC;IAED,OAAOA,IAAI,CAAC;AACd,CAAC;AAED,OAAO,SAASO,kBAAkB,CAACC,MAAsB,EAAE;IACzD,IAAIA,MAAM,KAAKN,SAAS,EAAE;QACxB,mEAAmE;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAACC,qBAAqB,CAACK,MAAM,CAACT,QAAQ,CAAC,EAAE;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAIS,MAAM,CAACR,IAAI,IAAI,CAACK,iBAAiB,CAACG,MAAM,CAACR,IAAI,CAAC,EAAE;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,OAAO,SAASS,4BAA4B,CAACC,IAAgB,EAAEC,aAAsC,EAAE;IACrG,0EAA0E;IAC1E,+BAA+B;IAC/B,OAAOA,aAAa,KAAK,KAAK,IAAI,CAAC,CAACA,aAAa,CAACD,IAAI,CAACE,EAAE,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -8,6 +8,6 @@ export declare type BytesUnitOptions = {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
|
|
10
10
|
export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>>;
|
|
11
|
-
export declare function formatBytes(bytes: number,
|
|
11
|
+
export declare function formatBytes(bytes: number, options: BytesUnitOptions): string;
|
|
12
12
|
export {};
|
|
13
13
|
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import numbro from 'numbro';
|
|
14
|
-
import {
|
|
14
|
+
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
15
|
+
import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
|
|
16
|
+
const DEFAULT_NUMBRO_MANTISSA = 2;
|
|
15
17
|
const bytesUnitKinds = [
|
|
16
18
|
'Bytes'
|
|
17
19
|
];
|
|
@@ -21,41 +23,43 @@ export const BYTES_GROUP_CONFIG = {
|
|
|
21
23
|
abbreviate: true
|
|
22
24
|
};
|
|
23
25
|
export const BYTES_UNIT_CONFIG = {
|
|
24
|
-
//
|
|
25
|
-
// In other words,
|
|
26
|
+
// These units are powers of 1000.
|
|
27
|
+
// In other words, 1 KB = 1000 bytes.
|
|
26
28
|
Bytes: {
|
|
27
29
|
group: 'Bytes',
|
|
28
30
|
label: 'Bytes'
|
|
29
31
|
}
|
|
30
32
|
};
|
|
31
|
-
export function formatBytes(bytes,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits
|
|
36
|
-
if (decimal_places < 0) {
|
|
37
|
-
decimal_places = 0;
|
|
38
|
-
} else if (decimal_places > 20) {
|
|
39
|
-
decimal_places = 20;
|
|
40
|
-
}
|
|
41
|
-
const showFullNumber = abbreviate == false || bytes < 1000;
|
|
42
|
-
if (showFullNumber) {
|
|
43
|
-
const formatter = new Intl.NumberFormat('en-US', {
|
|
33
|
+
export function formatBytes(bytes, options) {
|
|
34
|
+
const { abbreviate , decimal_places } = options;
|
|
35
|
+
if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {
|
|
36
|
+
const formatterOptions = {
|
|
44
37
|
style: 'unit',
|
|
45
38
|
unit: 'byte',
|
|
46
39
|
unitDisplay: 'long',
|
|
47
|
-
maximumFractionDigits: decimal_places,
|
|
48
40
|
useGrouping: true
|
|
49
|
-
}
|
|
50
|
-
|
|
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);
|
|
51
52
|
}
|
|
53
|
+
// numbro is able to add units like KB, MB, GB, etc. correctly
|
|
52
54
|
return numbro(bytes).format({
|
|
53
55
|
output: 'byte',
|
|
54
56
|
base: 'decimal',
|
|
55
57
|
spaceSeparated: true,
|
|
56
|
-
mantissa: decimal_places,
|
|
57
|
-
trimMantissa
|
|
58
|
-
|
|
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)
|
|
59
63
|
});
|
|
60
64
|
}
|
|
61
65
|
|
|
@@ -1 +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 {
|
|
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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const MAX_SIGNIFICANT_DIGITS = 3;
|
|
2
2
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
// Common constants needed across individual unit groups and the overall
|
|
14
14
|
// combined units.
|
|
15
|
-
export const
|
|
15
|
+
export const MAX_SIGNIFICANT_DIGITS = 3;
|
|
16
16
|
|
|
17
17
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +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
|
|
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"}
|
|
@@ -6,8 +6,8 @@ export declare type DecimalUnitOptions = {
|
|
|
6
6
|
decimal_places?: number;
|
|
7
7
|
abbreviate?: boolean;
|
|
8
8
|
};
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
|
|
10
10
|
export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>>;
|
|
11
|
-
export declare function formatDecimal(value: number,
|
|
11
|
+
export declare function formatDecimal(value: number, options: DecimalUnitOptions): string;
|
|
12
12
|
export {};
|
|
13
13
|
//# sourceMappingURL=decimal.d.ts.map
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -10,13 +10,15 @@
|
|
|
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
|
-
import {
|
|
13
|
+
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
14
|
+
import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
|
|
14
15
|
const decimalUnitKinds = [
|
|
15
16
|
'Decimal'
|
|
16
17
|
];
|
|
17
|
-
export const
|
|
18
|
-
label: '
|
|
19
|
-
decimal_places: true
|
|
18
|
+
export const DECIMAL_GROUP_CONFIG = {
|
|
19
|
+
label: 'Decimal',
|
|
20
|
+
decimal_places: true,
|
|
21
|
+
abbreviate: true
|
|
20
22
|
};
|
|
21
23
|
export const DECIMAL_UNIT_CONFIG = {
|
|
22
24
|
Decimal: {
|
|
@@ -24,23 +26,24 @@ export const DECIMAL_UNIT_CONFIG = {
|
|
|
24
26
|
label: 'Decimal'
|
|
25
27
|
}
|
|
26
28
|
};
|
|
27
|
-
export function formatDecimal(value,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits
|
|
31
|
-
if (decimal_places < 0) {
|
|
32
|
-
decimal_places = 0;
|
|
33
|
-
} else if (decimal_places > 20) {
|
|
34
|
-
decimal_places = 20;
|
|
35
|
-
}
|
|
36
|
-
const showFullNumber = abbreviate == false || value < 1000;
|
|
37
|
-
const formatter = new Intl.NumberFormat('en-US', {
|
|
29
|
+
export function formatDecimal(value, options) {
|
|
30
|
+
const { abbreviate , decimal_places } = options;
|
|
31
|
+
const formatterOptions = {
|
|
38
32
|
style: 'decimal',
|
|
39
|
-
notation: showFullNumber ? 'standard' : 'compact',
|
|
40
|
-
maximumFractionDigits: decimal_places,
|
|
41
33
|
useGrouping: true
|
|
42
|
-
}
|
|
43
|
-
|
|
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);
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
//# sourceMappingURL=decimal.js.map
|
|
@@ -1 +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 {
|
|
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"}
|
|
@@ -5,8 +5,8 @@ export declare type PercentUnitOptions = {
|
|
|
5
5
|
kind: PercentUnitKind;
|
|
6
6
|
decimal_places?: number;
|
|
7
7
|
};
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const PERCENT_GROUP_CONFIG: UnitGroupConfig;
|
|
9
9
|
export declare const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>>;
|
|
10
|
-
export declare function formatPercent(value: number,
|
|
10
|
+
export declare function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string;
|
|
11
11
|
export {};
|
|
12
12
|
//# sourceMappingURL=percent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -10,16 +10,16 @@
|
|
|
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
|
-
import {
|
|
13
|
+
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
14
|
+
import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
|
|
14
15
|
const percentUnitKinds = [
|
|
15
16
|
'Percent',
|
|
16
17
|
'PercentDecimal',
|
|
17
18
|
'%'
|
|
18
19
|
];
|
|
19
|
-
export const
|
|
20
|
-
label: '
|
|
21
|
-
decimal_places: true
|
|
22
|
-
abbreviate: true
|
|
20
|
+
export const PERCENT_GROUP_CONFIG = {
|
|
21
|
+
label: 'Percent',
|
|
22
|
+
decimal_places: true
|
|
23
23
|
};
|
|
24
24
|
const PERCENT_GROUP = 'Percent';
|
|
25
25
|
export const PERCENT_UNIT_CONFIG = {
|
|
@@ -39,13 +39,22 @@ export const PERCENT_UNIT_CONFIG = {
|
|
|
39
39
|
label: '%'
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
-
export function formatPercent(value,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
value = value * 100;
|
|
42
|
+
export function formatPercent(value, { kind , decimal_places }) {
|
|
43
|
+
// Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
|
|
44
|
+
if (kind === 'Percent') {
|
|
45
|
+
value = value / 100;
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
const formatterOptions = {
|
|
48
|
+
style: 'percent',
|
|
49
|
+
useGrouping: true
|
|
50
|
+
};
|
|
51
|
+
if (hasDecimalPlaces(decimal_places)) {
|
|
52
|
+
formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
|
|
53
|
+
formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
|
|
54
|
+
} else {
|
|
55
|
+
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
56
|
+
}
|
|
57
|
+
return Intl.NumberFormat('en-US', formatterOptions).format(value);
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
//# sourceMappingURL=percent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/percent.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 { UnitGroupConfig, UnitConfig } from './types';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/percent.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 } from './utils';\n\nconst percentUnitKinds = ['Percent', 'PercentDecimal', '%'] as const;\ntype PercentUnitKind = (typeof percentUnitKinds)[number];\nexport type PercentUnitOptions = {\n kind: PercentUnitKind;\n decimal_places?: number;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Percent',\n decimal_places: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>> = {\n Percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n PercentDecimal: {\n group: PERCENT_GROUP,\n label: 'Percent (0.0-1.0)',\n },\n '%': {\n // This option is not shown in the selector because it is a shorthand\n // duplicate of `Percent`.\n disableSelectorOption: true,\n group: PERCENT_GROUP,\n label: '%',\n },\n};\n\nexport function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string {\n // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%\n if (kind === 'Percent') {\n value = value / 100;\n }\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'percent',\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 formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","percentUnitKinds","PERCENT_GROUP_CONFIG","label","decimal_places","PERCENT_GROUP","PERCENT_UNIT_CONFIG","Percent","group","PercentDecimal","disableSelectorOption","formatPercent","value","kind","formatterOptions","style","useGrouping","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,QAAQ,SAAS,CAAC;AAE/D,MAAMC,gBAAgB,GAAG;IAAC,SAAS;IAAE,gBAAgB;IAAE,GAAG;CAAC,AAAS,AAAC;AAMrE,OAAO,MAAMC,oBAAoB,GAAoB;IACnDC,KAAK,EAAE,SAAS;IAChBC,cAAc,EAAE,IAAI;CACrB,CAAC;AACF,MAAMC,aAAa,GAAG,SAAS,AAAC;AAChC,OAAO,MAAMC,mBAAmB,GAAkD;IAChFC,OAAO,EAAE;QACPC,KAAK,EAAEH,aAAa;QACpBF,KAAK,EAAE,iBAAiB;KACzB;IACDM,cAAc,EAAE;QACdD,KAAK,EAAEH,aAAa;QACpBF,KAAK,EAAE,mBAAmB;KAC3B;IACD,GAAG,EAAE;QACH,qEAAqE;QACrE,0BAA0B;QAC1BO,qBAAqB,EAAE,IAAI;QAC3BF,KAAK,EAAEH,aAAa;QACpBF,KAAK,EAAE,GAAG;KACX;CACF,CAAC;AAEF,OAAO,SAASQ,aAAa,CAACC,KAAa,EAAE,EAAEC,IAAI,CAAA,EAAET,cAAc,CAAA,EAAsB,EAAU;IACjG,8DAA8D;IAC9D,IAAIS,IAAI,KAAK,SAAS,EAAE;QACtBD,KAAK,GAAGA,KAAK,GAAG,GAAG,CAAC;IACtB,CAAC;IAED,MAAME,gBAAgB,GAA6B;QACjDC,KAAK,EAAE,SAAS;QAChBC,WAAW,EAAE,IAAI;KAClB,AAAC;IAEF,IAAIjB,gBAAgB,CAACK,cAAc,CAAC,EAAE;QACpCU,gBAAgB,CAACG,qBAAqB,GAAGjB,kBAAkB,CAACI,cAAc,CAAC,CAAC;QAC5EU,gBAAgB,CAACI,qBAAqB,GAAGlB,kBAAkB,CAACI,cAAc,CAAC,CAAC;IAC9E,OAAO;QACLU,gBAAgB,CAACK,wBAAwB,GAAGrB,sBAAsB,CAAC;IACrE,CAAC;IAED,OAAOsB,IAAI,CAACC,YAAY,CAAC,OAAO,EAAEP,gBAAgB,CAAC,CAACQ,MAAM,CAACV,KAAK,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -7,7 +7,7 @@ export declare type TimeUnitOptions = {
|
|
|
7
7
|
};
|
|
8
8
|
export declare const TIME_GROUP_CONFIG: UnitGroupConfig;
|
|
9
9
|
export declare const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>>;
|
|
10
|
-
export declare enum
|
|
10
|
+
export declare enum PersesTimeToIntlTime {
|
|
11
11
|
Milliseconds = "millisecond",
|
|
12
12
|
Seconds = "second",
|
|
13
13
|
Minutes = "minute",
|
|
@@ -17,6 +17,6 @@ export declare enum TimeIntlDuration {
|
|
|
17
17
|
Months = "month",
|
|
18
18
|
Years = "year"
|
|
19
19
|
}
|
|
20
|
-
export declare function formatTime(value: number,
|
|
20
|
+
export declare function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string;
|
|
21
21
|
export {};
|
|
22
22
|
//# sourceMappingURL=time.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AACnH,aAAK,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAG/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAiCvE,CAAC;AAIF,oBAAY,oBAAoB;IAC9B,YAAY,gBAAgB;IAC5B,OAAO,WAAW;IAClB,OAAO,WAAW;IAClB,KAAK,SAAS;IACd,IAAI,QAAQ;IACZ,KAAK,SAAS;IACd,MAAM,UAAU;IAChB,KAAK,SAAS;CACf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,eAAe,GAAG,MAAM,CAiB3F"}
|
package/dist/model/units/time.js
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
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
|
-
import {
|
|
13
|
+
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
14
|
+
import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
|
|
14
15
|
const timeUnitKinds = [
|
|
15
16
|
'Milliseconds',
|
|
16
17
|
'Seconds',
|
|
@@ -60,28 +61,31 @@ export const TIME_UNIT_CONFIG = {
|
|
|
60
61
|
label: 'Years'
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
|
-
export var
|
|
64
|
-
(function(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})(
|
|
74
|
-
export function formatTime(value,
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
const timeUnit = TimeIntlDuration[unitOptions.kind];
|
|
78
|
-
const formatter = new Intl.NumberFormat('en-US', {
|
|
64
|
+
export var PersesTimeToIntlTime;
|
|
65
|
+
(function(PersesTimeToIntlTime) {
|
|
66
|
+
PersesTimeToIntlTime["Milliseconds"] = 'millisecond';
|
|
67
|
+
PersesTimeToIntlTime["Seconds"] = 'second';
|
|
68
|
+
PersesTimeToIntlTime["Minutes"] = 'minute';
|
|
69
|
+
PersesTimeToIntlTime["Hours"] = 'hour';
|
|
70
|
+
PersesTimeToIntlTime["Days"] = 'day';
|
|
71
|
+
PersesTimeToIntlTime["Weeks"] = 'week';
|
|
72
|
+
PersesTimeToIntlTime["Months"] = 'month';
|
|
73
|
+
PersesTimeToIntlTime["Years"] = 'year';
|
|
74
|
+
})(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
|
|
75
|
+
export function formatTime(value, { kind , decimal_places }) {
|
|
76
|
+
const isMonthOrYear = kind === 'Months' || kind === 'Years';
|
|
77
|
+
const formatterOptions = {
|
|
79
78
|
style: 'unit',
|
|
80
|
-
unit:
|
|
81
|
-
unitDisplay: 'long'
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
unit: PersesTimeToIntlTime[kind],
|
|
80
|
+
unitDisplay: isMonthOrYear ? 'long' : 'narrow'
|
|
81
|
+
};
|
|
82
|
+
if (hasDecimalPlaces(decimal_places)) {
|
|
83
|
+
formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
|
|
84
|
+
formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
|
|
85
|
+
} else {
|
|
86
|
+
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
87
|
+
}
|
|
88
|
+
return Intl.NumberFormat('en-US', formatterOptions).format(value);
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
//# sourceMappingURL=time.js.map
|