@react-magma/charts 13.3.0 → 13.3.2-v4-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 CHANGED
@@ -3059,14 +3059,15 @@ var CarbonChart = React__namespace.forwardRef(function (props, ref) {
3059
3059
  theme.chartColorsInverse,
3060
3060
  isInverse,
3061
3061
  ]);
3062
- var newOptions = __assign(__assign(__assign({}, options), { theme: isInverse ? ChartTheme.G100 : ChartTheme.WHITE, color: {
3062
+ var hasChartToolbar = Boolean(chartToolbar);
3063
+ var newOptions = React__namespace.useMemo(function () { return (__assign(__assign(__assign({}, options), { theme: isInverse ? ChartTheme.G100 : ChartTheme.WHITE, color: {
3063
3064
  scale: colorScale,
3064
3065
  }, tooltip: __assign(__assign({}, ((options === null || options === void 0 ? void 0 : options.tooltip) || {})), { truncation: {
3065
3066
  type: 'none',
3066
- } }) }), (chartToolbar
3067
+ } }) }), (hasChartToolbar
3067
3068
  ? __assign({ toolbar: { enabled: false }, title: chartTitle }, (options.fileDownload
3068
3069
  ? {}
3069
- : { fileDownload: { fileName: chartTitle } })) : {}));
3070
+ : { fileDownload: { fileName: chartTitle } })) : {}))); }, [options, isInverse, colorScale, hasChartToolbar, chartTitle]);
3070
3071
  var ChartType = ALL_CHARTS[type];
3071
3072
  React__namespace.useEffect(function () {
3072
3073
  if (!ariaLabel)
@@ -3080,86 +3081,16 @@ var CarbonChart = React__namespace.forwardRef(function (props, ref) {
3080
3081
  });
3081
3082
  return function () { return cancelAnimationFrame(rafId); };
3082
3083
  }, [ariaLabel]);
