@react-magma/charts 13.3.0-next.1 → 14.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts.js +79 -160
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +79 -160
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +537 -290
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/CarbonChart/CarbonChart.d.ts +10 -0
- package/dist/components/ChartTable/ChartTable.stories.d.ts +6 -0
- package/package.json +3 -3
- package/src/components/CarbonChart/CarbonChart.test.js +124 -0
- package/src/components/CarbonChart/CarbonChart.tsx +155 -188
- package/src/components/ChartTable/ChartTable.stories.tsx +54 -0
|
@@ -157,6 +157,16 @@ export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
157
157
|
* toolbar is automatically disabled.
|
|
158
158
|
*/
|
|
159
159
|
chartToolbar?: ChartToolbarConfig;
|
|
160
|
+
/**
|
|
161
|
+
* Custom content rendered below the toolbar row and above the chart itself,
|
|
162
|
+
* for example a filter. Requires `chartToolbar`; ignored without it.
|
|
163
|
+
*
|
|
164
|
+
* Providing this lays the toolbar out in normal flow instead of overlaying
|
|
165
|
+
* the single row Carbon reserves for its title, so the rendered height
|
|
166
|
+
* becomes toolbar + content + chart rather than the chart box alone. Set
|
|
167
|
+
* `options.height` so the chart still has a definite height of its own.
|
|
168
|
+
*/
|
|
169
|
+
additionalContent?: React.ReactNode;
|
|
160
170
|
}
|
|
161
171
|
|
|
162
172
|
const ChartContentWrapper = styled.div`
|
|
@@ -165,6 +175,7 @@ const ChartContentWrapper = styled.div`
|
|
|
165
175
|
`;
|
|
166
176
|
|
|
167
177
|
const FullscreenRoot = styled.div<{
|
|
178
|
+
isFlowLayout?: boolean;
|
|
168
179
|
isInverse?: boolean;
|
|
169
180
|
theme: ThemeInterface;
|
|
170
181
|
}>`
|
|
@@ -177,9 +188,34 @@ const FullscreenRoot = styled.div<{
|
|
|
177
188
|
props.isInverse
|
|
178
189
|
? props.theme.colors.primary700
|
|
179
190
|
: props.theme.colors.neutral100};
|
|
191
|
+
|
|
192
|
+
${props =>
|
|
193
|
+
props.isFlowLayout
|
|
194
|
+
? `
|
|
195
|
+
box-sizing: border-box;
|
|
196
|
+
display: flex;
|
|
197
|
+
flex-direction: column;
|
|
198
|
+
padding: 2em;
|
|
199
|
+
|
|
200
|
+
.carbon-chart-wrapper,
|
|
201
|
+
.carbon-chart-content {
|
|
202
|
+
display: flex;
|
|
203
|
+
flex: 1 1 auto;
|
|
204
|
+
flex-direction: column;
|
|
205
|
+
min-height: 0;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.cds--chart-holder {
|
|
209
|
+
flex: 1 1 auto;
|
|
210
|
+
height: auto !important;
|
|
211
|
+
min-height: 0;
|
|
212
|
+
}
|
|
213
|
+
`
|
|
214
|
+
: `
|
|
180
215
|
.cds--chart-holder {
|
|
181
216
|
height: 100vh !important;
|
|
182
217
|
}
|
|
218
|
+
`}
|
|
183
219
|
}
|
|
184
220
|
`;
|
|
185
221
|
|
|
@@ -217,6 +253,14 @@ const CarbonChartWrapper = styled.div<{
|
|
|
217
253
|
}
|
|
218
254
|
}
|
|
219
255
|
|
|
256
|
+
.cds--chart-holder.filled,
|
|
257
|
+
.cds--chart-holder.filled .cds--cc--chart-wrapper {
|
|
258
|
+
background-color: ${props =>
|
|
259
|
+
props.isInverse
|
|
260
|
+
? props.theme.colors.primary600
|
|
261
|
+
: props.theme.colors.neutral100};
|
|
262
|
+
}
|
|
263
|
+
|
|
220
264
|
.cds--data-table thead tr th {
|
|
221
265
|
background: ${props =>
|
|
222
266
|
props.isInverse ? props.theme.colors.primary700 : ''} !important;
|
|
@@ -700,6 +744,7 @@ interface ExtendedChartOptions extends ChartOptions {
|
|
|
700
744
|
}
|
|
701
745
|
|
|
702
746
|
const ToolbarWrapper = styled.div<{
|
|
747
|
+
isFlowLayout?: boolean;
|
|
703
748
|
isFullscreen?: boolean;
|
|
704
749
|
isInverse?: boolean;
|
|
705
750
|
theme: ThemeInterface;
|
|
@@ -707,12 +752,20 @@ const ToolbarWrapper = styled.div<{
|
|
|
707
752
|
align-items: center;
|
|
708
753
|
display: flex;
|
|
709
754
|
justify-content: space-between;
|
|
710
|
-
left: ${props => (props.isFullscreen ? '2em' : '0')};
|
|
711
|
-
position: absolute;
|
|
712
|
-
right: ${props => (props.isFullscreen ? '2em' : '0')};
|
|
713
|
-
top: ${props => (props.isFullscreen ? '2em' : '0')};
|
|
714
755
|
z-index: 2;
|
|
715
756
|
|
|
757
|
+
${props =>
|
|
758
|
+
props.isFlowLayout
|
|
759
|
+
? `
|
|
760
|
+
position: relative;
|
|
761
|
+
`
|
|
762
|
+
: `
|
|
763
|
+
left: ${props.isFullscreen ? '2em' : '0'};
|
|
764
|
+
position: absolute;
|
|
765
|
+
right: ${props.isFullscreen ? '2em' : '0'};
|
|
766
|
+
top: ${props.isFullscreen ? '2em' : '0'};
|
|
767
|
+
`}
|
|
768
|
+
|
|
716
769
|
button {
|
|
717
770
|
color: ${props =>
|
|
718
771
|
props.isInverse
|
|
@@ -758,6 +811,10 @@ const TitleSlot = styled.div`
|
|
|
758
811
|
display: flex;
|
|
759
812
|
`;
|
|
760
813
|
|
|
814
|
+
const ChartSlot = styled.div<{ theme: ThemeInterface }>`
|
|
815
|
+
margin: ${props => props.theme.spaceScale.spacing05} 0 0;
|
|
816
|
+
`;
|
|
817
|
+
|
|
761
818
|
const ToolbarActions = styled.div<{ theme: ThemeInterface }>`
|
|
762
819
|
align-items: center;
|
|
763
820
|
display: flex;
|
|
@@ -823,189 +880,54 @@ function downloadCsv(dataSet: Array<Record<string, unknown>>, title: string) {
|
|
|
823
880
|
URL.revokeObjectURL(url);
|
|
824
881
|
}
|
|
825
882
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
'style',
|
|
831
|
-
Array.from(computed)
|
|
832
|
-
.map(prop => `${prop}:${computed.getPropertyValue(prop)}`)
|
|
833
|
-
.join(';')
|
|
834
|
-
);
|
|
835
|
-
}
|
|
836
|
-
for (let i = 0; i < source.children.length; i++) {
|
|
837
|
-
if (target.children[i]) {
|
|
838
|
-
inlineStyles(source.children[i], target.children[i]);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
interface LegendItem {
|
|
844
|
-
label: string;
|
|
845
|
-
color: string;
|
|
883
|
+
interface CarbonChartCore {
|
|
884
|
+
services?: {
|
|
885
|
+
domUtils?: { exportToPNG: () => void; exportToJPG: () => void };
|
|
886
|
+
};
|
|
846
887
|
}
|
|
847
888
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
wrapper.querySelectorAll('.legend-item').forEach(item => {
|
|
851
|
-
const checkbox = item.querySelector<HTMLElement>('.checkbox');
|
|
852
|
-
const label = item.querySelector('p');
|
|
853
|
-
if (checkbox && label) {
|
|
854
|
-
items.push({
|
|
855
|
-
color: checkbox.style.background || checkbox.style.backgroundColor,
|
|
856
|
-
label: label.textContent || '',
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
});
|
|
860
|
-
return items;
|
|
889
|
+
interface CarbonChartComponent {
|
|
890
|
+
chart?: CarbonChartCore;
|
|
861
891
|
}
|
|
862
892
|
|
|
863
|
-
function
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
canvasWidth: number,
|
|
868
|
-
scale: number
|
|
893
|
+
function exportCarbonChartImage(
|
|
894
|
+
chart: CarbonChartCore | null | undefined,
|
|
895
|
+
toolbarWrapper: Element | null | undefined,
|
|
896
|
+
format: 'png' | 'jpg'
|
|
869
897
|
) {
|
|
870
|
-
const
|
|
871
|
-
const swatchSize = 12 * scale;
|
|
872
|
-
const gap = 8 * scale;
|
|
873
|
-
const itemGap = 16 * scale;
|
|
874
|
-
const paddingX = 16 * scale;
|
|
875
|
-
|
|
876
|
-
ctx.font = `${fontSize}px sans-serif`;
|
|
877
|
-
ctx.textBaseline = 'middle';
|
|
898
|
+
const domUtils = chart?.services?.domUtils;
|
|
878
899
|
|
|
879
|
-
|
|
880
|
-
let y = startY;
|
|
900
|
+
if (!domUtils) return;
|
|
881
901
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
902
|
+
const magmaWrapper = toolbarWrapper?.classList.contains('has-magma-toolbar')
|
|
903
|
+
? toolbarWrapper
|
|
904
|
+
: null;
|
|
885
905
|
|
|
886
|
-
|
|
887
|
-
x = paddingX;
|
|
888
|
-
y += fontSize + gap;
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
ctx.fillStyle = item.color;
|
|
892
|
-
ctx.fillRect(x, y - swatchSize / 2, swatchSize, swatchSize);
|
|
906
|
+
magmaWrapper?.classList.remove('has-magma-toolbar');
|
|
893
907
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
return y + fontSize + gap;
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
function downloadImage(
|
|
904
|
-
wrapperRef: React.RefObject<HTMLDivElement | null>,
|
|
905
|
-
title: string,
|
|
906
|
-
format: 'png' | 'jpg'
|
|
907
|
-
) {
|
|
908
|
-
const wrapper = wrapperRef.current;
|
|
909
|
-
if (!wrapper) return;
|
|
910
|
-
const svg = wrapper.querySelector('svg.layout-svg-wrapper');
|
|
911
|
-
if (!svg) return;
|
|
912
|
-
|
|
913
|
-
const svgRect = svg.getBoundingClientRect();
|
|
914
|
-
const legendItems = readLegendItems(wrapper);
|
|
915
|
-
|
|
916
|
-
const doWork = () => {
|
|
917
|
-
const scale = 2;
|
|
918
|
-
|
|
919
|
-
// Measure legend height
|
|
920
|
-
const tempCanvas = document.createElement('canvas');
|
|
921
|
-
const tempCtx = tempCanvas.getContext('2d');
|
|
922
|
-
const fontSize = 13 * scale;
|
|
923
|
-
const swatchSize = 12 * scale;
|
|
924
|
-
const gap = 8 * scale;
|
|
925
|
-
const itemGap = 16 * scale;
|
|
926
|
-
const paddingX = 16 * scale;
|
|
927
|
-
const canvasWidth = svgRect.width * scale;
|
|
928
|
-
|
|
929
|
-
let legendHeight = 0;
|
|
930
|
-
if (legendItems.length > 0 && tempCtx) {
|
|
931
|
-
tempCtx.font = `${fontSize}px sans-serif`;
|
|
932
|
-
let x = paddingX;
|
|
933
|
-
let rows = 1;
|
|
934
|
-
for (const item of legendItems) {
|
|
935
|
-
const textWidth = tempCtx.measureText(item.label).width;
|
|
936
|
-
const itemWidth = swatchSize + gap + textWidth + itemGap;
|
|
937
|
-
if (x + itemWidth > canvasWidth - paddingX && x > paddingX) {
|
|
938
|
-
x = paddingX;
|
|
939
|
-
rows++;
|
|
940
|
-
}
|
|
941
|
-
x += itemWidth;
|
|
942
|
-
}
|
|
943
|
-
legendHeight = rows * (fontSize + gap) + gap * 2;
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
const width = svgRect.width * scale;
|
|
947
|
-
const height = svgRect.height * scale + legendHeight;
|
|
948
|
-
|
|
949
|
-
const clone = svg.cloneNode(true) as SVGSVGElement;
|
|
950
|
-
clone.setAttribute('width', String(svgRect.width));
|
|
951
|
-
clone.setAttribute('height', String(svgRect.height));
|
|
952
|
-
clone.setAttribute('viewBox', `0 0 ${svgRect.width} ${svgRect.height}`);
|
|
953
|
-
clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
954
|
-
|
|
955
|
-
inlineStyles(svg, clone);
|
|
956
|
-
|
|
957
|
-
const serializer = new XMLSerializer();
|
|
958
|
-
const svgString = serializer.serializeToString(clone);
|
|
959
|
-
const svgBlob = new Blob([svgString], {
|
|
960
|
-
type: 'image/svg+xml;charset=utf-8',
|
|
961
|
-
});
|
|
962
|
-
const url = URL.createObjectURL(svgBlob);
|
|
963
|
-
|
|
964
|
-
const mimeType = format === 'jpg' ? 'image/jpeg' : 'image/png';
|
|
965
|
-
const ext = format === 'jpg' ? 'jpg' : 'png';
|
|
966
|
-
|
|
967
|
-
const img = new Image();
|
|
968
|
-
img.onload = () => {
|
|
969
|
-
const canvas = document.createElement('canvas');
|
|
970
|
-
canvas.width = width;
|
|
971
|
-
canvas.height = height;
|
|
972
|
-
const ctx = canvas.getContext('2d');
|
|
973
|
-
if (!ctx) return;
|
|
974
|
-
|
|
975
|
-
ctx.fillStyle = '#ffffff';
|
|
976
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
977
|
-
ctx.drawImage(img, 0, 0, svgRect.width * scale, svgRect.height * scale);
|
|
978
|
-
URL.revokeObjectURL(url);
|
|
979
|
-
|
|
980
|
-
if (legendItems.length > 0) {
|
|
981
|
-
drawLegend(
|
|
982
|
-
ctx,
|
|
983
|
-
legendItems,
|
|
984
|
-
svgRect.height * scale + gap,
|
|
985
|
-
width,
|
|
986
|
-
scale
|
|
987
|
-
);
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
canvas.toBlob(blob => {
|
|
991
|
-
if (!blob) return;
|
|
992
|
-
const imgUrl = URL.createObjectURL(blob);
|
|
993
|
-
const a = document.createElement('a');
|
|
994
|
-
a.href = imgUrl;
|
|
995
|
-
a.download = `${title || 'chart'}.${ext}`;
|
|
996
|
-
a.click();
|
|
997
|
-
URL.revokeObjectURL(imgUrl);
|
|
998
|
-
}, mimeType);
|
|
999
|
-
};
|
|
1000
|
-
img.onerror = () => URL.revokeObjectURL(url);
|
|
1001
|
-
img.src = url;
|
|
908
|
+
let restored = false;
|
|
909
|
+
const restore = () => {
|
|
910
|
+
if (restored) return;
|
|
911
|
+
restored = true;
|
|
912
|
+
magmaWrapper?.classList.add('has-magma-toolbar');
|
|
1002
913
|
};
|
|
1003
914
|
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
915
|
+
try {
|
|
916
|
+
if (format === 'jpg') {
|
|
917
|
+
domUtils.exportToJPG();
|
|
918
|
+
} else {
|
|
919
|
+
domUtils.exportToPNG();
|
|
920
|
+
}
|
|
921
|
+
} catch (error) {
|
|
922
|
+
console.warn('Carbon chart image export failed', error);
|
|
923
|
+
} finally {
|
|
924
|
+
// Re-add before the next paint so the title swap is never visible on
|
|
925
|
+
// screen; the timeout is only a fallback for when requestAnimationFrame is
|
|
926
|
+
// paused (e.g. the tab is in the background).
|
|
927
|
+
if (typeof requestAnimationFrame === 'function') {
|
|
928
|
+
requestAnimationFrame(restore);
|
|
929
|
+
}
|
|
930
|
+
setTimeout(restore, 1000);
|
|
1009
931
|
}
|
|
1010
932
|
}
|
|
1011
933
|
|
|
@@ -1031,8 +953,10 @@ const ALL_CHARTS: Record<CarbonChartType, React.ComponentType<any>> = {
|
|
|
1031
953
|
};
|
|
1032
954
|
|
|
1033
955
|
interface InternalToolbarProps {
|
|
956
|
+
chartRef: React.MutableRefObject<CarbonChartComponent | null>;
|
|
1034
957
|
config: ChartToolbarConfig;
|
|
1035
958
|
dataSet: Array<Record<string, unknown>>;
|
|
959
|
+
isFlowLayout: boolean;
|
|
1036
960
|
isInverse: boolean;
|
|
1037
961
|
isTableOpen: boolean;
|
|
1038
962
|
isFullscreen: boolean;
|
|
@@ -1044,8 +968,10 @@ interface InternalToolbarProps {
|
|
|
1044
968
|
}
|
|
1045
969
|
|
|
1046
970
|
function CarbonChartToolbar({
|
|
971
|
+
chartRef,
|
|
1047
972
|
config,
|
|
1048
973
|
dataSet,
|
|
974
|
+
isFlowLayout,
|
|
1049
975
|
isInverse,
|
|
1050
976
|
isTableOpen,
|
|
1051
977
|
isFullscreen,
|
|
@@ -1060,17 +986,28 @@ function CarbonChartToolbar({
|
|
|
1060
986
|
const showFullscreen = config.fullscreen !== false;
|
|
1061
987
|
const resolvedTitle = title || t.defaultTitle;
|
|
1062
988
|
|
|
989
|
+
const exportImage = React.useCallback(
|
|
990
|
+
(format: 'png' | 'jpg') => {
|
|
991
|
+
exportCarbonChartImage(
|
|
992
|
+
chartRef.current?.chart,
|
|
993
|
+
wrapperRef.current?.querySelector('.carbon-chart-wrapper'),
|
|
994
|
+
format
|
|
995
|
+
);
|
|
996
|
+
},
|
|
997
|
+
[chartRef, wrapperRef]
|
|
998
|
+
);
|
|
999
|
+
|
|
1063
1000
|
const handleDownloadCsv = React.useCallback(() => {
|
|
1064
1001
|
downloadCsv(dataSet, title);
|
|
1065
1002
|
}, [dataSet, title]);
|
|
1066
1003
|
|
|
1067
1004
|
const handleDownloadPng = React.useCallback(() => {
|
|
1068
|
-
|
|
1069
|
-
}, [
|
|
1005
|
+
exportImage('png');
|
|
1006
|
+
}, [exportImage]);
|
|
1070
1007
|
|
|
1071
1008
|
const handleDownloadJpg = React.useCallback(() => {
|
|
1072
|
-
|
|
1073
|
-
}, [
|
|
1009
|
+
exportImage('jpg');
|
|
1010
|
+
}, [exportImage]);
|
|
1074
1011
|
|
|
1075
1012
|
const moreOptionsContent = (
|
|
1076
1013
|
<>
|
|
@@ -1094,6 +1031,7 @@ function CarbonChartToolbar({
|
|
|
1094
1031
|
|
|
1095
1032
|
return (
|
|
1096
1033
|
<ToolbarWrapper
|
|
1034
|
+
isFlowLayout={isFlowLayout}
|
|
1097
1035
|
isFullscreen={isFullscreen}
|
|
1098
1036
|
isInverse={isInverse}
|
|
1099
1037
|
theme={theme}
|
|
@@ -1152,6 +1090,7 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1152
1090
|
type,
|
|
1153
1091
|
dataSet,
|
|
1154
1092
|
options,
|
|
1093
|
+
additionalContent,
|
|
1155
1094
|
ariaLabel,
|
|
1156
1095
|
chartToolbar,
|
|
1157
1096
|
...rest
|
|
@@ -1160,6 +1099,7 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1160
1099
|
const isInverse = useIsInverse(isInverseProp);
|
|
1161
1100
|
const toolbarI18n = useChartToolbarI18n();
|
|
1162
1101
|
const internalRef = React.useRef<HTMLDivElement | null>(null);
|
|
1102
|
+
const chartComponentRef = React.useRef<CarbonChartComponent | null>(null);
|
|
1163
1103
|
|
|
1164
1104
|
const [isTableOpen, setIsTableOpen] = React.useState(false);
|
|
1165
1105
|
const [isFullscreen, setIsFullscreen] = React.useState(false);
|
|
@@ -1186,6 +1126,8 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1186
1126
|
? chartToolbar.fullscreen !== false
|
|
1187
1127
|
: false;
|
|
1188
1128
|
|
|
1129
|
+
const isFlowLayout = Boolean(chartToolbar && additionalContent);
|
|
1130
|
+
|
|
1189
1131
|
const savedHeightRef = React.useRef<string>('');
|
|
1190
1132
|
|
|
1191
1133
|
React.useEffect(() => {
|
|
@@ -1197,7 +1139,8 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1197
1139
|
|
|
1198
1140
|
const chartHolder =
|
|
1199
1141
|
internalRef.current?.querySelector<HTMLElement>('.cds--chart-holder');
|
|
1200
|
-
|
|
1142
|
+
|
|
1143
|
+
if (chartHolder && !isFlowLayout) {
|
|
1201
1144
|
if (isFs) {
|
|
1202
1145
|
savedHeightRef.current = chartHolder.style.height;
|
|
1203
1146
|
chartHolder.style.height = '100vh';
|
|
@@ -1212,11 +1155,11 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1212
1155
|
// Restore height if the component unmounts while in fullscreen.
|
|
1213
1156
|
const chartHolder =
|
|
1214
1157
|
internalRef.current?.querySelector<HTMLElement>('.cds--chart-holder');
|
|
1215
|
-
if (chartHolder && document.fullscreenElement) {
|
|
1158
|
+
if (chartHolder && document.fullscreenElement && !isFlowLayout) {
|
|
1216
1159
|
chartHolder.style.height = savedHeightRef.current;
|
|
1217
1160
|
}
|
|
1218
1161
|
};
|
|
1219
|
-
}, [fullscreenEnabled]);
|
|
1162
|
+
}, [fullscreenEnabled, isFlowLayout]);
|
|
1220
1163
|
|
|
1221
1164
|
const openTableModal = React.useCallback(
|
|
1222
1165
|
(event: React.MouseEvent<HTMLButtonElement>) => {
|
|
@@ -1442,7 +1385,15 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1442
1385
|
type: 'none',
|
|
1443
1386
|
},
|
|
1444
1387
|
},
|
|
1445
|
-
...(chartToolbar
|
|
1388
|
+
...(chartToolbar
|
|
1389
|
+
? {
|
|
1390
|
+
toolbar: { enabled: false },
|
|
1391
|
+
title: chartTitle,
|
|
1392
|
+
...(options.fileDownload
|
|
1393
|
+
? {}
|
|
1394
|
+
: { fileDownload: { fileName: chartTitle } }),
|
|
1395
|
+
}
|
|
1396
|
+
: {}),
|
|
1446
1397
|
};
|
|
1447
1398
|
|
|
1448
1399
|
const ChartType = ALL_CHARTS[type];
|
|
@@ -1628,7 +1579,12 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1628
1579
|
if (!ChartType) return null;
|
|
1629
1580
|
|
|
1630
1581
|
return (
|
|
1631
|
-
<FullscreenRoot
|
|
1582
|
+
<FullscreenRoot
|
|
1583
|
+
ref={mergedRef}
|
|
1584
|
+
isFlowLayout={isFlowLayout}
|
|
1585
|
+
isInverse={isInverse}
|
|
1586
|
+
theme={theme}
|
|
1587
|
+
>
|
|
1632
1588
|
<VisuallyHidden>
|
|
1633
1589
|
<Announce>{legendAnnouncement}</Announce>
|
|
1634
1590
|
</VisuallyHidden>
|
|
@@ -1639,14 +1595,16 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1639
1595
|
data-testid={testId}
|
|
1640
1596
|
isInverse={isInverse}
|
|
1641
1597
|
theme={theme}
|
|
1642
|
-
className={`carbon-chart-wrapper${
|
|
1598
|
+
className={`carbon-chart-wrapper${
|
|
1599
|
+
chartToolbar ? ' has-magma-toolbar' : ''
|
|
1600
|
+
}`}
|
|
1643
1601
|
groupsLength={groupsLength < 6 ? groupsLength : 14}
|
|
1644
1602
|
role="region"
|
|
1645
1603
|
aria-label={ariaLabel || chartTitle}
|
|
1646
1604
|
aria-roledescription="chart"
|
|
1647
1605
|
{...rest}
|
|
1648
1606
|
>
|
|
1649
|
-
<ChartContentWrapper>
|
|
1607
|
+
<ChartContentWrapper className="carbon-chart-content">
|
|
1650
1608
|
{chartToolbar && (
|
|
1651
1609
|
/*
|
|
1652
1610
|
* Slot content comes from the adopter, so it resolves
|
|
@@ -1656,8 +1614,10 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1656
1614
|
*/
|
|
1657
1615
|
<InverseContext.Provider value={{ isInverse }}>
|
|
1658
1616
|
<CarbonChartToolbar
|
|
1617
|
+
chartRef={chartComponentRef}
|
|
1659
1618
|
config={chartToolbar}
|
|
1660
1619
|
dataSet={dataSet as Array<Record<string, unknown>>}
|
|
1620
|
+
isFlowLayout={isFlowLayout}
|
|
1661
1621
|
isInverse={isInverse}
|
|
1662
1622
|
isTableOpen={isTableOpen}
|
|
1663
1623
|
isFullscreen={isFullscreen}
|
|
@@ -1667,9 +1627,16 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1667
1627
|
title={chartTitle}
|
|
1668
1628
|
wrapperRef={internalRef}
|
|
1669
1629
|
/>
|
|
1630
|
+
{isFlowLayout && (
|
|
1631
|
+
<ChartSlot theme={theme}>{additionalContent}</ChartSlot>
|
|
1632
|
+
)}
|
|
1670
1633
|
</InverseContext.Provider>
|
|
1671
1634
|
)}
|
|
1672
|
-
<ChartType
|
|
1635
|
+
<ChartType
|
|
1636
|
+
ref={chartComponentRef}
|
|
1637
|
+
data={dataSet}
|
|
1638
|
+
options={newOptions}
|
|
1639
|
+
/>
|
|
1673
1640
|
</ChartContentWrapper>
|
|
1674
1641
|
</CarbonChartWrapper>
|
|
1675
1642
|
{chartToolbar && showTable && (
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
ButtonVariant,
|
|
11
11
|
Card,
|
|
12
12
|
IconButton,
|
|
13
|
+
Select,
|
|
13
14
|
Tooltip,
|
|
14
15
|
} from 'react-magma-dom';
|
|
15
16
|
import { InfoIcon } from 'react-magma-icons';
|
|
@@ -235,3 +236,56 @@ export const TitleSlots = {
|
|
|
235
236
|
dataSet: barDataSet,
|
|
236
237
|
},
|
|
237
238
|
};
|
|
239
|
+
|
|
240
|
+
const chapterFilters = [
|
|
241
|
+
{ label: 'All Chapters', value: 'all' },
|
|
242
|
+
{ label: 'Chapters 1-2', value: 'ch-1-2' },
|
|
243
|
+
{ label: 'Chapters 3-4', value: 'ch-3-4' },
|
|
244
|
+
];
|
|
245
|
+
|
|
246
|
+
const chaptersByFilter: Record<string, string[]> = {
|
|
247
|
+
'ch-1-2': ['Chapter 1', 'Chapter 2'],
|
|
248
|
+
'ch-3-4': ['Chapter 3', 'Chapter 4'],
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export const AdditionalContent = {
|
|
252
|
+
render: ({ isInverse }: Pick<CarbonChartProps, 'isInverse'>) => {
|
|
253
|
+
const [filter, setFilter] = React.useState(chapterFilters[0]);
|
|
254
|
+
const chapters = chaptersByFilter[filter.value];
|
|
255
|
+
const dataSet = chapters
|
|
256
|
+
? barDataSet.filter(row => chapters.includes(row.group))
|
|
257
|
+
: barDataSet;
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
<Card isInverse={isInverse} style={{ padding: '12px' }}>
|
|
261
|
+
<CarbonChart
|
|
262
|
+
isInverse={isInverse}
|
|
263
|
+
type={CarbonChartType.bar}
|
|
264
|
+
dataSet={dataSet}
|
|
265
|
+
options={{
|
|
266
|
+
title: 'Chapter Performance',
|
|
267
|
+
axes: {
|
|
268
|
+
left: { mapsTo: 'value' },
|
|
269
|
+
bottom: { mapsTo: 'group', scaleType: ScaleTypes.LABELS },
|
|
270
|
+
},
|
|
271
|
+
height: '400px',
|
|
272
|
+
}}
|
|
273
|
+
chartToolbar={{ titleSuffix: <ChartInfoTooltip /> }}
|
|
274
|
+
additionalContent={
|
|
275
|
+
<Select
|
|
276
|
+
items={chapterFilters}
|
|
277
|
+
labelText="Filter by"
|
|
278
|
+
selectedItem={filter}
|
|
279
|
+
onSelectedItemChange={changes =>
|
|
280
|
+
setFilter(changes.selectedItem ?? chapterFilters[0])
|
|
281
|
+
}
|
|
282
|
+
/>
|
|
283
|
+
}
|
|
284
|
+
/>
|
|
285
|
+
</Card>
|
|
286
|
+
);
|
|
287
|
+
},
|
|
288
|
+
args: {
|
|
289
|
+
isInverse: false,
|
|
290
|
+
},
|
|
291
|
+
};
|