@grafana/components 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +393 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +142 -3
- package/dist/esm/components/ComparisonBadge/ComparisonBadge.styles.js +2 -2
- package/dist/esm/components/ComparisonBadge/ComparisonBadge.styles.js.map +1 -1
- package/dist/esm/components/ComparisonTooltip/ComparisonTooltip.styles.js +2 -2
- package/dist/esm/components/ComparisonTooltip/ComparisonTooltip.styles.js.map +1 -1
- package/dist/esm/components/GenericSkeleton/GenericSkeleton.js +14 -0
- package/dist/esm/components/GenericSkeleton/GenericSkeleton.js.map +1 -0
- package/dist/esm/components/GenericSkeleton/GenericSkeleton.styles.js +47 -0
- package/dist/esm/components/GenericSkeleton/GenericSkeleton.styles.js.map +1 -0
- package/dist/esm/components/Popover/Popover.styles.js +2 -2
- package/dist/esm/components/StackedChart/StackedChart.js +158 -0
- package/dist/esm/components/StackedChart/StackedChart.js.map +1 -0
- package/dist/esm/components/StackedChart/StackedChart.styles.js +19 -0
- package/dist/esm/components/StackedChart/StackedChart.styles.js.map +1 -0
- package/dist/esm/components/StackedChart/shared.styles.js +6 -0
- package/dist/esm/components/StackedChart/shared.styles.js.map +1 -0
- package/dist/esm/components/StackedChartSegment/StackedChartSegment.js +32 -0
- package/dist/esm/components/StackedChartSegment/StackedChartSegment.js.map +1 -0
- package/dist/esm/components/StackedChartSegment/StackedChartSegment.styles.js +45 -0
- package/dist/esm/components/StackedChartSegment/StackedChartSegment.styles.js.map +1 -0
- package/dist/esm/components/StackedChartSegmentTooltip/StackedChartSegmentTooltip.js +40 -0
- package/dist/esm/components/StackedChartSegmentTooltip/StackedChartSegmentTooltip.js.map +1 -0
- package/dist/esm/components/StackedChartSegmentTooltip/StackedChartSegmentTooltip.styles.js +53 -0
- package/dist/esm/components/StackedChartSegmentTooltip/StackedChartSegmentTooltip.styles.js.map +1 -0
- package/dist/esm/components/StackedChartSkeleton/StackedChartSkeleton.js +11 -0
- package/dist/esm/components/StackedChartSkeleton/StackedChartSkeleton.js.map +1 -0
- package/dist/esm/components/StackedChartSkeleton/StackedChartSkeleton.styles.js +13 -0
- package/dist/esm/components/StackedChartSkeleton/StackedChartSkeleton.styles.js.map +1 -0
- package/dist/esm/index.d.ts +142 -3
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenericSkeleton.styles.js","sources":["../../../../src/components/GenericSkeleton/GenericSkeleton.styles.ts"],"sourcesContent":["import { css, keyframes } from '@emotion/css';\nimport { CSSVariables, getDesignTokens } from '@grafana/design-tokens';\n\nexport const cssVariables = (): CSSVariables => {\n const { legacy } = getDesignTokens({ valueType: 'css' });\n\n return {\n dark: {\n 'skeleton-gradient-background-color': legacy.palette.whiteBaseOpacity12,\n },\n light: {\n 'skeleton-gradient-background-color': legacy.palette.blackBaseOpacity12,\n },\n };\n};\n\nconst shimmer = keyframes({\n '0%': {\n transform: 'translateX(-100%);',\n },\n '100%': {\n transform: 'translateX(100%);',\n },\n});\n\nexport const getStyles = (animationDuration: number) => {\n return css({\n display: 'flex',\n width: '100%',\n height: '100%',\n background: 'transparent',\n position: 'relative',\n overflow: 'hidden',\n borderRadius: '5px',\n '&::before': {\n content: \"''\",\n position: 'absolute',\n top: 0,\n left: 0,\n width: '100%',\n height: '100%',\n animation: `${shimmer} ${animationDuration}s ease-in-out infinite`,\n transform: 'translateX(-100%)',\n background:\n 'linear-gradient(90deg, transparent, var(--skeleton-gradient-background-color), transparent)',\n },\n });\n};\n"],"names":["getStyles"],"mappings":";;;AAGO,MAAM,eAAe,MAAoB;AAC9C,EAAA,MAAM,EAAE,MAAA,EAAO,GAAI,gBAAgB,EAAE,SAAA,EAAW,OAAO,CAAA;AAEvD,EAAA,OAAO;AAAA,IACL,IAAA,EAAM;AAAA,MACJ,oCAAA,EAAsC,OAAO,OAAA,CAAQ;AAAA,KACvD;AAAA,IACA,KAAA,EAAO;AAAA,MACL,oCAAA,EAAsC,OAAO,OAAA,CAAQ;AAAA;AACvD,GACF;AACF;AAEA,MAAM,UAAU,SAAA,CAAU;AAAA,EACxB,IAAA,EAAM;AAAA,IACJ,SAAA,EAAW;AAAA,GACb;AAAA,EACA,MAAA,EAAQ;AAAA,IACN,SAAA,EAAW;AAAA;AAEf,CAAC,CAAA;AAEM,MAAMA,WAAA,GAAY,CAAC,iBAAA,KAA8B;AACtD,EAAA,OAAO,GAAA,CAAI;AAAA,IACT,OAAA,EAAS,MAAA;AAAA,IACT,KAAA,EAAO,MAAA;AAAA,IACP,MAAA,EAAQ,MAAA;AAAA,IACR,UAAA,EAAY,aAAA;AAAA,IACZ,QAAA,EAAU,UAAA;AAAA,IACV,QAAA,EAAU,QAAA;AAAA,IACV,YAAA,EAAc,KAAA;AAAA,IACd,WAAA,EAAa;AAAA,MACX,OAAA,EAAS,IAAA;AAAA,MACT,QAAA,EAAU,UAAA;AAAA,MACV,GAAA,EAAK,CAAA;AAAA,MACL,IAAA,EAAM,CAAA;AAAA,MACN,KAAA,EAAO,MAAA;AAAA,MACP,MAAA,EAAQ,MAAA;AAAA,MACR,SAAA,EAAW,CAAA,EAAG,OAAO,CAAA,CAAA,EAAI,iBAAiB,CAAA,sBAAA,CAAA;AAAA,MAC1C,SAAA,EAAW,mBAAA;AAAA,MACX,UAAA,EACE;AAAA;AACJ,GACD,CAAA;AACH;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { css } from '@emotion/css';
|
|
2
2
|
import { getDesignTokens } from '@grafana/design-tokens';
|
|
3
3
|
|
|
4
|
-
const getStyles$
|
|
4
|
+
const getStyles$6 = () => {
|
|
5
5
|
const {
|
|
6
6
|
legacy,
|
|
7
7
|
primitives: { spacing, typography }
|
|
@@ -25,5 +25,5 @@ const getStyles$1 = () => {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export { getStyles$
|
|
28
|
+
export { getStyles$6 as getStyles };
|
|
29
29
|
//# sourceMappingURL=Popover.styles.js.map
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useState, useMemo } from 'react';
|
|
3
|
+
import { StackedChartSegment } from '../StackedChartSegment/StackedChartSegment.js';
|
|
4
|
+
import { getStyles } from './StackedChart.styles.js';
|
|
5
|
+
import { StackedChartSegmentTooltip } from '../StackedChartSegmentTooltip/StackedChartSegmentTooltip.js';
|
|
6
|
+
import { StackedChartSkeleton } from '../StackedChartSkeleton/StackedChartSkeleton.js';
|
|
7
|
+
|
|
8
|
+
const StackedChart = ({
|
|
9
|
+
categories: _categories,
|
|
10
|
+
highlightedCategoryId: initialHighlightedCategoryId,
|
|
11
|
+
isSkeleton = false,
|
|
12
|
+
isDimmed = false,
|
|
13
|
+
sortOrder = "largest-first",
|
|
14
|
+
height = 24,
|
|
15
|
+
onSegmentMouseOver,
|
|
16
|
+
onSegmentMouseOut
|
|
17
|
+
}) => {
|
|
18
|
+
if (isSkeleton || !_categories) return /* @__PURE__ */ jsx(StackedChartSkeleton, { height });
|
|
19
|
+
let highlightedSegmentRef = useRef(null);
|
|
20
|
+
const [highlightedCategoryId, setHighlightedCategoryId] = useState(
|
|
21
|
+
/**
|
|
22
|
+
* Using a type assertion here ultimately because you can’t pass a generic
|
|
23
|
+
* type argument to the type of props in React.forwardRef (it is inferred as
|
|
24
|
+
* of type string).
|
|
25
|
+
*
|
|
26
|
+
* See: https://stackoverflow.com/questions/51884498/using-react-forwardref-with-typescript-generic-jsx-arguments
|
|
27
|
+
*/
|
|
28
|
+
initialHighlightedCategoryId
|
|
29
|
+
);
|
|
30
|
+
const [isHovered, setHovered] = useState(false);
|
|
31
|
+
const timer = useRef(void 0);
|
|
32
|
+
const categories = useMemo(() => {
|
|
33
|
+
switch (sortOrder) {
|
|
34
|
+
case "largest-first":
|
|
35
|
+
case "smallest-first":
|
|
36
|
+
default:
|
|
37
|
+
return _categories;
|
|
38
|
+
}
|
|
39
|
+
}, [_categories, sortOrder]);
|
|
40
|
+
const total = useMemo(() => {
|
|
41
|
+
const roundedTotal = Math.round(
|
|
42
|
+
Object.entries(categories).reduce(
|
|
43
|
+
(sum, [, category]) => sum + category.value,
|
|
44
|
+
0
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
if (roundedTotal > 100) {
|
|
48
|
+
console.error(`StackedChartCategories have a total value exceeding 100% (${roundedTotal})`);
|
|
49
|
+
} else {
|
|
50
|
+
console.info(`Total of all category value values is ${roundedTotal}`);
|
|
51
|
+
}
|
|
52
|
+
return roundedTotal;
|
|
53
|
+
}, [categories]);
|
|
54
|
+
const styles = getStyles({ height });
|
|
55
|
+
const onMouseOver = ({ ref, categoryId }) => () => {
|
|
56
|
+
clearTimeout(timer.current);
|
|
57
|
+
setHovered(true);
|
|
58
|
+
if (!initialHighlightedCategoryId) {
|
|
59
|
+
setHighlightedCategoryId(categoryId);
|
|
60
|
+
}
|
|
61
|
+
if (onSegmentMouseOver) onSegmentMouseOver({ ref, categoryId });
|
|
62
|
+
};
|
|
63
|
+
const onMouseOut = ({ ref, categoryId }) => () => {
|
|
64
|
+
timer.current = window.setTimeout(() => {
|
|
65
|
+
setHovered(false);
|
|
66
|
+
if (!initialHighlightedCategoryId) {
|
|
67
|
+
setHighlightedCategoryId(void 0);
|
|
68
|
+
}
|
|
69
|
+
}, 50);
|
|
70
|
+
if (onSegmentMouseOut) onSegmentMouseOut({ ref, categoryId });
|
|
71
|
+
};
|
|
72
|
+
const highlightedCategory = initialHighlightedCategoryId ? {
|
|
73
|
+
...categories[initialHighlightedCategoryId],
|
|
74
|
+
index: Object.keys(categories).indexOf(initialHighlightedCategoryId)
|
|
75
|
+
} : void 0;
|
|
76
|
+
const content = /* @__PURE__ */ jsx("div", { className: styles.container, children: Object.entries(categories).map(
|
|
77
|
+
([categoryId, category], categoryIndex) => {
|
|
78
|
+
const ref = useRef(null);
|
|
79
|
+
if (categoryId === initialHighlightedCategoryId) highlightedSegmentRef = ref;
|
|
80
|
+
const segmentState = (() => {
|
|
81
|
+
switch (true) {
|
|
82
|
+
/**
|
|
83
|
+
* If no initial highlighted category was set, and a category is
|
|
84
|
+
* moused over, use the _active_ state for that category rather
|
|
85
|
+
* than the color state; this adds a drop shadow to the segment.
|
|
86
|
+
* Also, if an initial highlighted category _was_ set, and it
|
|
87
|
+
* receives a hover event, also set it to active.
|
|
88
|
+
*/
|
|
89
|
+
case (!initialHighlightedCategoryId && highlightedCategoryId === categoryId && !isDimmed):
|
|
90
|
+
case (initialHighlightedCategoryId === categoryId && isHovered && !isDimmed):
|
|
91
|
+
return "active";
|
|
92
|
+
/**
|
|
93
|
+
* - no initial highlighted category ID was passed _and_ there is
|
|
94
|
+
* no highlightedCategoryId (i.e. all segments in colour)
|
|
95
|
+
* - the highlighted category is this category (but the chart
|
|
96
|
+
* isn’t dimmed)
|
|
97
|
+
* - the initial highlighted category is this category (but the
|
|
98
|
+
* chart isn’t dimmed)
|
|
99
|
+
*/
|
|
100
|
+
case (!initialHighlightedCategoryId && !highlightedCategoryId && !isDimmed):
|
|
101
|
+
case (initialHighlightedCategoryId === categoryId && !isDimmed):
|
|
102
|
+
return "color";
|
|
103
|
+
/**
|
|
104
|
+
* Has an initial highlighted category, but is dimmed (i.e. all
|
|
105
|
+
* segments excepted the highlighted category)
|
|
106
|
+
*/
|
|
107
|
+
case (Boolean(initialHighlightedCategoryId) && initialHighlightedCategoryId !== categoryId && isDimmed):
|
|
108
|
+
case (!initialHighlightedCategoryId && !highlightedCategoryId && isDimmed):
|
|
109
|
+
case (highlightedCategoryId !== categoryId && isDimmed):
|
|
110
|
+
return "dimmed";
|
|
111
|
+
/**
|
|
112
|
+
* In any other case, the segment should be the default grey
|
|
113
|
+
*/
|
|
114
|
+
default:
|
|
115
|
+
return "default";
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
const segment = /* @__PURE__ */ jsx(
|
|
119
|
+
StackedChartSegment,
|
|
120
|
+
{
|
|
121
|
+
ref,
|
|
122
|
+
categoryId,
|
|
123
|
+
index: categoryIndex,
|
|
124
|
+
title: category.title,
|
|
125
|
+
value: category.value,
|
|
126
|
+
total,
|
|
127
|
+
state: segmentState,
|
|
128
|
+
onMouseOver,
|
|
129
|
+
onMouseOut
|
|
130
|
+
},
|
|
131
|
+
categoryId
|
|
132
|
+
);
|
|
133
|
+
return initialHighlightedCategoryId ? segment : /* @__PURE__ */ jsx(
|
|
134
|
+
StackedChartSegmentTooltip,
|
|
135
|
+
{
|
|
136
|
+
title: category.title,
|
|
137
|
+
value: category.value,
|
|
138
|
+
index: categoryIndex,
|
|
139
|
+
hideDelay: 0,
|
|
140
|
+
trigger: segment
|
|
141
|
+
},
|
|
142
|
+
categoryId
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
) });
|
|
146
|
+
return initialHighlightedCategoryId && highlightedCategory ? /* @__PURE__ */ jsx(
|
|
147
|
+
StackedChartSegmentTooltip,
|
|
148
|
+
{
|
|
149
|
+
hideDelay: 0,
|
|
150
|
+
trigger: content,
|
|
151
|
+
virtualElement: highlightedSegmentRef,
|
|
152
|
+
...highlightedCategory
|
|
153
|
+
}
|
|
154
|
+
) : content;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export { StackedChart };
|
|
158
|
+
//# sourceMappingURL=StackedChart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StackedChart.js","sources":["../../../../src/components/StackedChart/StackedChart.tsx"],"sourcesContent":["import { useMemo, useRef, useState } from 'react';\nimport { StackedChartSegment } from '../StackedChartSegment';\nimport { getStyles } from './StackedChart.styles';\nimport { StackedChartSegmentState, SegmentMouseEventHandler } from '../StackedChartSegment/types';\nimport { StackedChartSegmentTooltip } from '../StackedChartSegmentTooltip';\nimport { StackedChartSkeleton } from '../StackedChartSkeleton/StackedChartSkeleton';\n\nexport interface StackedChartCategory {\n title: string;\n value: number;\n}\n\nexport type StackedChartCategories<T extends string> = Record<T, StackedChartCategory>;\n\nexport type StackedChartSortOrder = 'largest-first' | 'smallest-first' | 'natural';\n\ntype MouseEventHandler = ({\n categoryId,\n ref,\n}: {\n categoryId: string;\n ref: React.ForwardedRef<HTMLDivElement>;\n}) => void;\n\nexport interface CommonStackedChartProps<T extends string> {\n /**\n * How should category segments be sorted?\n */\n sortOrder?: StackedChartSortOrder;\n\n /**\n * Height to render the stacked chart, in pixels\n */\n height?: number;\n\n /**\n * initial category ID to highlight; if omitted then all segments will render\n * in colour and highlight based on mouseover events.\n */\n highlightedCategoryId?: T;\n\n /**\n * Should the whole StackedChart be dimmed, i.e. with a highlighted category\n * not in color, all other categories faded out?\n */\n isDimmed?: boolean;\n\n /**\n * Event handler for whenever a segment gets a mouseover event\n */\n onSegmentMouseOver?: MouseEventHandler;\n\n /**\n * Event handler for whenever a segment gets a mouseout event\n */\n onSegmentMouseOut?: MouseEventHandler;\n}\n\nexport interface SkeletonStackedChartProps<T extends string> extends CommonStackedChartProps<T> {\n isSkeleton: true;\n\n /**\n * Array of StackedChartCategory to build the chart from\n */\n categories?: StackedChartCategories<T>;\n}\n\nexport interface LoadedStackedChartProps<T extends string> extends CommonStackedChartProps<T> {\n isSkeleton?: false;\n\n /**\n * Array of StackedChartCategory to build the chart from\n */\n categories: StackedChartCategories<T>;\n}\n\nexport type StackedChartProps<T extends string> =\n | SkeletonStackedChartProps<T>\n | LoadedStackedChartProps<T>;\n\nexport const StackedChart = <T extends string>({\n categories: _categories,\n highlightedCategoryId: initialHighlightedCategoryId,\n isSkeleton = false,\n isDimmed = false,\n sortOrder = 'largest-first',\n height = 24,\n onSegmentMouseOver,\n onSegmentMouseOut,\n}: StackedChartProps<T>) => {\n if (isSkeleton || !_categories) return <StackedChartSkeleton height={height} />;\n\n let highlightedSegmentRef = useRef<HTMLDivElement>(null);\n const [highlightedCategoryId, setHighlightedCategoryId] = useState<string | undefined>(\n /**\n * Using a type assertion here ultimately because you can’t pass a generic\n * type argument to the type of props in React.forwardRef (it is inferred as\n * of type string).\n *\n * See: https://stackoverflow.com/questions/51884498/using-react-forwardref-with-typescript-generic-jsx-arguments\n */\n initialHighlightedCategoryId as string,\n );\n const [isHovered, setHovered] = useState<boolean>(false);\n const timer = useRef<number | undefined>(undefined);\n\n /**\n * Sort categories according to the sortOrder prop\n */\n const categories = useMemo(() => {\n switch (sortOrder) {\n case 'largest-first':\n case 'smallest-first':\n default:\n return _categories;\n }\n }, [_categories, sortOrder]);\n\n /**\n * Determine what the total value is for all category valeus combined\n */\n const total = useMemo(() => {\n const roundedTotal = Math.round(\n Object.entries<StackedChartCategory>(categories).reduce(\n (sum, [, category]) => sum + category.value,\n 0,\n ),\n );\n\n if (roundedTotal > 100) {\n console.error(`StackedChartCategories have a total value exceeding 100% (${roundedTotal})`);\n } else {\n console.info(`Total of all category value values is ${roundedTotal}`);\n }\n\n return roundedTotal;\n }, [categories]);\n\n const styles = getStyles({ height });\n\n const onMouseOver: SegmentMouseEventHandler =\n ({ ref, categoryId }) =>\n () => {\n clearTimeout(timer.current);\n setHovered(true);\n\n /**\n * Only update the highlighted category ID if an initial category wasn’t\n * supplied\n */\n if (!initialHighlightedCategoryId) {\n setHighlightedCategoryId(categoryId);\n }\n\n if (onSegmentMouseOver) onSegmentMouseOver({ ref, categoryId });\n };\n\n const onMouseOut: SegmentMouseEventHandler =\n ({ ref, categoryId }) =>\n () => {\n /**\n * TODO: rather than use a timeout, maybe use the parent element being\n * moused over (event bubbling?) to validate whether the mouse has left\n * the entire chart vs an individual segment?\n */\n timer.current = window.setTimeout(() => {\n setHovered(false);\n /**\n * Only clear the highlighted category if an initial category wasn’t\n * supplied\n */\n if (!initialHighlightedCategoryId) {\n setHighlightedCategoryId(undefined);\n }\n }, 50);\n\n if (onSegmentMouseOut) onSegmentMouseOut({ ref, categoryId });\n };\n\n const highlightedCategory: (StackedChartCategory & { index: number }) | undefined =\n initialHighlightedCategoryId\n ? {\n ...categories[initialHighlightedCategoryId],\n index: Object.keys(categories).indexOf(initialHighlightedCategoryId),\n }\n : undefined;\n\n const content = (\n <div className={styles.container}>\n {Object.entries<StackedChartCategory>(categories).map(\n ([categoryId, category], categoryIndex) => {\n const ref = useRef<HTMLDivElement>(null);\n if (categoryId === initialHighlightedCategoryId) highlightedSegmentRef = ref;\n\n const segmentState = ((): StackedChartSegmentState => {\n switch (true) {\n /**\n * If no initial highlighted category was set, and a category is\n * moused over, use the _active_ state for that category rather\n * than the color state; this adds a drop shadow to the segment.\n * Also, if an initial highlighted category _was_ set, and it\n * receives a hover event, also set it to active.\n */\n case !initialHighlightedCategoryId &&\n highlightedCategoryId === categoryId &&\n !isDimmed:\n case initialHighlightedCategoryId === categoryId && isHovered && !isDimmed:\n return 'active';\n\n /**\n * - no initial highlighted category ID was passed _and_ there is\n * no highlightedCategoryId (i.e. all segments in colour)\n * - the highlighted category is this category (but the chart\n * isn’t dimmed)\n * - the initial highlighted category is this category (but the\n * chart isn’t dimmed)\n */\n case !initialHighlightedCategoryId && !highlightedCategoryId && !isDimmed:\n case initialHighlightedCategoryId === categoryId && !isDimmed:\n return 'color';\n\n /**\n * Has an initial highlighted category, but is dimmed (i.e. all\n * segments excepted the highlighted category)\n */\n case Boolean(initialHighlightedCategoryId) &&\n initialHighlightedCategoryId !== categoryId &&\n isDimmed:\n case !initialHighlightedCategoryId && !highlightedCategoryId && isDimmed:\n case highlightedCategoryId !== categoryId && isDimmed:\n return 'dimmed';\n\n /**\n * In any other case, the segment should be the default grey\n */\n default:\n return 'default';\n }\n })();\n\n const segment = (\n <StackedChartSegment\n key={categoryId}\n ref={ref}\n categoryId={categoryId}\n index={categoryIndex}\n title={category.title}\n value={category.value}\n total={total}\n state={segmentState}\n onMouseOver={onMouseOver}\n onMouseOut={onMouseOut}\n />\n );\n\n /**\n * Only wrap the segment in a tooltip if no initially highlighted\n * category ID was supplied.\n */\n return initialHighlightedCategoryId ? (\n segment\n ) : (\n <StackedChartSegmentTooltip\n key={categoryId}\n title={category.title}\n value={category.value}\n index={categoryIndex}\n hideDelay={0}\n trigger={segment}\n />\n );\n },\n )}\n </div>\n );\n\n /**\n * If an initial highlight category was provided, wrap the entire chart inside\n * a tooltip using the props for the highlighted segment to drive the tooltip\n * content.\n */\n return initialHighlightedCategoryId && highlightedCategory ? (\n <StackedChartSegmentTooltip\n hideDelay={0}\n trigger={content}\n virtualElement={highlightedSegmentRef}\n {...highlightedCategory}\n />\n ) : (\n content\n );\n};\n"],"names":[],"mappings":";;;;;;;AAgFO,MAAM,eAAe,CAAmB;AAAA,EAC7C,UAAA,EAAY,WAAA;AAAA,EACZ,qBAAA,EAAuB,4BAAA;AAAA,EACvB,UAAA,GAAa,KAAA;AAAA,EACb,QAAA,GAAW,KAAA;AAAA,EACX,SAAA,GAAY,eAAA;AAAA,EACZ,MAAA,GAAS,EAAA;AAAA,EACT,kBAAA;AAAA,EACA;AACF,CAAA,KAA4B;AAC1B,EAAA,IAAI,cAAc,CAAC,WAAA,EAAa,uBAAO,GAAA,CAAC,wBAAqB,MAAA,EAAgB,CAAA;AAE7E,EAAA,IAAI,qBAAA,GAAwB,OAAuB,IAAI,CAAA;AACvD,EAAA,MAAM,CAAC,qBAAA,EAAuB,wBAAwB,CAAA,GAAI,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQxD;AAAA,GACF;AACA,EAAA,MAAM,CAAC,SAAA,EAAW,UAAU,CAAA,GAAI,SAAkB,KAAK,CAAA;AACvD,EAAA,MAAM,KAAA,GAAQ,OAA2B,MAAS,CAAA;AAKlD,EAAA,MAAM,UAAA,GAAa,QAAQ,MAAM;AAC/B,IAAA,QAAQ,SAAA;AAAW,MACjB,KAAK,eAAA;AAAA,MACL,KAAK,gBAAA;AAAA,MACL;AACE,QAAA,OAAO,WAAA;AAAA;AACX,EACF,CAAA,EAAG,CAAC,WAAA,EAAa,SAA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IAAyB,QAAA;AAAA,UAChE,MAAK,0BAA0B,UAAA,IAAc,QAAA;AAC3C,YAAA,OAAO,QAAA;AAAA;AAAA;AAAA;AAAA,UAKT;AACE,YAAA,OAAO,SAAA;AAAA;AACX,MACF,CAAA,GAAG;AAEH,MAAA,MAAM,OAAA,mBACJ,GAAA;AAAA,QAAC,mBAAA;AAAA,QAAA;AAAA,UAEC,GAAA;AAAA,UACA,UAAA;AAAA,UACA,KAAA,EAAO,aAAA;AAAA,UACP,OAAO,QAAA,CAAS,KAAA;AAAA,UAChB,OAAO,QAAA,CAAS,KAAA;AAAA,UAChB,KAAA;AAAA,UACA,KAAA,EAAO,YAAA;AAAA,UACP,WAAA;AAAA,UACA;AAAA,SAAA;AAAA,QATK;AAAA,OAUP;AAOF,MAAA,OAAO,+BACL,OAAA,mBAEA,GAAA;AAAA,QAAC,0BAAA;AAAA,QAAA;AAAA,UAEC,OAAO,QAAA,CAAS,KAAA;AAAA,UAChB,OAAO,QAAA,CAAS,KAAA;AAAA,UAChB,KAAA,EAAO,aAAA;AAAA,UACP,SAAA,EAAW,CAAA;AAAA,UACX,OAAA,EAAS;AAAA,SAAA;AAAA,QALJ;AAAA,OAMP;AAAA,IAEJ;AAAA,GACF,EACF,CAAA;AAQF,EAAA,OAAO,gCAAgC,mBAAA,mBACrC,GAAA;AAAA,IAAC,0BAAA;AAAA,IAAA;AAAA,MACC,SAAA,EAAW,CAAA;AAAA,MACX,OAAA,EAAS,OAAA;AAAA,MACT,cAAA,EAAgB,qBAAA;AAAA,MACf,GAAG;AAAA;AAAA,GACN,GAEA,OAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { css } from '@emotion/css';
|
|
2
|
+
import { getDesignTokens } from '@grafana/design-tokens';
|
|
3
|
+
|
|
4
|
+
const getStyles$2 = ({ height }) => {
|
|
5
|
+
const {
|
|
6
|
+
primitives: { spacing }
|
|
7
|
+
} = getDesignTokens({ valueType: "css" });
|
|
8
|
+
return {
|
|
9
|
+
container: css({
|
|
10
|
+
display: "flex",
|
|
11
|
+
width: "100%",
|
|
12
|
+
height,
|
|
13
|
+
gap: spacing.xxs
|
|
14
|
+
})
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { getStyles$2 as getStyles };
|
|
19
|
+
//# sourceMappingURL=StackedChart.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StackedChart.styles.js","sources":["../../../../src/components/StackedChart/StackedChart.styles.ts"],"sourcesContent":["import { css } from '@emotion/css';\nimport { getDesignTokens } from '@grafana/design-tokens';\n\nexport const getStyles = ({ height }: { height: number }) => {\n const {\n primitives: { spacing },\n } = getDesignTokens({ valueType: 'css' });\n\n return {\n container: css({\n display: 'flex',\n width: '100%',\n height,\n gap: spacing.xxs,\n }),\n };\n};\n\nexport const diagonalStripedBackground = ({\n stripeColor,\n stripeWidth = 2,\n gapWidth = 6,\n}: {\n stripeColor: string;\n stripeWidth?: number;\n gapWidth?: number;\n}) => {\n return `repeating-linear-gradient(\n -45deg,\n ${stripeColor},\n ${stripeColor} ${stripeWidth}px,\n transparent ${stripeWidth}px,\n transparent ${gapWidth}px)`;\n};\n"],"names":["getStyles"],"mappings":";;;AAGO,MAAMA,WAAA,GAAY,CAAC,EAAE,MAAA,EAAO,KAA0B;AAC3D,EAAA,MAAM;AAAA,IACJ,UAAA,EAAY,EAAE,OAAA;AAAQ,GACxB,GAAI,eAAA,CAAgB,EAAE,SAAA,EAAW,OAAO,CAAA;AAExC,EAAA,OAAO;AAAA,IACL,WAAW,GAAA,CAAI;AAAA,MACb,OAAA,EAAS,MAAA;AAAA,MACT,KAAA,EAAO,MAAA;AAAA,MACP,MAAA;AAAA,MACA,KAAK,OAAA,CAAQ;AAAA,KACd;AAAA,GACH;AACF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.styles.js","sources":["../../../../src/components/StackedChart/shared.styles.ts"],"sourcesContent":["/**\n * Apply a filter to rotate the hue by 10 degrees per index\n */\nexport const filterHueRotate = (index: number) => ({\n filter: `hue-rotate(${index * 10}deg)`,\n});\n"],"names":[],"mappings":"AAGO,MAAM,eAAA,GAAkB,CAAC,KAAA,MAAmB;AAAA,EACjD,MAAA,EAAQ,CAAA,WAAA,EAAc,KAAA,GAAQ,EAAE,CAAA,IAAA;AAClC,CAAA;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { getStyles, getSegmentStyles } from './StackedChartSegment.styles.js';
|
|
5
|
+
|
|
6
|
+
const _StackedChartSegment = ({
|
|
7
|
+
categoryId,
|
|
8
|
+
state = "default",
|
|
9
|
+
index,
|
|
10
|
+
value,
|
|
11
|
+
total = 100,
|
|
12
|
+
minValue = 4,
|
|
13
|
+
onMouseOver,
|
|
14
|
+
onMouseOut
|
|
15
|
+
}, ref) => {
|
|
16
|
+
const width = `${Math.max(value / total * 100, minValue)}%`;
|
|
17
|
+
return /* @__PURE__ */ jsx(
|
|
18
|
+
"div",
|
|
19
|
+
{
|
|
20
|
+
ref,
|
|
21
|
+
className: clsx(getStyles({ state, index }), getSegmentStyles()),
|
|
22
|
+
onMouseOver: onMouseOver && onMouseOver({ ref, categoryId }),
|
|
23
|
+
onMouseOut: onMouseOut && onMouseOut({ ref, categoryId }),
|
|
24
|
+
style: { width }
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
_StackedChartSegment.displayName = "StackedChartSegment";
|
|
29
|
+
const StackedChartSegment = React.forwardRef(_StackedChartSegment);
|
|
30
|
+
|
|
31
|
+
export { StackedChartSegment };
|
|
32
|
+
//# sourceMappingURL=StackedChartSegment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StackedChartSegment.js","sources":["../../../../src/components/StackedChartSegment/StackedChartSegment.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport React from 'react';\nimport { StackedChartSegmentProps } from './types';\nimport { getStyles, getSegmentStyles } from './StackedChartSegment.styles';\n\nconst _StackedChartSegment = <T extends string>(\n {\n categoryId,\n state = 'default',\n index,\n value,\n total = 100,\n minValue = 4,\n onMouseOver,\n onMouseOut,\n }: StackedChartSegmentProps<T>,\n ref: React.ForwardedRef<HTMLDivElement>,\n) => {\n const width = `${Math.max((value / total) * 100, minValue)}%`;\n\n return (\n <div\n ref={ref}\n className={clsx(getStyles({ state, index }), getSegmentStyles())}\n onMouseOver={onMouseOver && onMouseOver({ ref, categoryId })}\n onMouseOut={onMouseOut && onMouseOut({ ref, categoryId })}\n style={{ width }}\n />\n );\n};\n\n_StackedChartSegment.displayName = 'StackedChartSegment';\n\nexport const StackedChartSegment = React.forwardRef(_StackedChartSegment);\n"],"names":[],"mappings":";;;;;AAKA,MAAM,uBAAuB,CAC3B;AAAA,EACE,UAAA;AAAA,EACA,KAAA,GAAQ,SAAA;AAAA,EACR,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA,GAAQ,GAAA;AAAA,EACR,QAAA,GAAW,CAAA;AAAA,EACX,WAAA;AAAA,EACA;AACF,CAAA,EACA,GAAA,KACG;AACH,EAAA,MAAM,KAAA,GAAQ,GAAG,IAAA,CAAK,GAAA,CAAK,QAAQ,KAAA,GAAS,GAAA,EAAK,QAAQ,CAAC,CAAA,CAAA,CAAA;AAE1D,EAAA,uBACE,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACA,SAAA,EAAW,KAAK,SAAA,CAAU,EAAE,OAAO,KAAA,EAAO,CAAA,EAAG,gBAAA,EAAkB,CAAA;AAAA,MAC/D,aAAa,WAAA,IAAe,WAAA,CAAY,EAAE,GAAA,EAAK,YAAY,CAAA;AAAA,MAC3D,YAAY,UAAA,IAAc,UAAA,CAAW,EAAE,GAAA,EAAK,YAAY,CAAA;AAAA,MACxD,KAAA,EAAO,EAAE,KAAA;AAAM;AAAA,GACjB;AAEJ,CAAA;AAEA,oBAAA,CAAqB,WAAA,GAAc,qBAAA;AAE5B,MAAM,mBAAA,GAAsB,KAAA,CAAM,UAAA,CAAW,oBAAoB;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { css } from '@emotion/css';
|
|
2
|
+
import { getDesignTokens } from '@grafana/design-tokens';
|
|
3
|
+
import { filterHueRotate } from '../StackedChart/shared.styles.js';
|
|
4
|
+
|
|
5
|
+
const diagonalStripedBackground = ({
|
|
6
|
+
stripeColor,
|
|
7
|
+
stripeWidth = 2,
|
|
8
|
+
gapWidth = 6
|
|
9
|
+
}) => {
|
|
10
|
+
return `repeating-linear-gradient(
|
|
11
|
+
-45deg,
|
|
12
|
+
${stripeColor},
|
|
13
|
+
${stripeColor} ${stripeWidth}px,
|
|
14
|
+
transparent ${stripeWidth}px,
|
|
15
|
+
transparent ${gapWidth}px)`;
|
|
16
|
+
};
|
|
17
|
+
const getSegmentStyles = () => css({
|
|
18
|
+
display: "flex",
|
|
19
|
+
height: "100%"
|
|
20
|
+
});
|
|
21
|
+
const getStyles$3 = ({
|
|
22
|
+
index,
|
|
23
|
+
state = "default"
|
|
24
|
+
}) => {
|
|
25
|
+
const { legacy } = getDesignTokens({ valueType: "css" });
|
|
26
|
+
const hasColor = ["color", "active"].includes(state);
|
|
27
|
+
const backgroundImage = diagonalStripedBackground({
|
|
28
|
+
stripeColor: state === "dimmed" ? legacy.colors.secondary.shade : legacy.colors.secondary.transparent
|
|
29
|
+
});
|
|
30
|
+
return css({
|
|
31
|
+
cursor: hasColor ? "pointer" : void 0,
|
|
32
|
+
borderRadius: legacy.borderRadius.sm,
|
|
33
|
+
transitionDuration: "0.2s",
|
|
34
|
+
transitionTimingFunction: "ease-in-out",
|
|
35
|
+
transitionProperty: "background, filter, box-shadow",
|
|
36
|
+
background: hasColor ? legacy.colors.primary.main : legacy.colors.secondary.transparent,
|
|
37
|
+
backgroundImage,
|
|
38
|
+
opacity: state === "dimmed" ? 0.4 : void 0,
|
|
39
|
+
boxShadow: state === "active" ? legacy.boxShadows.z1 : "none",
|
|
40
|
+
...hasColor ? filterHueRotate(index) : {}
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { diagonalStripedBackground, getSegmentStyles, getStyles$3 as getStyles };
|
|
45
|
+
//# sourceMappingURL=StackedChartSegment.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StackedChartSegment.styles.js","sources":["../../../../src/components/StackedChartSegment/StackedChartSegment.styles.ts"],"sourcesContent":["import { css } from '@emotion/css';\nimport { getDesignTokens } from '@grafana/design-tokens';\nimport { StackedChartSegmentProps } from './types';\nimport { filterHueRotate } from '../StackedChart/shared.styles';\n\nexport const diagonalStripedBackground = ({\n stripeColor,\n stripeWidth = 2,\n gapWidth = 6,\n}: {\n stripeColor: string;\n stripeWidth?: number;\n gapWidth?: number;\n}) => {\n return `repeating-linear-gradient(\n -45deg,\n ${stripeColor},\n ${stripeColor} ${stripeWidth}px,\n transparent ${stripeWidth}px,\n transparent ${gapWidth}px)`;\n};\n\nexport const getSegmentStyles = () =>\n css({\n display: 'flex',\n height: '100%',\n });\n\nexport const getStyles = <T extends string>({\n index,\n state = 'default',\n}: Pick<StackedChartSegmentProps<T>, 'index' | 'state'>) => {\n const { legacy } = getDesignTokens({ valueType: 'css' });\n const hasColor = ['color', 'active'].includes(state);\n\n const backgroundImage = diagonalStripedBackground({\n stripeColor:\n state === 'dimmed' ? legacy.colors.secondary.shade : legacy.colors.secondary.transparent,\n });\n\n return css({\n cursor: hasColor ? 'pointer' : undefined,\n borderRadius: legacy.borderRadius.sm,\n transitionDuration: '0.2s',\n transitionTimingFunction: 'ease-in-out',\n transitionProperty: 'background, filter, box-shadow',\n background: hasColor ? legacy.colors.primary.main : legacy.colors.secondary.transparent,\n backgroundImage,\n opacity: state === 'dimmed' ? 0.4 : undefined,\n bo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AO,MAAA,CAAO,OAAO,SAAA,CAAU,WAAA;AAAA,IAC5E,eAAA;AAAA,IACA,OAAA,EAAS,KAAA,KAAU,QAAA,GAAW,GAAA,GAAM,MAAA;AAAA,IACpC,SAAA,EAAW,KAAA,KAAU,QAAA,GAAW,MAAA,CAAO,WAAW,EAAA,GAAK,MAAA;AAAA,IACvD,GAAI,QAAA,GAAW,eAAA,CAAgB,KAAK,IAAI;AAAC,GAC1C,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { Popover } from '../Popover/Popover.js';
|
|
3
|
+
import { getStyles } from './StackedChartSegmentTooltip.styles.js';
|
|
4
|
+
|
|
5
|
+
const defaultContentFormatter = ({ value, colorClassName }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6
|
+
/* @__PURE__ */ jsxs("span", { className: colorClassName, children: [
|
|
7
|
+
value,
|
|
8
|
+
"%"
|
|
9
|
+
] }),
|
|
10
|
+
" of total usage"
|
|
11
|
+
] });
|
|
12
|
+
const StackedChartSegmentTooltip = ({
|
|
13
|
+
trigger,
|
|
14
|
+
placement = "top",
|
|
15
|
+
hideDelay,
|
|
16
|
+
title,
|
|
17
|
+
value,
|
|
18
|
+
total = 100,
|
|
19
|
+
index,
|
|
20
|
+
formatContent = defaultContentFormatter,
|
|
21
|
+
virtualElement
|
|
22
|
+
}) => {
|
|
23
|
+
const styles = getStyles(index);
|
|
24
|
+
return /* @__PURE__ */ jsx(
|
|
25
|
+
Popover,
|
|
26
|
+
{
|
|
27
|
+
trigger,
|
|
28
|
+
placement,
|
|
29
|
+
hideDelay,
|
|
30
|
+
virtualElement,
|
|
31
|
+
children: /* @__PURE__ */ jsx("div", { className: styles.wrapper, children: /* @__PURE__ */ jsx("div", { className: styles.content, children: /* @__PURE__ */ jsxs("div", { className: styles.section, children: [
|
|
32
|
+
/* @__PURE__ */ jsx("div", { className: styles.title, children: title }),
|
|
33
|
+
/* @__PURE__ */ jsx("div", { className: styles.value, children: formatContent({ value, total, index, colorClassName: styles.color }) })
|
|
34
|
+
] }) }) })
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { StackedChartSegmentTooltip };
|
|
40
|
+
//# sourceMappingURL=StackedChartSegmentTooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StackedChartSegmentTooltip.js","sources":["../../../../src/components/StackedChartSegmentTooltip/StackedChartSegmentTooltip.tsx"],"sourcesContent":["import { StackedChartSegmentProps } from '../StackedChartSegment/types';\nimport { Popover, PopoverProps } from '../Popover';\nimport { getStyles } from './StackedChartSegmentTooltip.styles';\n\nexport type ContentFormatter = (\n args: {\n colorClassName: string;\n } & Required<Pick<StackedChartSegmentProps<string>, 'value' | 'total' | 'index'>>,\n) => React.ReactElement;\n\nexport interface StackedChartSegmentTooltipProps<T extends string>\n extends Pick<StackedChartSegmentProps<T>, 'title' | 'value' | 'total' | 'index'>,\n Omit<PopoverProps, 'children'> {\n formatContent?: ContentFormatter;\n}\n\n/**\n * The default content formatter assumes a percentage value, but you can create\n * your own formatter using the provided arguments of total and index. The\n * colorClassName allows you to set the colour of some text or an icon to the\n * same colour as the equivalent chart segment.\n */\nconst defaultContentFormatter: ContentFormatter = ({ value, colorClassName }) => (\n <>\n <span className={colorClassName}>{value}%</span> of total usage\n </>\n);\n\nexport const StackedChartSegmentTooltip = <T extends string>({\n trigger,\n placement = 'top',\n hideDelay,\n title,\n value,\n total = 100,\n index,\n formatContent = defaultContentFormatter,\n virtualElement,\n}: StackedChartSegmentTooltipProps<T>) => {\n const styles = getStyles(index);\n\n return (\n <Popover\n trigger={trigger}\n placement={placement}\n hideDelay={hideDelay}\n virtualElement={virtualElement}\n >\n <div className={styles.wrapper}>\n <div className={styles.content}>\n <div className={styles.section}>\n <div className={styles.title}>{title}</div>\n <div className={styles.value}>\n {formatContent({ value, total, index,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AAO,KAAA,EAAO,cAAA,EAAgB,MAAA,CAAO,KAAA,EAAO,CAAA,EACtE;AAAA,OAAA,EACF,GACF,CAAA,EACF;AAAA;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { css } from '@emotion/css';
|
|
2
|
+
import { getDesignTokens } from '@grafana/design-tokens';
|
|
3
|
+
import { filterHueRotate } from '../StackedChart/shared.styles.js';
|
|
4
|
+
|
|
5
|
+
const getStyles$1 = (index) => {
|
|
6
|
+
const {
|
|
7
|
+
legacy,
|
|
8
|
+
primitives: { spacing, typography }
|
|
9
|
+
} = getDesignTokens({ valueType: "css" });
|
|
10
|
+
return {
|
|
11
|
+
wrapper: css({
|
|
12
|
+
display: "flex",
|
|
13
|
+
flexDirection: "column",
|
|
14
|
+
gap: spacing.xs
|
|
15
|
+
}),
|
|
16
|
+
content: css({
|
|
17
|
+
display: "flex",
|
|
18
|
+
gap: spacing.xs
|
|
19
|
+
}),
|
|
20
|
+
section: css({
|
|
21
|
+
display: "flex",
|
|
22
|
+
flex: 1,
|
|
23
|
+
flexDirection: "column",
|
|
24
|
+
justifyContent: "flex-end",
|
|
25
|
+
gap: spacing.xs,
|
|
26
|
+
background: legacy.colors.background.primary,
|
|
27
|
+
borderRadius: legacy.borderRadius.md,
|
|
28
|
+
padding: `${spacing.sm} ${spacing.md}`
|
|
29
|
+
}),
|
|
30
|
+
title: css({
|
|
31
|
+
fontFamily: typography.fontFamily.ui,
|
|
32
|
+
fontSize: typography.fontSize.ui.sm,
|
|
33
|
+
fontWeight: typography.fontWeight.medium,
|
|
34
|
+
// TODO: this should come from a token!
|
|
35
|
+
lineHeight: "16px",
|
|
36
|
+
color: legacy.colors.text.primary,
|
|
37
|
+
whiteSpace: "nowrap"
|
|
38
|
+
}),
|
|
39
|
+
value: css({
|
|
40
|
+
// TODO: this should come from a token!
|
|
41
|
+
lineHeight: "16px",
|
|
42
|
+
color: legacy.colors.text.secondary
|
|
43
|
+
}),
|
|
44
|
+
color: css({
|
|
45
|
+
color: legacy.colors.primary.main,
|
|
46
|
+
fill: "currentColor",
|
|
47
|
+
...filterHueRotate(index)
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { getStyles$1 as getStyles };
|
|
53
|
+
//# sourceMappingURL=StackedChartSegmentTooltip.styles.js.map
|
package/dist/esm/components/StackedChartSegmentTooltip/StackedChartSegmentTooltip.styles.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StackedChartSegmentTooltip.styles.js","sources":["../../../../src/components/StackedChartSegmentTooltip/StackedChartSegmentTooltip.styles.ts"],"sourcesContent":["import { css } from '@emotion/css';\nimport { getDesignTokens } from '@grafana/design-tokens';\nimport { filterHueRotate } from '../StackedChart/shared.styles';\n\nexport const getStyles = (index: number) => {\n const {\n legacy,\n primitives: { spacing, typography },\n } = getDesignTokens({ valueType: 'css' });\n\n return {\n wrapper: css({\n display: 'flex',\n flexDirection: 'column',\n gap: spacing.xs,\n }),\n content: css({\n display: 'flex',\n gap: spacing.xs,\n }),\n section: css({\n display: 'flex',\n flex: 1,\n flexDirection: 'column',\n justifyContent: 'flex-end',\n gap: spacing.xs,\n background: legacy.colors.background.primary,\n borderRadius: legacy.borderRadius.md,\n padding: `${spacing.sm} ${spacing.md}`,\n }),\n title: css({\n fontFamily: typography.fontFamily.ui,\n fontSize: typography.fontSize.ui.sm,\n fontWeight: typography.fontWeight.medium,\n // TODO: this should come from a token!\n lineHeight: '16px',\n color: legacy.colors.text.primary,\n whiteSpace: 'nowrap',\n }),\n value: css({\n // TODO: this should come from a token!\n lineHeight: '16px',\n color: legacy.colors.text.secondary,\n }),\n color: css({\n color: legacy.colors.primary.main,\n fill: 'currentColor',\n ...filterHueRotate(index),\n }),\n };\n};\n"],"names":["getStyles"],"mappings":";;;;AAIO,MAAMA,WAAA,GAAY,CAAC,KAAA,KAAkB;AAC1C,EAAA,MAAM;AAAA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AAK;AAAA,KAC3B,CAAA;AAAA,IACD,OAAO,GAAA,CAAI;AAAA,MACT,KAAA,EAAO,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,IAAA;AAAA,MAC7B,IAAA,EAAM,cAAA;AAAA,MACN,GAAG,gBAAgB,KAAK;AAAA,KACzB;AAAA,GACH;AACF;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { getStyles } from './StackedChartSkeleton.styles.js';
|
|
3
|
+
import { GenericSkeleton } from '../GenericSkeleton/GenericSkeleton.js';
|
|
4
|
+
|
|
5
|
+
const StackedChartSkeleton = ({ height = 24 }) => {
|
|
6
|
+
const styles = getStyles(height);
|
|
7
|
+
return /* @__PURE__ */ jsx("div", { className: styles, children: /* @__PURE__ */ jsx(GenericSkeleton, {}) });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { StackedChartSkeleton };
|
|
11
|
+
//# sourceMappingURL=StackedChartSkeleton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StackedChartSkeleton.js","sources":["../../../../src/components/StackedChartSkeleton/StackedChartSkeleton.tsx"],"sourcesContent":["import { getStyles } from './StackedChartSkeleton.styles';\nimport { GenericSkeleton } from '../GenericSkeleton';\n\nexport interface StackedChartSkeletonProps {\n /**\n * Height to render the stacked chart skeleton, in pixels\n */\n height?: number;\n}\n\nexport const StackedChartSkeleton = ({ height = 24 }: StackedChartSkeletonProps) => {\n const styles = getStyles(height);\n\n return (\n <div className={styles}>\n <GenericSkeleton />\n </div>\n );\n};\n"],"names":[],"mappings":";;;;AAUO,MAAM,oBAAA,GAAuB,CAAC,EAAE,MAAA,GAAS,IAAG,KAAiC;AAClF,EAAA,MAAM,MAAA,GAAS,UAAU,MAAM,CAAA;AAE/B,EAAA,2BACG,KAAA,EAAA,EAAI,SAAA,EAAW,MAAA,EACd,QAAA,kBAAA,GAAA,CAAC,mBAAgB,CAAA,EACnB,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { css } from '@emotion/css';
|
|
2
|
+
|
|
3
|
+
const getStyles = (height) => {
|
|
4
|
+
return css({
|
|
5
|
+
width: "100%",
|
|
6
|
+
height: `${height}px`,
|
|
7
|
+
borderRadius: "4px",
|
|
8
|
+
overflow: "hidden"
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { getStyles };
|
|
13
|
+
//# sourceMappingURL=StackedChartSkeleton.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StackedChartSkeleton.styles.js","sources":["../../../../src/components/StackedChartSkeleton/StackedChartSkeleton.styles.ts"],"sourcesContent":["import { css } from '@emotion/css';\n\nexport const getStyles = (height: number) => {\n return css({\n width: '100%',\n height: `${height}px`,\n borderRadius: '4px',\n overflow: 'hidden',\n });\n};\n"],"names":[],"mappings":";;AAEO,MAAM,SAAA,GAAY,CAAC,MAAA,KAAmB;AAC3C,EAAA,OAAO,GAAA,CAAI;AAAA,IACT,KAAA,EAAO,MAAA;AAAA,IACP,MAAA,EAAQ,GAAG,MAAM,CAAA,EAAA,CAAA;AAAA,IACjB,YAAA,EAAc,KAAA;AAAA,IACd,QAAA,EAAU;AAAA,GACX,CAAA;AACH;;;;"}
|