3083
- // Make Carbon Charts data points keyboard-focusable.
3084
- React__namespace.useEffect(function () {
3085
- var wrapper = internalRef.current;
3086
- if (!wrapper)
3087
- return;
3088
- var isDot = function (el) {
3089
- return el instanceof Element &&
3090
- el.nodeName.toLowerCase() === 'circle' &&
3091
- el.classList.contains('dot');
3092
- };
3093
- var onFocusIn = function (e) {
3094
- if (!isDot(e.target))
3095
- return;
3096
- var dot = e.target;
3097
- dot.style.opacity = '1';
3098
- var _a = dot.getBoundingClientRect(), left = _a.left, top = _a.top, width = _a.width, height = _a.height;
3099
- var cx = left + width / 2;
3100
- var cy = top + height / 2;
3101
- dot.dispatchEvent(new MouseEvent('mouseover', {
3102
- bubbles: true,
3103
- clientX: cx,
3104
- clientY: cy,
3105
- screenX: cx,
3106
- screenY: cy,
3107
- }));
3108
- dot.dispatchEvent(new MouseEvent('mousemove', {
3109
- bubbles: true,
3110
- clientX: cx,
3111
- clientY: cy,
3112
- screenX: cx,
3113
- screenY: cy,
3114
- }));
3115
- };
3116
- var onFocusOut = function (e) {
3117
- if (!isDot(e.target))
3118
- return;
3119
- var dot = e.target;
3120
- dot.style.opacity = '';
3121
- dot.dispatchEvent(new MouseEvent('mouseout', { bubbles: true }));
3122
- };
3123
- var onKeyDown = function (e) {
3124
- if (!isDot(e.target))
3125
- return;
3126
- if (e.key !== 'Enter' && e.key !== ' ')
3127
- return;
3128
- e.preventDefault();
3129
- var dot = e.target;
3130
- var _a = dot.getBoundingClientRect(), left = _a.left, top = _a.top, width = _a.width, height = _a.height;
3131
- var cx = left + width / 2;
3132
- var cy = top + height / 2;
3133
- dot.dispatchEvent(new MouseEvent('click', {
3134
- bubbles: true,
3135
- clientX: cx,
3136
- clientY: cy,
3137
- }));
3138
- };
3139
- var rafId = requestAnimationFrame(function () {
3140
- wrapper
3141
- .querySelectorAll('circle.dot')
3142
- .forEach(function (dot) {
3143
- if (!dot.hasAttribute('tabindex')) {
3144
- dot.setAttribute('tabindex', '0');
3145
- }
3146
- });
3147
- });
3148
- wrapper.addEventListener('focusin', onFocusIn);
3149
- wrapper.addEventListener('focusout', onFocusOut);
3150
- wrapper.addEventListener('keydown', onKeyDown);
3151
- return function () {
3152
- cancelAnimationFrame(rafId);
3153
- wrapper.removeEventListener('focusin', onFocusIn);
3154
- wrapper.removeEventListener('focusout', onFocusOut);
3155
- wrapper.removeEventListener('keydown', onKeyDown);
3156
- };
3157
- }, [type]);
3158
3084
  React__namespace.useEffect(function () {
3159
3085
  var timer = setTimeout(function () {
3160
3086
  if (internalRef.current) {
3161
3087
  internalRef.current
3162
- .querySelectorAll('g[aria-label]')
3088
+ .querySelectorAll('g.ruler[aria-label]')
3089
+ .forEach(function (g) {
3090
+ g.setAttribute('aria-hidden', 'true');
3091
+ });
3092
+ internalRef.current
3093
+ .querySelectorAll('g[aria-label]:not(.ruler)')
3163
3094
  .forEach(function (g) {
3164
3095
  var role = g.getAttribute('role');
3165
3096
  if (!role) {
@@ -3173,6 +3104,24 @@ var CarbonChart = React__namespace.forwardRef(function (props, ref) {
3173
3104
  }, 0);
3174
3105
  return function () { return clearTimeout(timer); };
3175
3106
  }, [type, dataSet]);
3107
+ React__namespace.useEffect(function () {
3108
+ var container = internalRef.current;
3109
+ if (!container)
3110
+ return;
3111
+ var hideRulerFromAT = function () {
3112
+ container
3113
+ .querySelectorAll('g.ruler[aria-label]')
3114
+ .forEach(function (g) {
3115
+ if (!g.hasAttribute('aria-hidden')) {
3116
+ g.setAttribute('aria-hidden', 'true');
3117
+ }
3118
+ });
3119
+ };
3120
+ hideRulerFromAT();
3121
+ var observer = new MutationObserver(hideRulerFromAT);
3122
+ observer.observe(container, { childList: true, subtree: true });
3123
+ return function () { return observer.disconnect(); };
3124
+ }, [type, dataSet]);
3176
3125
  React__namespace.useEffect(function () {
3177
3126
  var wrapper = internalRef.current;
3178
3127
  if (!wrapper)
@@ -3224,6 +3173,96 @@ var CarbonChart = React__namespace.forwardRef(function (props, ref) {
3224
3173
  });
3225
3174
  return function () { return observer.disconnect(); };
3226
3175
  }, [type, dataSet]);
3176
+ // Make Carbon Charts data points keyboard-focusable.
3177
+ React__namespace.useEffect(function () {
3178
+ var wrapper = internalRef.current;
3179
+ if (!wrapper)
3180
+ return;
3181
+ var stampDotTabIndex = function () {
3182
+ wrapper
3183
+ .querySelectorAll('circle.dot')
3184
+ .forEach(function (dot) {
3185
+ if (!dot.hasAttribute('tabindex')) {
3186
+ dot.setAttribute('tabindex', '0');
3187
+ }
3188
+ });
3189
+ };
3190
+ var isDot = function (el) {
3191
+ return el instanceof Element &&
3192
+ el.nodeName.toLowerCase() === 'circle' &&
3193
+ el.classList.contains('dot');
3194
+ };
3195
+ var onFocusIn = function (e) {
3196
+ if (!isDot(e.target))
3197
+ return;
3198
+ var dot = e.target;
3199
+ var _a = dot.getBoundingClientRect(), left = _a.left, top = _a.top, width = _a.width, height = _a.height;
3200
+ var cx = left + width / 2;
3201
+ var cy = top + height / 2;
3202
+ dot.dispatchEvent(new MouseEvent('mouseover', {
3203
+ bubbles: true,
3204
+ clientX: cx,
3205
+ clientY: cy,
3206
+ screenX: cx,
3207
+ screenY: cy,
3208
+ }));
3209
+ dot.dispatchEvent(new MouseEvent('mousemove', {
3210
+ bubbles: true,
3211
+ clientX: cx,
3212
+ clientY: cy,
3213
+ screenX: cx,
3214
+ screenY: cy,
3215
+ }));
3216
+ };
3217
+ var onFocusOut = function (e) {
3218
+ if (!isDot(e.target))
3219
+ return;
3220
+ var dot = e.target;
3221
+ // Keep tooltip context while Tab focus moves between chart points.
3222
+ if (isDot(e.relatedTarget)) {
3223
+ return;
3224
+ }
3225
+ dot.dispatchEvent(new MouseEvent('mouseout', { bubbles: true }));
3226
+ };
3227
+ var onKeyDown = function (e) {
3228
+ if (!isDot(e.target))
3229
+ return;
3230
+ if (e.key !== 'Enter' && e.key !== ' ')
3231
+ return;
3232
+ e.preventDefault();
3233
+ var dot = e.target;
3234
+ var _a = dot.getBoundingClientRect(), left = _a.left, top = _a.top, width = _a.width, height = _a.height;
3235
+ var cx = left + width / 2;
3236
+ var cy = top + height / 2;
3237
+ dot.dispatchEvent(new MouseEvent('click', {
3238
+ bubbles: true,
3239
+ clientX: cx,
3240
+ clientY: cy,
3241
+ }));
3242
+ };
3243
+ var rafId = requestAnimationFrame(function () {
3244
+ stampDotTabIndex();
3245
+ });
3246
+ var dotObserver = new MutationObserver(function () {
3247
+ stampDotTabIndex();
3248
+ });
3249
+ dotObserver.observe(wrapper, {
3250
+ childList: true,
3251
+ subtree: true,
3252
+ attributes: true,
3253
+ attributeFilter: ['class', 'style', 'tabindex'],
3254
+ });
3255
+ wrapper.addEventListener('focusin', onFocusIn);
3256
+ wrapper.addEventListener('focusout', onFocusOut);
3257
+ wrapper.addEventListener('keydown', onKeyDown);
3258
+ return function () {
3259
+ cancelAnimationFrame(rafId);
3260
+ dotObserver.disconnect();
3261
+ wrapper.removeEventListener('focusin', onFocusIn);
3262
+ wrapper.removeEventListener('focusout', onFocusOut);
3263
+ wrapper.removeEventListener('keydown', onKeyDown);
3264
+ };
3265
+ }, [type, dataSet]);
3227
3266
  var groupsLength = Object.keys(colorScale).length;
3228
3267
  var showTable = (chartToolbar === null || chartToolbar === void 0 ? void 0 : chartToolbar.showAsTable) !== false;
3229
3268
  if (!ChartType)