@cloudscape-design/components 3.0.22 → 3.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/alert/styles.scoped.css +0 -34
  2. package/annotation-context/annotation/annotation-popover.d.ts.map +1 -1
  3. package/annotation-context/annotation/annotation-popover.js +12 -16
  4. package/annotation-context/annotation/annotation-popover.js.map +1 -1
  5. package/annotation-context/annotation/styles.scoped.css +0 -18
  6. package/app-layout/content-wrapper/styles.scoped.css +0 -4
  7. package/app-layout/index.d.ts.map +1 -1
  8. package/app-layout/index.js +6 -4
  9. package/app-layout/index.js.map +1 -1
  10. package/app-layout/mobile-toolbar/styles.scoped.css +0 -9
  11. package/app-layout/styles.scoped.css +0 -20
  12. package/app-layout/toggles/styles.scoped.css +0 -16
  13. package/app-layout/visual-refresh/styles.scoped.css +0 -71
  14. package/area-chart/styles.scoped.css +0 -13
  15. package/attribute-editor/styles.scoped.css +0 -23
  16. package/badge/styles.scoped.css +0 -15
  17. package/bar-chart/interfaces.d.ts +1 -1
  18. package/bar-chart/interfaces.d.ts.map +1 -1
  19. package/bar-chart/interfaces.js.map +1 -1
  20. package/box/styles.scoped.css +0 -171
  21. package/breadcrumb-group/item/styles.scoped.css +0 -11
  22. package/breadcrumb-group/styles.scoped.css +0 -10
  23. package/button/styles.scoped.css +0 -264
  24. package/button-dropdown/category-elements/styles.scoped.css +0 -26
  25. package/button-dropdown/item-element/styles.scoped.css +0 -22
  26. package/button-dropdown/mobile-expandable-group/styles.scoped.css +0 -5
  27. package/button-dropdown/styles.scoped.css +0 -7
  28. package/cards/styles.scoped.css +0 -45
  29. package/checkbox/styles.scoped.css +0 -11
  30. package/code-editor/styles.scoped.css +0 -87
  31. package/collection-preferences/styles.scoped.css +0 -12
  32. package/column-layout/styles.scoped.css +0 -12
  33. package/container/styles.scoped.css +0 -27
  34. package/date-picker/calendar/index.d.ts.map +1 -1
  35. package/date-picker/calendar/index.js +2 -2
  36. package/date-picker/calendar/index.js.map +1 -1
  37. package/date-picker/calendar/utils/locales.d.ts +2 -0
  38. package/date-picker/calendar/utils/locales.d.ts.map +1 -1
  39. package/date-picker/calendar/utils/locales.js +4 -0
  40. package/date-picker/calendar/utils/locales.js.map +1 -1
  41. package/date-picker/styles.scoped.css +0 -45
  42. package/date-range-picker/calendar/grids/day/styles.scoped.css +0 -45
  43. package/date-range-picker/calendar/index.js +2 -2
  44. package/date-range-picker/calendar/index.js.map +1 -1
  45. package/date-range-picker/index.d.ts.map +1 -1
  46. package/date-range-picker/index.js +13 -15
  47. package/date-range-picker/index.js.map +1 -1
  48. package/date-range-picker/relative-range/styles.scoped.css +0 -3
  49. package/date-range-picker/styles.css.js +41 -42
  50. package/date-range-picker/styles.scoped.css +49 -92
  51. package/date-range-picker/styles.selectors.js +41 -42
  52. package/expandable-section/styles.scoped.css +0 -33
  53. package/flashbar/styles.scoped.css +0 -36
  54. package/form/styles.scoped.css +0 -12
  55. package/form-field/styles.scoped.css +0 -26
  56. package/grid/styles.scoped.css +0 -6
  57. package/header/styles.scoped.css +0 -51
  58. package/help-panel/styles.scoped.css +0 -73
  59. package/hotspot/styles.scoped.css +0 -3
  60. package/icon/styles.scoped.css +0 -33
  61. package/input/styles.scoped.css +0 -49
  62. package/internal/base-component/styles.scoped.css +0 -1
  63. package/internal/components/abstract-switch/styles.scoped.css +0 -7
  64. package/internal/components/button-trigger/styles.scoped.css +0 -42
  65. package/internal/components/cartesian-chart/styles.scoped.css +0 -10
  66. package/internal/components/chart-filter/styles.scoped.css +0 -4
  67. package/internal/components/chart-legend/styles.scoped.css +0 -8
  68. package/internal/components/chart-plot/styles.scoped.css +0 -1
  69. package/internal/components/chart-popover/styles.scoped.css +0 -4
  70. package/internal/components/chart-series-details/styles.scoped.css +0 -12
  71. package/internal/components/chart-series-marker/styles.scoped.css +0 -7
  72. package/internal/components/chart-status-container/styles.scoped.css +0 -1
  73. package/internal/components/checkbox-icon/styles.scoped.css +0 -10
  74. package/internal/components/content-layout/styles.scoped.css +0 -5
  75. package/internal/components/dark-ribbon/styles.scoped.css +0 -1
  76. package/internal/components/dropdown/styles.scoped.css +0 -17
  77. package/internal/components/dropdown-footer/styles.scoped.css +0 -6
  78. package/internal/components/dropdown-status/styles.scoped.css +0 -6
  79. package/internal/components/filtering-token/styles.scoped.css +0 -21
  80. package/internal/components/menu-dropdown/styles.scoped.css +0 -17
  81. package/internal/components/option/index.js +3 -3
  82. package/internal/components/option/index.js.map +1 -1
  83. package/internal/components/option/option-parts.js +3 -3
  84. package/internal/components/option/option-parts.js.map +1 -1
  85. package/internal/components/option/styles.scoped.css +0 -16
  86. package/internal/components/options-list/styles.scoped.css +0 -5
  87. package/internal/components/selectable-item/styles.scoped.css +0 -44
  88. package/internal/environment.js +1 -1
  89. package/line-chart/interfaces.d.ts +1 -1
  90. package/line-chart/interfaces.d.ts.map +1 -1
  91. package/line-chart/interfaces.js.map +1 -1
  92. package/link/styles.scoped.css +0 -77
  93. package/mixed-line-bar-chart/bar-series.d.ts +1 -1
  94. package/mixed-line-bar-chart/bar-series.d.ts.map +1 -1
  95. package/mixed-line-bar-chart/bar-series.js.map +1 -1
  96. package/mixed-line-bar-chart/chart-container.d.ts.map +1 -1
  97. package/mixed-line-bar-chart/chart-container.js +9 -10
  98. package/mixed-line-bar-chart/chart-container.js.map +1 -1
  99. package/mixed-line-bar-chart/chart-filters.d.ts +2 -2
  100. package/mixed-line-bar-chart/chart-filters.d.ts.map +1 -1
  101. package/mixed-line-bar-chart/chart-filters.js +1 -2
  102. package/mixed-line-bar-chart/chart-filters.js.map +1 -1
  103. package/mixed-line-bar-chart/chart-legend.d.ts +2 -2
  104. package/mixed-line-bar-chart/chart-legend.d.ts.map +1 -1
  105. package/mixed-line-bar-chart/chart-legend.js +1 -2
  106. package/mixed-line-bar-chart/chart-legend.js.map +1 -1
  107. package/mixed-line-bar-chart/domain.d.ts +4 -0
  108. package/mixed-line-bar-chart/domain.d.ts.map +1 -0
  109. package/mixed-line-bar-chart/domain.js +138 -0
  110. package/mixed-line-bar-chart/domain.js.map +1 -0
  111. package/mixed-line-bar-chart/format-highlighted.d.ts +2 -4
  112. package/mixed-line-bar-chart/format-highlighted.d.ts.map +1 -1
  113. package/mixed-line-bar-chart/format-highlighted.js +26 -15
  114. package/mixed-line-bar-chart/format-highlighted.js.map +1 -1
  115. package/mixed-line-bar-chart/hooks/use-mouse-hover.d.ts.map +1 -1
  116. package/mixed-line-bar-chart/hooks/use-mouse-hover.js +3 -2
  117. package/mixed-line-bar-chart/hooks/use-mouse-hover.js.map +1 -1
  118. package/mixed-line-bar-chart/hooks/use-navigation.d.ts.map +1 -1
  119. package/mixed-line-bar-chart/hooks/use-navigation.js +23 -35
  120. package/mixed-line-bar-chart/hooks/use-navigation.js.map +1 -1
  121. package/mixed-line-bar-chart/interfaces.d.ts +12 -2
  122. package/mixed-line-bar-chart/interfaces.d.ts.map +1 -1
  123. package/mixed-line-bar-chart/interfaces.js.map +1 -1
  124. package/mixed-line-bar-chart/internal.d.ts.map +1 -1
  125. package/mixed-line-bar-chart/internal.js +14 -6
  126. package/mixed-line-bar-chart/internal.js.map +1 -1
  127. package/mixed-line-bar-chart/line-series.d.ts +2 -2
  128. package/mixed-line-bar-chart/line-series.d.ts.map +1 -1
  129. package/mixed-line-bar-chart/line-series.js +21 -9
  130. package/mixed-line-bar-chart/line-series.js.map +1 -1
  131. package/mixed-line-bar-chart/make-scaled-bar-groups.d.ts.map +1 -1
  132. package/mixed-line-bar-chart/make-scaled-bar-groups.js +11 -4
  133. package/mixed-line-bar-chart/make-scaled-bar-groups.js.map +1 -1
  134. package/mixed-line-bar-chart/make-scaled-series.d.ts +2 -4
  135. package/mixed-line-bar-chart/make-scaled-series.d.ts.map +1 -1
  136. package/mixed-line-bar-chart/make-scaled-series.js +89 -25
  137. package/mixed-line-bar-chart/make-scaled-series.js.map +1 -1
  138. package/mixed-line-bar-chart/styles.scoped.css +0 -13
  139. package/mixed-line-bar-chart/utils.d.ts +5 -6
  140. package/mixed-line-bar-chart/utils.d.ts.map +1 -1
  141. package/mixed-line-bar-chart/utils.js +11 -112
  142. package/mixed-line-bar-chart/utils.js.map +1 -1
  143. package/modal/styles.scoped.css +0 -31
  144. package/multiselect/styles.scoped.css +0 -4
  145. package/package.json +1 -1
  146. package/pagination/styles.scoped.css +0 -22
  147. package/pie-chart/styles.scoped.css +0 -25
  148. package/popover/styles.scoped.css +0 -35
  149. package/progress-bar/internal.d.ts.map +1 -1
  150. package/progress-bar/internal.js +1 -1
  151. package/progress-bar/internal.js.map +1 -1
  152. package/progress-bar/styles.scoped.css +0 -25
  153. package/property-filter/controller.d.ts +3 -3
  154. package/property-filter/controller.d.ts.map +1 -1
  155. package/property-filter/interfaces.d.ts +7 -20
  156. package/property-filter/interfaces.d.ts.map +1 -1
  157. package/property-filter/interfaces.js.map +1 -1
  158. package/property-filter/styles.scoped.css +0 -22
  159. package/property-filter/use-load-items.d.ts +1 -1
  160. package/radio-group/styles.scoped.css +0 -22
  161. package/s3-resource-selector/s3-in-context/styles.scoped.css +0 -6
  162. package/segmented-control/styles.scoped.css +0 -36
  163. package/select/parts/styles.scoped.css +0 -6
  164. package/select/styles.scoped.css +0 -4
  165. package/side-navigation/styles.scoped.css +0 -38
  166. package/space-between/styles.scoped.css +0 -40
  167. package/spinner/styles.scoped.css +0 -17
  168. package/split-panel/styles.scoped.css +0 -65
  169. package/status-indicator/styles.scoped.css +0 -20
  170. package/table/body-cell/styles.scoped.css +0 -29
  171. package/table/header-cell/styles.scoped.css +0 -32
  172. package/table/resizer/styles.scoped.css +0 -6
  173. package/table/selection-control/styles.scoped.css +0 -3
  174. package/table/styles.scoped.css +0 -39
  175. package/tabs/styles.scoped.css +0 -41
  176. package/tabs/tab-header-bar.d.ts.map +1 -1
  177. package/tabs/tab-header-bar.js +3 -1
  178. package/tabs/tab-header-bar.js.map +1 -1
  179. package/tag-editor/styles.scoped.css +0 -12
  180. package/test-utils/dom/split-panel/index.d.ts +1 -0
  181. package/test-utils/dom/split-panel/index.js +3 -0
  182. package/test-utils/dom/split-panel/index.js.map +1 -1
  183. package/test-utils/selectors/split-panel/index.d.ts +1 -0
  184. package/test-utils/selectors/split-panel/index.js +3 -0
  185. package/test-utils/selectors/split-panel/index.js.map +1 -1
  186. package/test-utils/tsconfig.tsbuildinfo +1 -1
  187. package/text-content/styles.scoped.css +0 -54
  188. package/text-filter/styles.scoped.css +0 -7
  189. package/textarea/styles.scoped.css +0 -30
  190. package/tiles/styles.scoped.css +0 -55
  191. package/toggle/styles.scoped.css +0 -14
  192. package/token-group/styles.scoped.css +0 -35
  193. package/top-navigation/1.0-beta/styles.scoped.css +0 -40
  194. package/top-navigation/styles.scoped.css +0 -75
  195. package/tutorial-panel/components/tutorial-detail-view/styles.scoped.css +0 -22
  196. package/tutorial-panel/components/tutorial-list/styles.scoped.css +0 -24
  197. package/tutorial-panel/styles.scoped.css +0 -5
  198. package/wizard/styles.scoped.css +0 -54
@@ -3,6 +3,7 @@
3
3
  import { useState } from 'react';
4
4
  import { nodeContains } from '../../internal/utils/dom';
5
5
  import styles from '../styles.css.js';
6
+ import { isYThreshold } from '../utils';
6
7
  var MAX_HOVER_MARGIN = 6;
7
8
  export function useMouseHover(_a) {
8
9
  var plotRef = _a.plotRef, scaledSeries = _a.scaledSeries, barGroups = _a.barGroups, highlightSeries = _a.highlightSeries, highlightPoint = _a.highlightPoint, highlightGroup = _a.highlightGroup, clearHighlightedSeries = _a.clearHighlightedSeries, isGroupNavigation = _a.isGroupNavigation, isHandlersDisabled = _a.isHandlersDisabled;
@@ -15,7 +16,7 @@ export function useMouseHover(_a) {
15
16
  .map(function (v) { return v.x; })
16
17
  .reduce(function (prev, curr) { return (Math.abs(curr - offsetX) < Math.abs(prev - offsetX) ? curr : prev); }, -Infinity);
17
18
  var closestY = scaledSeries
18
- .filter(function (v) { return v.x === closestX || v.series.type === 'threshold'; })
19
+ .filter(function (v) { return v.x === closestX || isYThreshold(v.series); })
19
20
  .map(function (v) { return v.y; })
20
21
  .reduce(function (prev, curr) { return (Math.abs(curr - offsetY) < Math.abs(prev - offsetY) ? curr : prev); }, -Infinity);
21
22
  if (isFinite(closestX)) {
@@ -23,7 +24,7 @@ export function useMouseHover(_a) {
23
24
  if (isFinite(closestY) &&
24
25
  Math.abs(offsetX - closestX) < MAX_HOVER_MARGIN &&
25
26
  Math.abs(offsetY - closestY) < MAX_HOVER_MARGIN) {
26
- var _a = scaledSeries.filter(function (s) { return (s.x === closestX || s.series.type === 'threshold') && s.y === closestY; })[0], color = _a.color, datum = _a.datum, series = _a.series;
27
+ var _a = scaledSeries.filter(function (s) { return (s.x === closestX || isYThreshold(s.series)) && s.y === closestY; })[0], color = _a.color, datum = _a.datum, series = _a.series;
27
28
  highlightSeries(series);
28
29
  highlightPoint({ x: closestX, y: closestY, color: color, datum: datum, series: series });
29
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-mouse-hover.js","sourceRoot":"","sources":["../../../../src/mixed-line-bar-chart/hooks/use-mouse-hover.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAKxD,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAItC,IAAM,gBAAgB,GAAG,CAAC,CAAC;AAc3B,MAAM,UAAU,aAAa,CAAI,EAUT;QATtB,OAAO,aAAA,EACP,YAAY,kBAAA,EACZ,SAAS,eAAA,EACT,eAAe,qBAAA,EACf,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,sBAAsB,4BAAA,EACtB,iBAAiB,uBAAA,EACjB,kBAAkB,wBAAA;IAEZ,IAAA,KAA8C,QAAQ,CAAgB,IAAI,CAAC,EAA1E,kBAAkB,QAAA,EAAE,qBAAqB,QAAiC,CAAC;IAElF,IAAM,iBAAiB,GAAG,UAAC,KAA+C;QACxE,IAAM,OAAO,GAAI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AAO,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,IAAI,OAAO,IAAI,OAAO,IAAI,CAAC,GAAG,MAAM,EAAE;gBACjF,cAAc,CAAC,UAAU,CAAC,CAAC;gBAC3B,OAAO;aACR;SACF;QACD,mCAAmC;QACnC,sBAAsB,EAAE,CAAC;IAC3B,CAAC,CAAC;IAEF,IAAM,cAAc,GAAG,UAAC,KAA+C;QACrE,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC,OAAQ,CAAC,GAAG,IAAI,CAAC,kBAAkB,EAAE;YAChE,IAAI,iBAAiB,EAAE;gBACrB,gBAAgB,CAAC,KAAK,CAAC,CAAC;aACzB;iBAAM,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;gBAClC,iBAAiB,CAAC,KAAK,CAAC,CAAC;aAC1B;SACF;IACH,CAAC,CAAC;IAEF,IAAM,aAAa,GAAG,UAAC,KAA+C;QACpE,IAAI,kBAAkB,EAAE;YACtB,OAAO;SACR;QACD,IACE,CAAC,YAAY,CAAC,OAAO,CAAC,OAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,aAAwB,CAAC;YACnE,wDAAwD;YACxD,CAAC,CAAC,KAAK,CAAC,aAAa,IAAK,KAAK,CAAC,aAAyB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;iBACpF,KAAK,CAAC,GAAG,CAAC;iBACV,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAC9B;YACA,qBAAqB,CAAC,IAAI,CAAC,CAAC;YAC5B,sBAAsB,EAAE,CAAC;SAC1B;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,kBAAkB,oBAAA,EAAE,cAAc,gBAAA,EAAE,aAAa,eAAA,EAAE,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useState } from 'react';\nimport { nodeContains } from '../../internal/utils/dom';\n\nimport { ScaledBarGroup } from '../make-scaled-bar-groups';\nimport { ScaledPoint } from '../make-scaled-series';\n\nimport styles from '../styles.css.js';\nimport { ChartPlotRef } from '../../internal/components/chart-plot';\nimport { MixedLineBarChartProps } from '../interfaces';\n\nconst MAX_HOVER_MARGIN = 6;\n\nexport interface UseMouseHoverProps<T> {\n plotRef: React.RefObject<ChartPlotRef>;\n scaledSeries: ReadonlyArray<ScaledPoint<T>>;\n barGroups: ScaledBarGroup<T>[];\n highlightSeries: (series: MixedLineBarChartProps.ChartSeries<T> | null) => void;\n highlightPoint: (point: ScaledPoint<T> | null) => void;\n highlightGroup: (groupIndex: number) => void;\n clearHighlightedSeries: () => void;\n isGroupNavigation: boolean;\n isHandlersDisabled: boolean;\n}\n\nexport function useMouseHover<T>({\n plotRef,\n scaledSeries,\n barGroups,\n highlightSeries,\n highlightPoint,\n highlightGroup,\n clearHighlightedSeries,\n isGroupNavigation,\n isHandlersDisabled,\n}: UseMouseHoverProps<T>) {\n const [verticalMarkerLeft, setVerticalMarkerLeft] = useState<number | null>(null);\n\n const onSeriesMouseMove = (event: React.MouseEvent<SVGElement, MouseEvent>) => {\n const svgRect = (event.target as SVGElement).getBoundingClientRect();\n const offsetX = event.clientX - svgRect.left;\n const offsetY = event.clientY - svgRect.top;\n\n const closestX = scaledSeries\n .map(v => v.x)\n .reduce((prev, curr) => (Math.abs(curr - offsetX) < Math.abs(prev - offsetX) ? curr : prev), -Infinity);\n\n const closestY = scaledSeries\n .filter(v => v.x === closestX || v.series.type === 'threshold')\n .map(v => v.y)\n .reduce((prev, curr) => (Math.abs(curr - offsetY) < Math.abs(prev - offsetY) ? curr : prev), -Infinity);\n\n if (isFinite(closestX)) {\n setVerticalMarkerLeft(closestX);\n if (\n isFinite(closestY) &&\n Math.abs(offsetX - closestX) < MAX_HOVER_MARGIN &&\n Math.abs(offsetY - closestY) < MAX_HOVER_MARGIN\n ) {\n const [{ color, datum, series }] = scaledSeries.filter(\n s => (s.x === closestX || s.series.type === 'threshold') && s.y === closestY\n );\n highlightSeries(series);\n highlightPoint({ x: closestX, y: closestY, color, datum, series });\n } else {\n highlightSeries(null);\n highlightPoint(null);\n }\n }\n };\n\n const onGroupMouseMove = (event: React.MouseEvent<SVGElement, MouseEvent>) => {\n const svgRect = (event.target as SVGElement).getBoundingClientRect();\n const offsetX = event.clientX - svgRect.left;\n const offsetY = event.clientY - svgRect.top;\n\n // If hovering over some group - highlight it.\n for (let groupIndex = 0; groupIndex < barGroups.length; groupIndex++) {\n const {\n position: { x, y, width, height },\n } = barGroups[groupIndex];\n\n if (x <= offsetX && offsetX <= x + width && y <= offsetY && offsetY <= y + height) {\n highlightGroup(groupIndex);\n return;\n }\n }\n // Otherwise - clear the highlight.\n clearHighlightedSeries();\n };\n\n const onSVGMouseMove = (event: React.MouseEvent<SVGElement, MouseEvent>) => {\n if (event.target === plotRef.current!.svg && !isHandlersDisabled) {\n if (isGroupNavigation) {\n onGroupMouseMove(event);\n } else if (scaledSeries.length > 0) {\n onSeriesMouseMove(event);\n }\n }\n };\n\n const onSVGMouseOut = (event: React.MouseEvent<SVGElement, MouseEvent>) => {\n if (isHandlersDisabled) {\n return;\n }\n if (\n !nodeContains(plotRef.current!.svg, event.relatedTarget as Element) ||\n // `classList` is not supported on IE11 for SVG elements\n ((event.relatedTarget && (event.relatedTarget as Element).getAttribute('class')) || '')\n .split(' ')\n .indexOf(styles.series) > -1\n ) {\n setVerticalMarkerLeft(null);\n clearHighlightedSeries();\n }\n };\n\n return { verticalMarkerLeft, onSVGMouseMove, onSVGMouseOut };\n}\n"]}
1
+ {"version":3,"file":"use-mouse-hover.js","sourceRoot":"","sources":["../../../../src/mixed-line-bar-chart/hooks/use-mouse-hover.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAKxD,OAAO,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KAAK,CAAC,aAAyB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;iBACpF,KAAK,CAAC,GAAG,CAAC;iBACV,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAC9B;YACA,qBAAqB,CAAC,IAAI,CAAC,CAAC;YAC5B,sBAAsB,EAAE,CAAC;SAC1B;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,kBAAkB,oBAAA,EAAE,cAAc,gBAAA,EAAE,aAAa,eAAA,EAAE,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useState } from 'react';\nimport { nodeContains } from '../../internal/utils/dom';\n\nimport { ScaledBarGroup } from '../make-scaled-bar-groups';\nimport { ScaledPoint } from '../make-scaled-series';\n\nimport styles from '../styles.css.js';\nimport { ChartPlotRef } from '../../internal/components/chart-plot';\nimport { MixedLineBarChartProps } from '../interfaces';\nimport { isYThreshold } from '../utils';\n\nconst MAX_HOVER_MARGIN = 6;\n\nexport interface UseMouseHoverProps<T> {\n plotRef: React.RefObject<ChartPlotRef>;\n scaledSeries: ReadonlyArray<ScaledPoint<T>>;\n barGroups: ScaledBarGroup<T>[];\n highlightSeries: (series: MixedLineBarChartProps.ChartSeries<T> | null) => void;\n highlightPoint: (point: ScaledPoint<T> | null) => void;\n highlightGroup: (groupIndex: number) => void;\n clearHighlightedSeries: () => void;\n isGroupNavigation: boolean;\n isHandlersDisabled: boolean;\n}\n\nexport function useMouseHover<T>({\n plotRef,\n scaledSeries,\n barGroups,\n highlightSeries,\n highlightPoint,\n highlightGroup,\n clearHighlightedSeries,\n isGroupNavigation,\n isHandlersDisabled,\n}: UseMouseHoverProps<T>) {\n const [verticalMarkerLeft, setVerticalMarkerLeft] = useState<number | null>(null);\n\n const onSeriesMouseMove = (event: React.MouseEvent<SVGElement, MouseEvent>) => {\n const svgRect = (event.target as SVGElement).getBoundingClientRect();\n const offsetX = event.clientX - svgRect.left;\n const offsetY = event.clientY - svgRect.top;\n\n const closestX = scaledSeries\n .map(v => v.x)\n .reduce((prev, curr) => (Math.abs(curr - offsetX) < Math.abs(prev - offsetX) ? curr : prev), -Infinity);\n\n const closestY = scaledSeries\n .filter(v => v.x === closestX || isYThreshold(v.series))\n .map(v => v.y)\n .reduce((prev, curr) => (Math.abs(curr - offsetY) < Math.abs(prev - offsetY) ? curr : prev), -Infinity);\n\n if (isFinite(closestX)) {\n setVerticalMarkerLeft(closestX);\n if (\n isFinite(closestY) &&\n Math.abs(offsetX - closestX) < MAX_HOVER_MARGIN &&\n Math.abs(offsetY - closestY) < MAX_HOVER_MARGIN\n ) {\n const [{ color, datum, series }] = scaledSeries.filter(\n s => (s.x === closestX || isYThreshold(s.series)) && s.y === closestY\n );\n highlightSeries(series);\n highlightPoint({ x: closestX, y: closestY, color, datum, series });\n } else {\n highlightSeries(null);\n highlightPoint(null);\n }\n }\n };\n\n const onGroupMouseMove = (event: React.MouseEvent<SVGElement, MouseEvent>) => {\n const svgRect = (event.target as SVGElement).getBoundingClientRect();\n const offsetX = event.clientX - svgRect.left;\n const offsetY = event.clientY - svgRect.top;\n\n // If hovering over some group - highlight it.\n for (let groupIndex = 0; groupIndex < barGroups.length; groupIndex++) {\n const {\n position: { x, y, width, height },\n } = barGroups[groupIndex];\n\n if (x <= offsetX && offsetX <= x + width && y <= offsetY && offsetY <= y + height) {\n highlightGroup(groupIndex);\n return;\n }\n }\n // Otherwise - clear the highlight.\n clearHighlightedSeries();\n };\n\n const onSVGMouseMove = (event: React.MouseEvent<SVGElement, MouseEvent>) => {\n if (event.target === plotRef.current!.svg && !isHandlersDisabled) {\n if (isGroupNavigation) {\n onGroupMouseMove(event);\n } else if (scaledSeries.length > 0) {\n onSeriesMouseMove(event);\n }\n }\n };\n\n const onSVGMouseOut = (event: React.MouseEvent<SVGElement, MouseEvent>) => {\n if (isHandlersDisabled) {\n return;\n }\n if (\n !nodeContains(plotRef.current!.svg, event.relatedTarget as Element) ||\n // `classList` is not supported on IE11 for SVG elements\n ((event.relatedTarget && (event.relatedTarget as Element).getAttribute('class')) || '')\n .split(' ')\n .indexOf(styles.series) > -1\n ) {\n setVerticalMarkerLeft(null);\n clearHighlightedSeries();\n }\n };\n\n return { verticalMarkerLeft, onSVGMouseMove, onSVGMouseOut };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-navigation.d.ts","sourceRoot":"","sources":["../../../../src/mixed-line-bar-chart/hooks/use-navigation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kDAAkD,CAAC;AAEjG,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,oBAAY,kBAAkB,CAAC,CAAC,SAAS,cAAc,IAAI,IAAI,CAC7D,mBAAmB,CAAC,CAAC,CAAC,EACtB,mBAAmB,GAAG,QAAQ,GAAG,eAAe,CACjD,GAAG;IACF,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/B,YAAY,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5C,gBAAgB,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACxC,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,YAAY,EAAE,IAAI,GAAG,sBAAsB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC3D,kBAAkB,EAAE,OAAO,CAAC;IAE5B,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG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AAC;IAC/B,YAAY,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5C,gBAAgB,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACxC,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,YAAY,EAAE,IAAI,GAAG,sBAAsB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC3D,kBAAkB,EAAE,OAAO,CAAC;IAE5B,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACnC,eAAe,CAAC,MAAM,EAAE,sBAAsB,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IAC5E,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,cAAc,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IACnD,sBAAsB,IAAI,IAAI,CAAC;CAChC,CAAC;AAEF,wBAAgB,aAAa,CAAC,CAAC,SAAS,cAAc,EAAE,EACtD,MAAM,EACN,aAAa,EACb,YAAY,EACZ,SAAS,EACT,MAAM,EACN,MAAM,EACN,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,cAAc,EACd,cAAc,GACf,EAAE,kBAAkB,CAAC,CAAC,CAAC;;;uBAqKZ,mBAAmB;EA+B9B"}
@@ -3,7 +3,7 @@ import { __assign } from "tslib";
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import { useCallback, useMemo, useState } from 'react';
5
5
  import { KeyCode } from '../../internal/keycode';
6
- import { findNavigableSeries, nextValidDomainIndex } from '../utils';
6
+ import { findNavigableSeries, isXThreshold, isYThreshold, nextValidDomainIndex } from '../utils';
7
7
  export function useNavigation(_a) {
8
8
  var series = _a.series, visibleSeries = _a.visibleSeries, scaledSeries = _a.scaledSeries, barGroups = _a.barGroups, xScale = _a.xScale, yScale = _a.yScale, highlightedPoint = _a.highlightedPoint, highlightedGroupIndex = _a.highlightedGroupIndex, highlightedSeries = _a.highlightedSeries, legendSeries = _a.legendSeries, isHandlersDisabled = _a.isHandlersDisabled, pinPopover = _a.pinPopover, highlightSeries = _a.highlightSeries, highlightGroup = _a.highlightGroup, highlightPoint = _a.highlightPoint;
9
9
  var _b = useState(null), targetX = _b[0], setTargetX = _b[1];
@@ -44,7 +44,7 @@ export function useNavigation(_a) {
44
44
  }
45
45
  };
46
46
  var moveBetweenSeries = useCallback(function (direction) {
47
- var _a, _b, _c;
47
+ var _a, _b, _c, _d;
48
48
  if (isGroupNavigation) {
49
49
  return;
50
50
  }
@@ -77,21 +77,12 @@ export function useNavigation(_a) {
77
77
  targetXPoint = 0;
78
78
  }
79
79
  if (nextSeries.type === 'line') {
80
- var nextSeriesData = nextSeries.data;
81
- var lookingForScaled_1 = targetXPoint; // scaled X in previous series
82
- var nextPoint = nextSeriesData
83
- // scale all points in series
84
- .map(function (d) { return ({
85
- x: (xScale.d3Scale(d.x) || 0) + xOffset,
86
- y: yScale.d3Scale(d.y) || 0,
87
- datum: d
88
- }); })
89
- // find the closest point to previous X
90
- .reduce(function (prev, curr) { return (Math.abs(curr.x - lookingForScaled_1) < Math.abs(prev.x - lookingForScaled_1) ? curr : prev); }, { x: -Infinity, y: -Infinity });
80
+ var nextScaledSeries = scaledSeries.filter(function (it) { return it.series === nextSeries; });
81
+ var closestNextSeriesPoint = nextScaledSeries.reduce(function (prev, curr) { return (Math.abs(curr.x - targetXPoint) < Math.abs(prev.x - targetXPoint) ? curr : prev); }, { x: -Infinity, y: -Infinity });
91
82
  highlightSeries(nextSeries);
92
- highlightPoint(__assign(__assign({}, nextPoint), { color: nextInternalSeries.color, series: nextSeries }));
83
+ highlightPoint(__assign(__assign({}, closestNextSeriesPoint), { color: nextInternalSeries.color, series: nextSeries }));
93
84
  }
94
- else if (nextSeries.type === 'threshold') {
85
+ else if (isYThreshold(nextSeries)) {
95
86
  var scaledTargetIndex = scaledSeries.map(function (it) { var _a; return ((_a = it.datum) === null || _a === void 0 ? void 0 : _a.x) || null; }).indexOf(targetX);
96
87
  highlightSeries(nextSeries);
97
88
  highlightPoint({
@@ -102,6 +93,16 @@ export function useNavigation(_a) {
102
93
  datum: (_c = scaledSeries[scaledTargetIndex]) === null || _c === void 0 ? void 0 : _c.datum
103
94
  });
104
95
  }
96
+ else if (isXThreshold(nextSeries)) {
97
+ highlightSeries(nextSeries);
98
+ highlightPoint({
99
+ x: (_d = xScale.d3Scale(nextSeries.x)) !== null && _d !== void 0 ? _d : NaN,
100
+ y: yScale.d3Scale.range()[0],
101
+ color: nextInternalSeries.color,
102
+ series: nextSeries,
103
+ datum: { x: nextSeries.x, y: NaN }
104
+ });
105
+ }
105
106
  }, [
106
107
  isGroupNavigation,
107
108
  xScale,
@@ -118,27 +119,14 @@ export function useNavigation(_a) {
118
119
  var _a;
119
120
  var series = highlightedSeries || visibleSeries[0].series;
120
121
  var previousPoint = highlightedPoint || scaledSeries[0];
121
- if (series.type === 'line') {
122
- // find previous point in series
123
- var indexOfPreviousPoint = (previousPoint === null || previousPoint === void 0 ? void 0 : previousPoint.datum)
124
- ? series.data.indexOf(previousPoint.datum)
125
- : 0;
126
- var nextPointIndex = circleIndex(indexOfPreviousPoint + direction, [0, series.data.length - 1]);
127
- var nextPoint_1 = series.data[nextPointIndex];
128
- // find scaled next point
129
- var nextPointScaled = scaledSeries.filter(function (s) { return s.datum === nextPoint_1; })[0] || null;
130
- setTargetX(nextPoint_1.x);
131
- highlightSeries(series);
132
- highlightPoint(nextPointScaled);
133
- }
134
- else if (series.type === 'threshold') {
135
- var scaledThresholdSeries = scaledSeries.filter(function (it) { return it.series === series; })[0];
136
- var scaledDataSeries = scaledSeries.filter(function (it) { return it.datum; });
137
- var indexOfPreviousPoint = scaledDataSeries.map(function (it) { return it.x; }).indexOf(previousPoint.x);
138
- var nextPointIndex = circleIndex(indexOfPreviousPoint + direction, [0, scaledDataSeries.length - 1]);
139
- setTargetX(((_a = scaledDataSeries[nextPointIndex].datum) === null || _a === void 0 ? void 0 : _a.x) || null);
122
+ if (series.type === 'line' || isYThreshold(series)) {
123
+ var targetScaledSeries = scaledSeries.filter(function (it) { return it.series === series; });
124
+ var indexOfPreviousPoint = targetScaledSeries.map(function (it) { return it.x; }).indexOf(previousPoint.x);
125
+ var nextPointIndex = circleIndex(indexOfPreviousPoint + direction, [0, targetScaledSeries.length - 1]);
126
+ var nextPoint = targetScaledSeries[nextPointIndex];
127
+ setTargetX(((_a = nextPoint.datum) === null || _a === void 0 ? void 0 : _a.x) || null);
140
128
  highlightSeries(series);
141
- highlightPoint(__assign(__assign({}, scaledThresholdSeries), { datum: scaledDataSeries[nextPointIndex].datum, x: scaledDataSeries[nextPointIndex].x }));
129
+ highlightPoint(nextPoint);
142
130
  }
143
131
  else if (series.type === 'bar') {
144
132
  var xDomain = xScale.domain;
@@ -1 +1 @@
1
- {"version":3,"file":"use-navigation.js","sourceRoot":"","sources":["../../../../src/mixed-line-bar-chart/hooks/use-navigation.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAIjD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAyBrE,MAAM,UAAU,aAAa,CAA2B,EAgBhC;QAftB,MAAM,YAAA,EACN,aAAa,mBAAA,EACb,YAAY,kBAAA,EACZ,SAAS,eAAA,EACT,MAAM,YAAA,EACN,MAAM,YAAA,EACN,gBAAgB,sBAAA,EAChB,qBAAqB,2BAAA,EACrB,iBAAiB,uBAAA,EACjB,YAAY,kBAAA,EACZ,kBAAkB,wBAAA,EAClB,UAAU,gBAAA,EACV,eAAe,qBAAA,EACf,cAAc,oBAAA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AK,OAAO,CAAC,EAAE,EAAE;YACtD,iBAAiB,CAAC,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACtD;aAAM,IAAI,OAAO,KAAK,OAAO,CAAC,IAAI,IAAI,OAAO,KAAK,OAAO,CAAC,KAAK,EAAE;YAChE,gBAAgB,CAAC,OAAO,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACtD;aAAM,IAAI,OAAO,KAAK,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,OAAO,CAAC,KAAK,EAAE;YACjE,UAAU,EAAE,CAAC;SACd;IACH,CAAC,EACD,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,UAAU,CAAC,CACtE,CAAC;IAEF,OAAO,EAAE,iBAAiB,mBAAA,EAAE,OAAO,SAAA,EAAE,SAAS,WAAA,EAAE,CAAC;AACnD,CAAC;AAED,kFAAkF;AAClF,SAAS,WAAW,CAAC,KAAa,EAAE,EAA4B;QAA3B,IAAI,QAAA,EAAE,EAAE,QAAA;IAC3C,IAAI,KAAK,GAAG,IAAI,EAAE;QAChB,OAAO,EAAE,CAAC;KACX;IACD,IAAI,KAAK,GAAG,EAAE,EAAE;QACd,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useCallback, useMemo, useState } from 'react';\nimport { KeyCode } from '../../internal/keycode';\nimport { ChartContainerProps } from '../chart-container';\nimport { ChartDataTypes, MixedLineBarChartProps } from '../interfaces';\nimport { ChartScale, NumericChartScale } from '../../internal/components/cartesian-chart/scales';\nimport { findNavigableSeries, nextValidDomainIndex } from '../utils';\nimport { ScaledPoint } from '../make-scaled-series';\nimport { ScaledBarGroup } from '../make-scaled-bar-groups';\n\nexport type UseNavigationProps<T extends ChartDataTypes> = Pick<\n ChartContainerProps<T>,\n 'highlightedSeries' | 'series' | 'visibleSeries'\n> & {\n xScale: ChartScale;\n yScale: NumericChartScale;\n barGroups: ScaledBarGroup<T>[];\n scaledSeries: ReadonlyArray<ScaledPoint<T>>;\n\n highlightedPoint: ScaledPoint<T> | null;\n highlightedGroupIndex: number | null;\n legendSeries: null | MixedLineBarChartProps.ChartSeries<T>;\n isHandlersDisabled: boolean;\n\n pinPopover(pinned?: boolean): void;\n highlightSeries(series: MixedLineBarChartProps.ChartSeries<T> | null): void;\n highlightGroup(groupIndex: number): void;\n highlightPoint(point: ScaledPoint<T> | null): void;\n clearHighlightedSeries(): void;\n};\n\nexport function useNavigation<T extends ChartDataTypes>({\n series,\n visibleSeries,\n scaledSeries,\n barGroups,\n xScale,\n yScale,\n highlightedPoint,\n highlightedGroupIndex,\n highlightedSeries,\n legendSeries,\n isHandlersDisabled,\n pinPopover,\n highlightSeries,\n highlightGroup,\n highlightPoint,\n}: UseNavigationProps<T>) {\n const [targetX, setTargetX] = useState<T | null>(null);\n\n // There are two different types of navigation:\n // 1) Group navigation for any chart that contains a bar series\n // 2) Line navigation for any chart that only contains lines and thresholds\n const isGroupNavigation = visibleSeries.some(({ series }) => series.type === 'bar');\n\n // Make a list of series that can be navigated between. Bar series are treated as one.\n const { navigableSeries } = useMemo(() => findNavigableSeries(visibleSeries), [visibleSeries]);\n\n const onBarGroupFocus = () => {\n const groupIndex = highlightedGroupIndex ?? 0;\n setTargetX((xScale.domain as T[])[groupIndex]);\n highlightGroup(groupIndex);\n };\n\n const onLineGroupFocus = () => {\n if (!highlightedSeries || !highlightedPoint) {\n const targetSeries = highlightedSeries ?? legendSeries ?? series[0]?.series ?? null;\n highlightSeries(targetSeries);\n for (const scaledS of scaledSeries) {\n if (scaledS.series === targetSeries) {\n highlightPoint(scaledS);\n return;\n }\n }\n }\n };\n\n const onFocus = () => {\n if (isGroupNavigation) {\n onBarGroupFocus();\n } else {\n onLineGroupFocus();\n }\n };\n\n const moveBetweenSeries = useCallback(\n (direction: number) => {\n if (isGroupNavigation) {\n return;\n }\n\n const xOffset = xScale.isCategorical() ? Math.max(0, xScale.d3Scale.bandwidth() - 1) / 2 : 0;\n const MAX_SERIES_INDEX = navigableSeries.length - 1;\n\n // Find the index of the currently highlighted series (if any)\n let previousSeriesIndex = -1;\n if (highlightedSeries) {\n previousSeriesIndex = navigableSeries.indexOf(highlightedSeries);\n }\n\n // Move forwards or backwards to the new series\n let nextSeriesIndex = 0;\n if (previousSeriesIndex !== -1) {\n nextSeriesIndex = previousSeriesIndex + direction;\n if (nextSeriesIndex > MAX_SERIES_INDEX) {\n nextSeriesIndex = 0;\n } else if (nextSeriesIndex < 0) {\n nextSeriesIndex = MAX_SERIES_INDEX;\n }\n }\n\n const nextSeries = navigableSeries[nextSeriesIndex];\n const nextInternalSeries = series.filter(({ series }) => series === nextSeries)[0];\n\n // 2. Find point in the next series\n let targetXPoint = (xScale.d3Scale(targetX as any) ?? NaN) + xOffset;\n if (!isFinite(targetXPoint)) {\n targetXPoint = 0;\n }\n\n if (nextSeries.type === 'line') {\n const nextSeriesData = nextSeries.data as ReadonlyArray<MixedLineBarChartProps.Datum<T>>;\n const lookingForScaled = targetXPoint; // scaled X in previous series\n\n const nextPoint = nextSeriesData\n // scale all points in series\n .map(d => ({\n x: (xScale.d3Scale(d.x as any) || 0) + xOffset,\n y: yScale.d3Scale(d.y) || 0,\n datum: d,\n }))\n // find the closest point to previous X\n .reduce(\n (prev, curr) => (Math.abs(curr.x - lookingForScaled) < Math.abs(prev.x - lookingForScaled) ? curr : prev),\n { x: -Infinity, y: -Infinity }\n );\n\n highlightSeries(nextSeries);\n highlightPoint({ ...nextPoint, color: nextInternalSeries.color, series: nextSeries });\n } else if (nextSeries.type === 'threshold') {\n const scaledTargetIndex = scaledSeries.map(it => it.datum?.x || null).indexOf(targetX);\n highlightSeries(nextSeries);\n highlightPoint({\n x: targetXPoint,\n y: yScale.d3Scale(nextSeries.y) ?? NaN,\n color: nextInternalSeries.color,\n series: nextSeries,\n datum: scaledSeries[scaledTargetIndex]?.datum,\n });\n }\n },\n [\n isGroupNavigation,\n xScale,\n navigableSeries,\n highlightedSeries,\n scaledSeries,\n series,\n targetX,\n highlightSeries,\n highlightPoint,\n yScale,\n ]\n );\n\n const moveWithinSeries = useCallback(\n (direction: number) => {\n const series = highlightedSeries || visibleSeries[0].series;\n const previousPoint = highlightedPoint || scaledSeries[0];\n\n if (series.type === 'line') {\n // find previous point in series\n const indexOfPreviousPoint = previousPoint?.datum\n ? (series.data as ReadonlyArray<MixedLineBarChartProps.Datum<T>>).indexOf(previousPoint.datum)\n : 0;\n const nextPointIndex = circleIndex(indexOfPreviousPoint + direction, [0, series.data.length - 1]);\n const nextPoint = series.data[nextPointIndex];\n\n // find scaled next point\n const nextPointScaled = scaledSeries.filter(s => s.datum === nextPoint)[0] || null;\n\n setTargetX(nextPoint.x as T);\n highlightSeries(series);\n highlightPoint(nextPointScaled);\n } else if (series.type === 'threshold') {\n const [scaledThresholdSeries] = scaledSeries.filter(it => it.series === series);\n const scaledDataSeries = scaledSeries.filter(it => it.datum);\n const indexOfPreviousPoint = scaledDataSeries.map(it => it.x).indexOf(previousPoint.x);\n const nextPointIndex = circleIndex(indexOfPreviousPoint + direction, [0, scaledDataSeries.length - 1]);\n setTargetX(scaledDataSeries[nextPointIndex].datum?.x || null);\n highlightSeries(series);\n highlightPoint({\n ...scaledThresholdSeries,\n datum: scaledDataSeries[nextPointIndex].datum,\n x: scaledDataSeries[nextPointIndex].x,\n });\n } else if (series.type === 'bar') {\n const xDomain = xScale.domain as T[];\n const MAX_GROUP_INDEX = xDomain.length - 1;\n\n let nextGroupIndex = 0;\n if (highlightedGroupIndex !== null) {\n // find next group\n nextGroupIndex = highlightedGroupIndex + direction;\n if (nextGroupIndex > MAX_GROUP_INDEX) {\n nextGroupIndex = 0;\n } else if (nextGroupIndex < 0) {\n nextGroupIndex = MAX_GROUP_INDEX;\n }\n }\n\n const nextDomainIndex = nextValidDomainIndex(nextGroupIndex, barGroups, direction);\n setTargetX(xDomain[nextDomainIndex]);\n highlightGroup(nextDomainIndex);\n }\n },\n [\n highlightedSeries,\n visibleSeries,\n highlightedPoint,\n scaledSeries,\n highlightSeries,\n highlightPoint,\n xScale.domain,\n highlightedGroupIndex,\n barGroups,\n highlightGroup,\n ]\n );\n\n const onKeyDown = useCallback(\n (event: React.KeyboardEvent) => {\n const keyCode = event.keyCode;\n if (\n keyCode !== KeyCode.up &&\n keyCode !== KeyCode.right &&\n keyCode !== KeyCode.down &&\n keyCode !== KeyCode.left &&\n keyCode !== KeyCode.space &&\n keyCode !== KeyCode.enter\n ) {\n return;\n }\n\n event.preventDefault();\n\n if (isHandlersDisabled) {\n return;\n }\n\n if (keyCode === KeyCode.down || keyCode === KeyCode.up) {\n moveBetweenSeries(keyCode === KeyCode.down ? 1 : -1);\n } else if (keyCode === KeyCode.left || keyCode === KeyCode.right) {\n moveWithinSeries(keyCode === KeyCode.right ? 1 : -1);\n } else if (keyCode === KeyCode.enter || keyCode === KeyCode.space) {\n pinPopover();\n }\n },\n [moveWithinSeries, moveBetweenSeries, isHandlersDisabled, pinPopover]\n );\n\n return { isGroupNavigation, onFocus, onKeyDown };\n}\n\n// Returns given index if it is in range or the opposite range boundary otherwise.\nfunction circleIndex(index: number, [from, to]: [number, number]): number {\n if (index < from) {\n return to;\n }\n if (index > to) {\n return from;\n }\n return index;\n}\n"]}
1
+ {"version":3,"file":"use-navigation.js","sourceRoot":"","sources":["../../../../src/mixed-line-bar-chart/hooks/use-navigation.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAIjD,OAAO,EAAE,mBAAmB,EAAE,YAAY,E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UAAU,EAAE,CAAC;SACd;IACH,CAAC,EACD,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,UAAU,CAAC,CACtE,CAAC;IAEF,OAAO,EAAE,iBAAiB,mBAAA,EAAE,OAAO,SAAA,EAAE,SAAS,WAAA,EAAE,CAAC;AACnD,CAAC;AAED,kFAAkF;AAClF,SAAS,WAAW,CAAC,KAAa,EAAE,EAA4B;QAA3B,IAAI,QAAA,EAAE,EAAE,QAAA;IAC3C,IAAI,KAAK,GAAG,IAAI,EAAE;QAChB,OAAO,EAAE,CAAC;KACX;IACD,IAAI,KAAK,GAAG,EAAE,EAAE;QACd,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useCallback, useMemo, useState } from 'react';\nimport { KeyCode } from '../../internal/keycode';\nimport { ChartContainerProps } from '../chart-container';\nimport { ChartDataTypes, MixedLineBarChartProps } from '../interfaces';\nimport { ChartScale, NumericChartScale } from '../../internal/components/cartesian-chart/scales';\nimport { findNavigableSeries, isXThreshold, isYThreshold, nextValidDomainIndex } from '../utils';\nimport { ScaledPoint } from '../make-scaled-series';\nimport { ScaledBarGroup } from '../make-scaled-bar-groups';\n\nexport type UseNavigationProps<T extends ChartDataTypes> = Pick<\n ChartContainerProps<T>,\n 'highlightedSeries' | 'series' | 'visibleSeries'\n> & {\n xScale: ChartScale;\n yScale: NumericChartScale;\n barGroups: ScaledBarGroup<T>[];\n scaledSeries: ReadonlyArray<ScaledPoint<T>>;\n\n highlightedPoint: ScaledPoint<T> | null;\n highlightedGroupIndex: number | null;\n legendSeries: null | MixedLineBarChartProps.ChartSeries<T>;\n isHandlersDisabled: boolean;\n\n pinPopover(pinned?: boolean): void;\n highlightSeries(series: MixedLineBarChartProps.ChartSeries<T> | null): void;\n highlightGroup(groupIndex: number): void;\n highlightPoint(point: ScaledPoint<T> | null): void;\n clearHighlightedSeries(): void;\n};\n\nexport function useNavigation<T extends ChartDataTypes>({\n series,\n visibleSeries,\n scaledSeries,\n barGroups,\n xScale,\n yScale,\n highlightedPoint,\n highlightedGroupIndex,\n highlightedSeries,\n legendSeries,\n isHandlersDisabled,\n pinPopover,\n highlightSeries,\n highlightGroup,\n highlightPoint,\n}: UseNavigationProps<T>) {\n const [targetX, setTargetX] = useState<T | null>(null);\n\n // There are two different types of navigation:\n // 1) Group navigation for any chart that contains a bar series\n // 2) Line navigation for any chart that only contains lines and thresholds\n const isGroupNavigation = visibleSeries.some(({ series }) => series.type === 'bar');\n\n // Make a list of series that can be navigated between. Bar series are treated as one.\n const { navigableSeries } = useMemo(() => findNavigableSeries(visibleSeries), [visibleSeries]);\n\n const onBarGroupFocus = () => {\n const groupIndex = highlightedGroupIndex ?? 0;\n setTargetX((xScale.domain as T[])[groupIndex]);\n highlightGroup(groupIndex);\n };\n\n const onLineGroupFocus = () => {\n if (!highlightedSeries || !highlightedPoint) {\n const targetSeries = highlightedSeries ?? legendSeries ?? series[0]?.series ?? null;\n highlightSeries(targetSeries);\n for (const scaledS of scaledSeries) {\n if (scaledS.series === targetSeries) {\n highlightPoint(scaledS);\n return;\n }\n }\n }\n };\n\n const onFocus = () => {\n if (isGroupNavigation) {\n onBarGroupFocus();\n } else {\n onLineGroupFocus();\n }\n };\n\n const moveBetweenSeries = useCallback(\n (direction: number) => {\n if (isGroupNavigation) {\n return;\n }\n\n const xOffset = xScale.isCategorical() ? Math.max(0, xScale.d3Scale.bandwidth() - 1) / 2 : 0;\n const MAX_SERIES_INDEX = navigableSeries.length - 1;\n\n // Find the index of the currently highlighted series (if any)\n let previousSeriesIndex = -1;\n if (highlightedSeries) {\n previousSeriesIndex = navigableSeries.indexOf(highlightedSeries);\n }\n\n // Move forwards or backwards to the new series\n let nextSeriesIndex = 0;\n if (previousSeriesIndex !== -1) {\n nextSeriesIndex = previousSeriesIndex + direction;\n if (nextSeriesIndex > MAX_SERIES_INDEX) {\n nextSeriesIndex = 0;\n } else if (nextSeriesIndex < 0) {\n nextSeriesIndex = MAX_SERIES_INDEX;\n }\n }\n\n const nextSeries = navigableSeries[nextSeriesIndex];\n const nextInternalSeries = series.filter(({ series }) => series === nextSeries)[0];\n\n // 2. Find point in the next series\n let targetXPoint = (xScale.d3Scale(targetX as any) ?? NaN) + xOffset;\n if (!isFinite(targetXPoint)) {\n targetXPoint = 0;\n }\n\n if (nextSeries.type === 'line') {\n const nextScaledSeries = scaledSeries.filter(it => it.series === nextSeries);\n const closestNextSeriesPoint = nextScaledSeries.reduce(\n (prev, curr) => (Math.abs(curr.x - targetXPoint) < Math.abs(prev.x - targetXPoint) ? curr : prev),\n { x: -Infinity, y: -Infinity }\n );\n highlightSeries(nextSeries);\n highlightPoint({ ...closestNextSeriesPoint, color: nextInternalSeries.color, series: nextSeries });\n } else if (isYThreshold(nextSeries)) {\n const scaledTargetIndex = scaledSeries.map(it => it.datum?.x || null).indexOf(targetX);\n highlightSeries(nextSeries);\n highlightPoint({\n x: targetXPoint,\n y: yScale.d3Scale(nextSeries.y) ?? NaN,\n color: nextInternalSeries.color,\n series: nextSeries,\n datum: scaledSeries[scaledTargetIndex]?.datum,\n });\n } else if (isXThreshold(nextSeries)) {\n highlightSeries(nextSeries);\n highlightPoint({\n x: xScale.d3Scale(nextSeries.x as any) ?? NaN,\n y: yScale.d3Scale.range()[0],\n color: nextInternalSeries.color,\n series: nextSeries,\n datum: { x: nextSeries.x, y: NaN },\n });\n }\n },\n [\n isGroupNavigation,\n xScale,\n navigableSeries,\n highlightedSeries,\n scaledSeries,\n series,\n targetX,\n highlightSeries,\n highlightPoint,\n yScale,\n ]\n );\n\n const moveWithinSeries = useCallback(\n (direction: number) => {\n const series = highlightedSeries || visibleSeries[0].series;\n const previousPoint = highlightedPoint || scaledSeries[0];\n\n if (series.type === 'line' || isYThreshold(series)) {\n const targetScaledSeries = scaledSeries.filter(it => it.series === series);\n const indexOfPreviousPoint = targetScaledSeries.map(it => it.x).indexOf(previousPoint.x);\n const nextPointIndex = circleIndex(indexOfPreviousPoint + direction, [0, targetScaledSeries.length - 1]);\n const nextPoint = targetScaledSeries[nextPointIndex];\n\n setTargetX(nextPoint.datum?.x || null);\n highlightSeries(series);\n highlightPoint(nextPoint);\n } else if (series.type === 'bar') {\n const xDomain = xScale.domain as T[];\n const MAX_GROUP_INDEX = xDomain.length - 1;\n\n let nextGroupIndex = 0;\n if (highlightedGroupIndex !== null) {\n // find next group\n nextGroupIndex = highlightedGroupIndex + direction;\n if (nextGroupIndex > MAX_GROUP_INDEX) {\n nextGroupIndex = 0;\n } else if (nextGroupIndex < 0) {\n nextGroupIndex = MAX_GROUP_INDEX;\n }\n }\n\n const nextDomainIndex = nextValidDomainIndex(nextGroupIndex, barGroups, direction);\n setTargetX(xDomain[nextDomainIndex]);\n highlightGroup(nextDomainIndex);\n }\n },\n [\n highlightedSeries,\n visibleSeries,\n highlightedPoint,\n scaledSeries,\n highlightSeries,\n highlightPoint,\n xScale.domain,\n highlightedGroupIndex,\n barGroups,\n highlightGroup,\n ]\n );\n\n const onKeyDown = useCallback(\n (event: React.KeyboardEvent) => {\n const keyCode = event.keyCode;\n if (\n keyCode !== KeyCode.up &&\n keyCode !== KeyCode.right &&\n keyCode !== KeyCode.down &&\n keyCode !== KeyCode.left &&\n keyCode !== KeyCode.space &&\n keyCode !== KeyCode.enter\n ) {\n return;\n }\n\n event.preventDefault();\n\n if (isHandlersDisabled) {\n return;\n }\n\n if (keyCode === KeyCode.down || keyCode === KeyCode.up) {\n moveBetweenSeries(keyCode === KeyCode.down ? 1 : -1);\n } else if (keyCode === KeyCode.left || keyCode === KeyCode.right) {\n moveWithinSeries(keyCode === KeyCode.right ? 1 : -1);\n } else if (keyCode === KeyCode.enter || keyCode === KeyCode.space) {\n pinPopover();\n }\n },\n [moveWithinSeries, moveBetweenSeries, isHandlersDisabled, pinPopover]\n );\n\n return { isGroupNavigation, onFocus, onKeyDown };\n}\n\n// Returns given index if it is in range or the opposite range boundary otherwise.\nfunction circleIndex(index: number, [from, to]: [number, number]): number {\n if (index < from) {\n return to;\n }\n if (index > to) {\n return from;\n }\n return index;\n}\n"]}
@@ -53,13 +53,23 @@ export declare namespace MixedLineBarChartProps {
53
53
  export interface LineDataSeries<T> extends IDataSeries<T> {
54
54
  type: 'line';
55
55
  }
56
- export interface ThresholdSeries extends Omit<IDataSeries<never>, 'data' | 'valueFormatter'> {
56
+ export interface ThresholdSeries<T = any> extends Omit<IDataSeries<never>, 'data' | 'valueFormatter'> {
57
+ type: 'threshold';
58
+ y?: number;
59
+ x?: T;
60
+ valueFormatter?: CartesianChartProps.TickFormatter<number>;
61
+ }
62
+ export interface YThresholdSeries extends Omit<ThresholdSeries<never>, 'x'> {
57
63
  type: 'threshold';
58
64
  y: number;
59
65
  valueFormatter?: CartesianChartProps.TickFormatter<number>;
60
66
  }
67
+ export interface XThresholdSeries<T> extends Omit<ThresholdSeries<T>, 'y' | 'valueFormatter'> {
68
+ type: 'threshold';
69
+ x: T;
70
+ }
61
71
  export type DataSeries<T> = LineDataSeries<T> | BarDataSeries<T>;
62
- export type ChartSeries<T> = DataSeries<T> | ThresholdSeries;
72
+ export type ChartSeries<T> = DataSeries<T> | ThresholdSeries<T>;
63
73
  export type FilterChangeDetail<T> = CartesianChartProps.FilterChangeDetail<ChartSeries<T>>;
64
74
  export type HighlightChangeDetail<T> = CartesianChartProps.HighlightChangeDetail<ChartSeries<T>>;
65
75
  export type TickFormatter<T> = CartesianChartProps.TickFormatter<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AAExF,oBAAY,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAEpD,oBAAY,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC;AACxC,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AC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAEjE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;IAEhE,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,mBAAmB,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3F,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAAI,mBAAmB,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjG,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,mBAAmB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAEpE,MAAM,MAAM,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,IAAI,mBAAmB,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAEnG,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;;CACjE"}
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { CartesianChartProps } from '../internal/components/cartesian-chart/interfaces';\n\nexport type ChartDataTypes = number | string | Date;\n\nexport type SeriesType = 'line' | 'bar';\nexport type ScaleType = 'linear' | 'log' | 'time' | 'categorical';\nexport type ScaleRange = [number, number];\n\nexport interface InternalChartSeries<T> {\n index: number;\n color: string;\n series: MixedLineBarChartProps.ChartSeries<T>;\n}\n\nexport interface MixedLineBarChartProps<T extends ChartDataTypes>\n extends CartesianChartProps<T, MixedLineBarChartProps.ChartSeries<T>> {\n /**\n * Array that represents the source of data for the displayed chart.\n * Each element can represent a line series, bar series, or a threshold, and can have the following properties:\n *\n * * `title` (string): A human-readable title for this series\n * * `type` (string): Series type (`\"line\"`, `\"bar\"`, or `\"threshold\"`)\n * * `data` (Array): An array of data points, represented as objects with `x` and `y` properties\n * * `color` (string): (Optional) A color hex value for this series. When assigned, it takes priority over the automatically assigned color\n * * `valueFormatter` (Function): (Optional) A function that formats data values before rendering in the UI, For example, in the details popover.\n */\n series: ReadonlyArray<MixedLineBarChartProps.ChartSeries<T>>;\n\n /**\n * When set to `true`, bars in the same data point are stacked instead of grouped next to each other.\n */\n stackedBars?: boolean;\n\n /**\n * When set to `true`, the x and y axes are flipped, which causes any bars to be rendered horizontally instead of vertically.\n * This can only be used when the chart consists exclusively of bar series.\n */\n horizontalBars?: boolean;\n\n /**\n * When set to `true`, adds a visual emphasis on the zero baseline axis.\n * See the usage guidelines for more details.\n */\n emphasizeBaselineAxis?: boolean;\n}\n\nexport namespace MixedLineBarChartProps {\n export interface Datum<T> {\n x: T;\n y: number;\n }\n\n interface IDataSeries<T> {\n type: 'line' | 'bar' | 'threshold';\n title: string;\n color?: string;\n\n // This makes sure that the element type of the array is reduced to just one type,\n // even if `T` is a union type, e.g. `number | string`.\n data: T extends unknown ? ReadonlyArray<Datum<T>> : ReadonlyArray<Datum<T>>;\n valueFormatter?: T extends unknown\n ? CartesianChartProps.ValueFormatter<number, T>\n : CartesianChartProps.ValueFormatter<number, T>;\n }\n\n export interface BarDataSeries<T> extends IDataSeries<T> {\n type: 'bar';\n }\n\n export interface LineDataSeries<T> extends IDataSeries<T> {\n type: 'line';\n }\n\n export interface ThresholdSeries extends Omit<IDataSeries<never>, 'data' | 'valueFormatter'> {\n type: 'threshold';\n y: number;\n valueFormatter?: CartesianChartProps.TickFormatter<number>;\n }\n\n export type DataSeries<T> = LineDataSeries<T> | BarDataSeries<T>;\n\n export type ChartSeries<T> = DataSeries<T> | ThresholdSeries;\n\n export type FilterChangeDetail<T> = CartesianChartProps.FilterChangeDetail<ChartSeries<T>>;\n\n export type HighlightChangeDetail<T> = CartesianChartProps.HighlightChangeDetail<ChartSeries<T>>;\n\n export type TickFormatter<T> = CartesianChartProps.TickFormatter<T>;\n\n export type ValueFormatter<YType, XType = null> = CartesianChartProps.ValueFormatter<YType, XType>;\n\n export type I18nStrings<T> = CartesianChartProps.I18nStrings<T>;\n}\n"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { CartesianChartProps } from '../internal/components/cartesian-chart/interfaces';\n\nexport type ChartDataTypes = number | string | Date;\n\nexport type SeriesType = 'line' | 'bar';\nexport type ScaleType = 'linear' | 'log' | 'time' | 'categorical';\nexport type ScaleRange = [number, number];\n\nexport interface InternalChartSeries<T> {\n index: number;\n color: string;\n series: MixedLineBarChartProps.ChartSeries<T>;\n}\n\nexport interface MixedLineBarChartProps<T extends ChartDataTypes>\n extends CartesianChartProps<T, MixedLineBarChartProps.ChartSeries<T>> {\n /**\n * Array that represents the source of data for the displayed chart.\n * Each element can represent a line series, bar series, or a threshold, and can have the following properties:\n *\n * * `title` (string): A human-readable title for this series\n * * `type` (string): Series type (`\"line\"`, `\"bar\"`, or `\"threshold\"`)\n * * `data` (Array): An array of data points, represented as objects with `x` and `y` properties\n * * `color` (string): (Optional) A color hex value for this series. When assigned, it takes priority over the automatically assigned color\n * * `valueFormatter` (Function): (Optional) A function that formats data values before rendering in the UI, For example, in the details popover.\n */\n series: ReadonlyArray<MixedLineBarChartProps.ChartSeries<T>>;\n\n /**\n * When set to `true`, bars in the same data point are stacked instead of grouped next to each other.\n */\n stackedBars?: boolean;\n\n /**\n * When set to `true`, the x and y axes are flipped, which causes any bars to be rendered horizontally instead of vertically.\n * This can only be used when the chart consists exclusively of bar series.\n */\n horizontalBars?: boolean;\n\n /**\n * When set to `true`, adds a visual emphasis on the zero baseline axis.\n * See the usage guidelines for more details.\n */\n emphasizeBaselineAxis?: boolean;\n}\n\nexport namespace MixedLineBarChartProps {\n export interface Datum<T> {\n x: T;\n y: number;\n }\n\n interface IDataSeries<T> {\n type: 'line' | 'bar' | 'threshold';\n title: string;\n color?: string;\n\n // This makes sure that the element type of the array is reduced to just one type,\n // even if `T` is a union type, e.g. `number | string`.\n data: T extends unknown ? ReadonlyArray<Datum<T>> : ReadonlyArray<Datum<T>>;\n valueFormatter?: T extends unknown\n ? CartesianChartProps.ValueFormatter<number, T>\n : CartesianChartProps.ValueFormatter<number, T>;\n }\n\n export interface BarDataSeries<T> extends IDataSeries<T> {\n type: 'bar';\n }\n\n export interface LineDataSeries<T> extends IDataSeries<T> {\n type: 'line';\n }\n\n export interface ThresholdSeries<T = any> extends Omit<IDataSeries<never>, 'data' | 'valueFormatter'> {\n type: 'threshold';\n y?: number;\n x?: T;\n valueFormatter?: CartesianChartProps.TickFormatter<number>;\n }\n\n export interface YThresholdSeries extends Omit<ThresholdSeries<never>, 'x'> {\n type: 'threshold';\n y: number;\n valueFormatter?: CartesianChartProps.TickFormatter<number>;\n }\n\n export interface XThresholdSeries<T> extends Omit<ThresholdSeries<T>, 'y' | 'valueFormatter'> {\n type: 'threshold';\n x: T;\n }\n\n export type DataSeries<T> = LineDataSeries<T> | BarDataSeries<T>;\n\n export type ChartSeries<T> = DataSeries<T> | ThresholdSeries<T>;\n\n export type FilterChangeDetail<T> = CartesianChartProps.FilterChangeDetail<ChartSeries<T>>;\n\n export type HighlightChangeDetail<T> = CartesianChartProps.HighlightChangeDetail<ChartSeries<T>>;\n\n export type TickFormatter<T> = CartesianChartProps.TickFormatter<T>;\n\n export type ValueFormatter<YType, XType = null> = CartesianChartProps.ValueFormatter<YType, XType>;\n\n export type I18nStrings<T> = CartesianChartProps.I18nStrings<T>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/internal.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAMtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAMlF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,aAAK,8BAA8B,CAAC,CAAC,SAAS,cAAc,IAAI,YAAY,CAC1E,sBAAsB,CAAC,CAAC,CAAC,EACvB,QAAQ,GACR,QAAQ,GACR,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,gBAAgB,GAChB,YAAY,GACZ,mBAAmB,GACnB,uBAAuB,CAC1B,GACC,0BAA0B,CAAC;AAE7B,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,EAClF,MAAM,EACN,UAAU,EACV,UAAU,EACV,OAAO,EACP,OAAO,EACP,iBAAiB,EAAE,2BAA2B,EAC9C,aAAa,EAAE,uBAAuB,EACtC,MAAM,EAAE,cAAc,EACtB,cAAc,EACd,iBAAiB,EAAE,2BAA2B,EAC9C,WAAW,EACX,SAAS,EACT,cAAc,EACd,eAAe,EACf,MAAM,EACN,MAAM,EACN,WAAW,EACX,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,EACL,OAAO,EACP,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,EACf,iBAAwB,EACxB,GAAG,KAAK,EACT,EAAE,8BAA8B,CAAC,CAAC,CAAC,eA4MnC"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/internal.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAMtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAMlF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,aAAK,8BAA8B,CAAC,CAAC,SAAS,cAAc,IAAI,YAAY,CAC1E,sBAAsB,CAAC,CAAC,CAAC,EACvB,QAAQ,GACR,QAAQ,GACR,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,gBAAgB,GAChB,YAAY,GACZ,mBAAmB,GACnB,uBAAuB,CAC1B,GACC,0BAA0B,CAAC;AAE7B,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,EAClF,MAAM,EACN,UAAU,EACV,UAAU,EACV,OAAO,EACP,OAAO,EACP,iBAAiB,EAAE,2BAA2B,EAC9C,aAAa,EAAE,uBAAuB,EACtC,MAAM,EAAE,cAAc,EACtB,cAAc,EACd,iBAAiB,EAAE,2BAA2B,EAC9C,WAAW,EACX,SAAS,EACT,cAAc,EACd,eAAe,EACf,MAAM,EACN,MAAM,EACN,WAAW,EACX,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,EACL,OAAO,EACP,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,EACf,iBAAwB,EACxB,GAAG,KAAK,EACT,EAAE,8BAA8B,CAAC,CAAC,CAAC,eAmNnC"}
@@ -19,6 +19,7 @@ import { isDevelopment } from '../internal/is-development';
19
19
  import createCategoryColorScale from '../internal/utils/create-category-color-scale';
20
20
  import { useMergeRefs } from '../internal/hooks/use-merge-refs';
21
21
  import { nodeContains } from '../internal/utils/dom';
22
+ import { isXThreshold, isYThreshold } from './utils';
22
23
  export default function InternalMixedLineBarChart(_a) {
23
24
  var _b;
24
25
  var height = _a.height, xScaleType = _a.xScaleType, yScaleType = _a.yScaleType, xDomain = _a.xDomain, yDomain = _a.yDomain, controlledHighlightedSeries = _a.highlightedSeries, controlledVisibleSeries = _a.visibleSeries, externalSeries = _a.series, onFilterChange = _a.onFilterChange, controlledOnHighlightChange = _a.onHighlightChange, i18nStrings = _a.i18nStrings, ariaLabel = _a.ariaLabel, ariaLabelledby = _a.ariaLabelledby, ariaDescription = _a.ariaDescription, xTitle = _a.xTitle, yTitle = _a.yTitle, stackedBars = _a.stackedBars, horizontalBars = _a.horizontalBars, hideFilter = _a.hideFilter, additionalFilters = _a.additionalFilters, hideLegend = _a.hideLegend, legendTitle = _a.legendTitle, statusType = _a.statusType, detailPopoverSize = _a.detailPopoverSize, emphasizeBaselineAxis = _a.emphasizeBaselineAxis, empty = _a.empty, noMatch = _a.noMatch, errorText = _a.errorText, loadingText = _a.loadingText, recoveryText = _a.recoveryText, onRecoveryClick = _a.onRecoveryClick, _c = _a.__internalRootRef, __internalRootRef = _c === void 0 ? null : _c, props = __rest(_a, ["height", "xScaleType", "yScaleType", "xDomain", "yDomain", "highlightedSeries", "visibleSeries", "series", "onFilterChange", "onHighlightChange", "i18nStrings", "ariaLabel", "ariaLabelledby", "ariaDescription", "xTitle", "yTitle", "stackedBars", "horizontalBars", "hideFilter", "additionalFilters", "hideLegend", "legendTitle", "statusType", "detailPopoverSize", "emphasizeBaselineAxis", "empty", "noMatch", "errorText", "loadingText", "recoveryText", "onRecoveryClick", "__internalRootRef"]);
@@ -33,14 +34,21 @@ export default function InternalMixedLineBarChart(_a) {
33
34
  if (horizontalBars && gotLineSeries) {
34
35
  warnOnce('MixedLineBarChart', "Property horizontalBars can only be used with charts that contain only bar or threshold series.");
35
36
  }
37
+ for (var _i = 0, externalSeries_1 = externalSeries; _i < externalSeries_1.length; _i++) {
38
+ var s = externalSeries_1[_i];
39
+ if (s.type === 'threshold' && s.x !== undefined && s.y !== undefined) {
40
+ warnOnce('MixedLineBarChart', "Series of type \"threshold\" must contain either x or y property.");
41
+ }
42
+ if (s.type === 'threshold' && s.x === undefined && s.y === undefined) {
43
+ warnOnce('MixedLineBarChart', "Series of type \"threshold\" must contain either x or y property.");
44
+ }
45
+ }
36
46
  }, [xScaleType, horizontalBars, externalSeries]);
37
47
  var series = useMemo(function () {
38
- var colors = createCategoryColorScale(externalSeries, function (it) { return it.type === 'threshold'; }, function (it) { return it.color || null; });
39
- return externalSeries.map(function (s, i) { return ({
40
- index: i,
41
- color: colors[i],
42
- series: s
43
- }); });
48
+ // Generate series colors if not explicitly provided.
49
+ // The thresholds use a dedicated colour scale.
50
+ var colors = createCategoryColorScale(externalSeries, function (it) { return isYThreshold(it) || isXThreshold(it); }, function (it) { return it.color || null; });
51
+ return externalSeries.map(function (s, i) { return ({ index: i, color: colors[i], series: s }); });
44
52
  }, [externalSeries]);
45
53
  var _d = useState(null), highlightedPoint = _d[0], setHighlightedPoint = _d[1];
46
54
  var _e = useState(null), highlightedGroupIndex = _e[0], setHighlightedGroupIndex = _e[1];
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,oBAAoB,EAAE,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C,OAAO,oBAAoB,MAAM,iBAAiB,CAAC;AACnD,OAAO,mBAAmB,MAAM,gBAAgB,CAAC;AACjD,OAAO,cAAc,MAAM,mBAAm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EAAE,OAAO,EAChB,cAAc,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,EAC3C,cAAc,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,EAC3C,qBAAqB,EAAE,qBAAqB,EAC5C,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,aAAa,EAC5B,iBAAiB,EAAE,iBAAiB,EACpC,iBAAiB,EAAE,iBAAiB,EACpC,gBAAgB,EAAE,gBAAgB,EAClC,mBAAmB,EAAE,mBAAmB,EACxC,qBAAqB,EAAE,qBAAqB,EAC5C,wBAAwB,EAAE,wBAAwB,EAClD,YAAY,EAAE,YAAY,EAC1B,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,YAAY,GAC9B,CACH,CACG;QAEL,UAAU,IAAI,CACb,oBAAC,WAAW,IAAC,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE;YAC/B,oBAAC,mBAAmB,IAClB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,qBAAqB,IAAI,EAAE,EAC1C,iBAAiB,EAAE,YAAY,EAC/B,iBAAiB,EAAE,iBAAiB,EACpC,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,EACvC,gBAAgB,EAAE,YAAY,GAC9B,CACU,CACf,CACG,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useMemo, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { getBaseProps } from '../internal/base-component';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport InternalBox from '../box/internal';\nimport ChartStatusContainer, { getChartStatus } from '../internal/components/chart-status-container';\nimport { useControllable } from '../internal/hooks/use-controllable';\nimport { usePrevious } from '../internal/hooks/use-previous';\nimport { warnOnce } from '../internal/logging';\n\nimport { ChartDataTypes, MixedLineBarChartProps } from './interfaces';\nimport InternalChartFilters from './chart-filters';\nimport InternalChartLegend from './chart-legend';\nimport ChartContainer from './chart-container';\nimport cartesianStyles from '../internal/components/cartesian-chart/styles.css.js';\nimport styles from './styles.css.js';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { isDevelopment } from '../internal/is-development';\nimport createCategoryColorScale from '../internal/utils/create-category-color-scale';\nimport { ScaledPoint } from './make-scaled-series';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { nodeContains } from '../internal/utils/dom';\nimport { SomeRequired } from '../internal/types';\n\ntype InternalMixedLineBarChartProps<T extends ChartDataTypes> = SomeRequired<\n MixedLineBarChartProps<T>,\n | 'series'\n | 'height'\n | 'xScaleType'\n | 'yScaleType'\n | 'stackedBars'\n | 'horizontalBars'\n | 'statusType'\n | 'detailPopoverSize'\n | 'emphasizeBaselineAxis'\n> &\n InternalBaseComponentProps;\n\nexport default function InternalMixedLineBarChart<T extends number | string | Date>({\n height,\n xScaleType,\n yScaleType,\n xDomain,\n yDomain,\n highlightedSeries: controlledHighlightedSeries,\n visibleSeries: controlledVisibleSeries,\n series: externalSeries,\n onFilterChange,\n onHighlightChange: controlledOnHighlightChange,\n i18nStrings,\n ariaLabel,\n ariaLabelledby,\n ariaDescription,\n xTitle,\n yTitle,\n stackedBars,\n horizontalBars,\n hideFilter,\n additionalFilters,\n hideLegend,\n legendTitle,\n statusType,\n detailPopoverSize,\n emphasizeBaselineAxis,\n empty,\n noMatch,\n errorText,\n loadingText,\n recoveryText,\n onRecoveryClick,\n __internalRootRef = null,\n ...props\n}: InternalMixedLineBarChartProps<T>) {\n const baseProps = getBaseProps(props);\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const gotBarSeries = externalSeries.some(s => s.type === 'bar');\n const gotLineSeries = externalSeries.some(s => s.type === 'line');\n\n if (xScaleType !== 'categorical' && gotBarSeries) {\n warnOnce(\n 'MixedLineBarChart',\n `Bar series cannot be used with a ${xScaleType} scale. Use a categorical x axis instead.`\n );\n }\n\n if (horizontalBars && gotLineSeries) {\n warnOnce(\n 'MixedLineBarChart',\n `Property horizontalBars can only be used with charts that contain only bar or threshold series.`\n );\n }\n }, [xScaleType, horizontalBars, externalSeries]);\n\n const series = useMemo(() => {\n const colors = createCategoryColorScale(\n externalSeries,\n it => it.type === 'threshold',\n it => it.color || null\n );\n\n return externalSeries.map((s, i) => ({\n index: i,\n color: colors[i],\n series: s,\n }));\n }, [externalSeries]);\n\n const [highlightedPoint, setHighlightedPoint] = useState<ScaledPoint<T> | null>(null);\n const [highlightedGroupIndex, setHighlightedGroupIndex] = useState<number | null>(null);\n const [highlightedSeries = null, setHighlightedSeries] = useControllable(\n controlledHighlightedSeries,\n controlledOnHighlightChange,\n null,\n {\n componentName: 'MixedLineBarChart',\n controlledProp: 'highlightedSeries',\n changeHandler: 'onHighlightChange',\n }\n );\n const [legendSeries, setLegendSeries] = useState<MixedLineBarChartProps.ChartSeries<T> | null>(highlightedSeries);\n useEffect(() => {\n setLegendSeries(controlledHighlightedSeries || null);\n }, [controlledHighlightedSeries]);\n\n const [externalVisibleSeries, setExternalVisibleSeries] = useControllable(\n controlledVisibleSeries,\n onFilterChange,\n externalSeries,\n {\n componentName: 'MixedLineBarChart',\n controlledProp: 'visibleSeries',\n changeHandler: 'onFilterChange',\n }\n );\n\n if (isDevelopment) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const previousSeries = usePrevious(externalSeries);\n\n const hasPrevious = !!(previousSeries && previousSeries.length);\n const hasCurrent = !!externalSeries.length;\n\n if (hasPrevious && hasCurrent && externalSeries !== previousSeries && !controlledVisibleSeries && !hideFilter) {\n warnOnce(\n 'MixedLineBarChart',\n 'The `series` value passed into the component changed. ' +\n 'This may cause problems with filtering - we recommend that you make the `series` value constant, ' +\n 'or provide a `visibleSeries` value that derives from the current `series` value.'\n );\n }\n }\n\n const visibleSeries = useMemo(\n () => series.filter(s => externalVisibleSeries?.indexOf(s.series) !== -1),\n [series, externalVisibleSeries]\n );\n\n const filterChange = (selectedSeries: ReadonlyArray<MixedLineBarChartProps.ChartSeries<T>>) => {\n setExternalVisibleSeries(selectedSeries);\n fireNonCancelableEvent(onFilterChange, {\n visibleSeries: selectedSeries,\n });\n };\n\n const onHighlightChange = (series: MixedLineBarChartProps.ChartSeries<T> | null) => {\n setHighlightedSeries(series);\n fireNonCancelableEvent(controlledOnHighlightChange, {\n highlightedSeries: series,\n });\n setLegendSeries(series);\n };\n\n const onBlur = (event: React.FocusEvent) => {\n if (event.relatedTarget && !nodeContains(containerRef.current, event.relatedTarget)) {\n highlightedSeries && onHighlightChange(highlightedSeries);\n setHighlightedPoint(null);\n setHighlightedGroupIndex(null);\n setLegendSeries(null);\n }\n };\n\n const { isEmpty, isNoMatch, showChart } = getChartStatus({\n externalData: externalSeries,\n visibleData: visibleSeries || [],\n statusType,\n });\n const showFilters = statusType === 'finished' && (!isEmpty || isNoMatch);\n const showLegend = !hideLegend && !isEmpty && statusType === 'finished';\n const reserveLegendSpace = !showChart && !hideLegend;\n const reserveFilterSpace = !showChart && !isNoMatch && (!hideFilter || additionalFilters);\n const mergedRef = useMergeRefs(containerRef, __internalRootRef);\n\n return (\n <div {...baseProps} className={clsx(baseProps.className, styles.root)} ref={mergedRef} onBlur={onBlur}>\n {showFilters && (\n <InternalBox className={cartesianStyles['filter-container']} margin={{ bottom: 'l' }}>\n <InternalChartFilters\n series={series}\n visibleSeries={externalVisibleSeries || []}\n onChange={filterChange}\n i18nStrings={i18nStrings}\n hideFilter={hideFilter}\n additionalFilters={additionalFilters}\n />\n </InternalBox>\n )}\n\n <div\n className={clsx(styles.content, {\n [styles['content--reserve-filter']]: reserveFilterSpace,\n [styles['content--reserve-legend']]: reserveLegendSpace,\n })}\n style={{ minHeight: height }}\n >\n <ChartStatusContainer\n isEmpty={isEmpty}\n isNoMatch={isNoMatch}\n showChart={showChart}\n statusType={statusType}\n empty={empty}\n noMatch={noMatch}\n loadingText={loadingText}\n errorText={errorText}\n recoveryText={recoveryText}\n onRecoveryClick={onRecoveryClick}\n />\n {showChart && (\n <ChartContainer\n height={height}\n xScaleType={xScaleType}\n yScaleType={yScaleType}\n xDomain={xDomain}\n yDomain={yDomain}\n xTickFormatter={i18nStrings?.xTickFormatter}\n yTickFormatter={i18nStrings?.yTickFormatter}\n emphasizeBaselineAxis={emphasizeBaselineAxis}\n stackedBars={stackedBars}\n horizontalBars={horizontalBars}\n series={series}\n visibleSeries={visibleSeries}\n highlightedSeries={highlightedSeries}\n onHighlightChange={onHighlightChange}\n highlightedPoint={highlightedPoint}\n setHighlightedPoint={setHighlightedPoint}\n highlightedGroupIndex={highlightedGroupIndex}\n setHighlightedGroupIndex={setHighlightedGroupIndex}\n legendSeries={legendSeries}\n detailPopoverSize={detailPopoverSize}\n xTitle={xTitle}\n yTitle={yTitle}\n ariaLabel={ariaLabel}\n ariaLabelledby={ariaLabelledby}\n ariaDescription={ariaDescription}\n i18nStrings={i18nStrings}\n plotContainerRef={containerRef}\n />\n )}\n </div>\n\n {showLegend && (\n <InternalBox margin={{ top: 'm' }}>\n <InternalChartLegend\n series={series}\n visibleSeries={externalVisibleSeries || []}\n highlightedSeries={legendSeries}\n onHighlightChange={onHighlightChange}\n legendTitle={legendTitle}\n ariaLabel={i18nStrings?.legendAriaLabel}\n plotContainerRef={containerRef}\n />\n </InternalBox>\n )}\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,MA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AAW,uBAAX,WAAW,CAAE,cAAc,EAC3C,qBAAqB,EAAE,qBAAqB,EAC5C,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,aAAa,EAC5B,iBAAiB,EAAE,iBAAiB,EACpC,iBAAiB,EAAE,iBAAiB,EACpC,gBAAgB,EAAE,gBAAgB,EAClC,mBAAmB,EAAE,mBAAmB,EACxC,qBAAqB,EAAE,qBAAqB,EAC5C,wBAAwB,EAAE,wBAAwB,EAClD,YAAY,EAAE,YAAY,EAC1B,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,YAAY,GAC9B,CACH,CACG;QAEL,UAAU,IAAI,CACb,oBAAC,WAAW,IAAC,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE;YAC/B,oBAAC,mBAAmB,IAClB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,qBAAqB,IAAI,EAAE,EAC1C,iBAAiB,EAAE,YAAY,EAC/B,iBAAiB,EAAE,iBAAiB,EACpC,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,EACvC,gBAAgB,EAAE,YAAY,GAC9B,CACU,CACf,CACG,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useMemo, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { getBaseProps } from '../internal/base-component';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport InternalBox from '../box/internal';\nimport ChartStatusContainer, { getChartStatus } from '../internal/components/chart-status-container';\nimport { useControllable } from '../internal/hooks/use-controllable';\nimport { usePrevious } from '../internal/hooks/use-previous';\nimport { warnOnce } from '../internal/logging';\n\nimport { ChartDataTypes, MixedLineBarChartProps } from './interfaces';\nimport InternalChartFilters from './chart-filters';\nimport InternalChartLegend from './chart-legend';\nimport ChartContainer from './chart-container';\nimport cartesianStyles from '../internal/components/cartesian-chart/styles.css.js';\nimport styles from './styles.css.js';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { isDevelopment } from '../internal/is-development';\nimport createCategoryColorScale from '../internal/utils/create-category-color-scale';\nimport { ScaledPoint } from './make-scaled-series';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { nodeContains } from '../internal/utils/dom';\nimport { SomeRequired } from '../internal/types';\nimport { isXThreshold, isYThreshold } from './utils';\n\ntype InternalMixedLineBarChartProps<T extends ChartDataTypes> = SomeRequired<\n MixedLineBarChartProps<T>,\n | 'series'\n | 'height'\n | 'xScaleType'\n | 'yScaleType'\n | 'stackedBars'\n | 'horizontalBars'\n | 'statusType'\n | 'detailPopoverSize'\n | 'emphasizeBaselineAxis'\n> &\n InternalBaseComponentProps;\n\nexport default function InternalMixedLineBarChart<T extends number | string | Date>({\n height,\n xScaleType,\n yScaleType,\n xDomain,\n yDomain,\n highlightedSeries: controlledHighlightedSeries,\n visibleSeries: controlledVisibleSeries,\n series: externalSeries,\n onFilterChange,\n onHighlightChange: controlledOnHighlightChange,\n i18nStrings,\n ariaLabel,\n ariaLabelledby,\n ariaDescription,\n xTitle,\n yTitle,\n stackedBars,\n horizontalBars,\n hideFilter,\n additionalFilters,\n hideLegend,\n legendTitle,\n statusType,\n detailPopoverSize,\n emphasizeBaselineAxis,\n empty,\n noMatch,\n errorText,\n loadingText,\n recoveryText,\n onRecoveryClick,\n __internalRootRef = null,\n ...props\n}: InternalMixedLineBarChartProps<T>) {\n const baseProps = getBaseProps(props);\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const gotBarSeries = externalSeries.some(s => s.type === 'bar');\n const gotLineSeries = externalSeries.some(s => s.type === 'line');\n\n if (xScaleType !== 'categorical' && gotBarSeries) {\n warnOnce(\n 'MixedLineBarChart',\n `Bar series cannot be used with a ${xScaleType} scale. Use a categorical x axis instead.`\n );\n }\n\n if (horizontalBars && gotLineSeries) {\n warnOnce(\n 'MixedLineBarChart',\n `Property horizontalBars can only be used with charts that contain only bar or threshold series.`\n );\n }\n\n for (const s of externalSeries) {\n if (s.type === 'threshold' && s.x !== undefined && s.y !== undefined) {\n warnOnce('MixedLineBarChart', `Series of type \"threshold\" must contain either x or y property.`);\n }\n if (s.type === 'threshold' && s.x === undefined && s.y === undefined) {\n warnOnce('MixedLineBarChart', `Series of type \"threshold\" must contain either x or y property.`);\n }\n }\n }, [xScaleType, horizontalBars, externalSeries]);\n\n const series = useMemo(() => {\n // Generate series colors if not explicitly provided.\n // The thresholds use a dedicated colour scale.\n const colors = createCategoryColorScale(\n externalSeries,\n it => isYThreshold(it) || isXThreshold(it),\n it => it.color || null\n );\n\n return externalSeries.map((s, i) => ({ index: i, color: colors[i], series: s }));\n }, [externalSeries]);\n\n const [highlightedPoint, setHighlightedPoint] = useState<ScaledPoint<T> | null>(null);\n const [highlightedGroupIndex, setHighlightedGroupIndex] = useState<number | null>(null);\n const [highlightedSeries = null, setHighlightedSeries] = useControllable(\n controlledHighlightedSeries,\n controlledOnHighlightChange,\n null,\n {\n componentName: 'MixedLineBarChart',\n controlledProp: 'highlightedSeries',\n changeHandler: 'onHighlightChange',\n }\n );\n const [legendSeries, setLegendSeries] = useState<MixedLineBarChartProps.ChartSeries<T> | null>(highlightedSeries);\n useEffect(() => {\n setLegendSeries(controlledHighlightedSeries || null);\n }, [controlledHighlightedSeries]);\n\n const [externalVisibleSeries, setExternalVisibleSeries] = useControllable(\n controlledVisibleSeries,\n onFilterChange,\n externalSeries,\n {\n componentName: 'MixedLineBarChart',\n controlledProp: 'visibleSeries',\n changeHandler: 'onFilterChange',\n }\n );\n\n if (isDevelopment) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const previousSeries = usePrevious(externalSeries);\n\n const hasPrevious = !!(previousSeries && previousSeries.length);\n const hasCurrent = !!externalSeries.length;\n\n if (hasPrevious && hasCurrent && externalSeries !== previousSeries && !controlledVisibleSeries && !hideFilter) {\n warnOnce(\n 'MixedLineBarChart',\n 'The `series` value passed into the component changed. ' +\n 'This may cause problems with filtering - we recommend that you make the `series` value constant, ' +\n 'or provide a `visibleSeries` value that derives from the current `series` value.'\n );\n }\n }\n\n const visibleSeries = useMemo(\n () => series.filter(s => externalVisibleSeries?.indexOf(s.series) !== -1),\n [series, externalVisibleSeries]\n );\n\n const filterChange = (selectedSeries: ReadonlyArray<MixedLineBarChartProps.ChartSeries<T>>) => {\n setExternalVisibleSeries(selectedSeries);\n fireNonCancelableEvent(onFilterChange, {\n visibleSeries: selectedSeries,\n });\n };\n\n const onHighlightChange = (series: MixedLineBarChartProps.ChartSeries<T> | null) => {\n setHighlightedSeries(series);\n fireNonCancelableEvent(controlledOnHighlightChange, {\n highlightedSeries: series,\n });\n setLegendSeries(series);\n };\n\n const onBlur = (event: React.FocusEvent) => {\n if (event.relatedTarget && !nodeContains(containerRef.current, event.relatedTarget)) {\n highlightedSeries && onHighlightChange(highlightedSeries);\n setHighlightedPoint(null);\n setHighlightedGroupIndex(null);\n setLegendSeries(null);\n }\n };\n\n const { isEmpty, isNoMatch, showChart } = getChartStatus({\n externalData: externalSeries,\n visibleData: visibleSeries || [],\n statusType,\n });\n const showFilters = statusType === 'finished' && (!isEmpty || isNoMatch);\n const showLegend = !hideLegend && !isEmpty && statusType === 'finished';\n const reserveLegendSpace = !showChart && !hideLegend;\n const reserveFilterSpace = !showChart && !isNoMatch && (!hideFilter || additionalFilters);\n const mergedRef = useMergeRefs(containerRef, __internalRootRef);\n\n return (\n <div {...baseProps} className={clsx(baseProps.className, styles.root)} ref={mergedRef} onBlur={onBlur}>\n {showFilters && (\n <InternalBox className={cartesianStyles['filter-container']} margin={{ bottom: 'l' }}>\n <InternalChartFilters\n series={series}\n visibleSeries={externalVisibleSeries || []}\n onChange={filterChange}\n i18nStrings={i18nStrings}\n hideFilter={hideFilter}\n additionalFilters={additionalFilters}\n />\n </InternalBox>\n )}\n\n <div\n className={clsx(styles.content, {\n [styles['content--reserve-filter']]: reserveFilterSpace,\n [styles['content--reserve-legend']]: reserveLegendSpace,\n })}\n style={{ minHeight: height }}\n >\n <ChartStatusContainer\n isEmpty={isEmpty}\n isNoMatch={isNoMatch}\n showChart={showChart}\n statusType={statusType}\n empty={empty}\n noMatch={noMatch}\n loadingText={loadingText}\n errorText={errorText}\n recoveryText={recoveryText}\n onRecoveryClick={onRecoveryClick}\n />\n {showChart && (\n <ChartContainer\n height={height}\n xScaleType={xScaleType}\n yScaleType={yScaleType}\n xDomain={xDomain}\n yDomain={yDomain}\n xTickFormatter={i18nStrings?.xTickFormatter}\n yTickFormatter={i18nStrings?.yTickFormatter}\n emphasizeBaselineAxis={emphasizeBaselineAxis}\n stackedBars={stackedBars}\n horizontalBars={horizontalBars}\n series={series}\n visibleSeries={visibleSeries}\n highlightedSeries={highlightedSeries}\n onHighlightChange={onHighlightChange}\n highlightedPoint={highlightedPoint}\n setHighlightedPoint={setHighlightedPoint}\n highlightedGroupIndex={highlightedGroupIndex}\n setHighlightedGroupIndex={setHighlightedGroupIndex}\n legendSeries={legendSeries}\n detailPopoverSize={detailPopoverSize}\n xTitle={xTitle}\n yTitle={yTitle}\n ariaLabel={ariaLabel}\n ariaLabelledby={ariaLabelledby}\n ariaDescription={ariaDescription}\n i18nStrings={i18nStrings}\n plotContainerRef={containerRef}\n />\n )}\n </div>\n\n {showLegend && (\n <InternalBox margin={{ top: 'm' }}>\n <InternalChartLegend\n series={series}\n visibleSeries={externalVisibleSeries || []}\n highlightedSeries={legendSeries}\n onHighlightChange={onHighlightChange}\n legendTitle={legendTitle}\n ariaLabel={i18nStrings?.legendAriaLabel}\n plotContainerRef={containerRef}\n />\n </InternalBox>\n )}\n </div>\n );\n}\n"]}
@@ -2,11 +2,11 @@ import { ChartScale, NumericChartScale } from '../internal/components/cartesian-
2
2
  import { MixedLineBarChartProps } from './interfaces';
3
3
  export interface LineSeriesProps<T> {
4
4
  axis: 'x' | 'y';
5
- series: MixedLineBarChartProps.LineDataSeries<T> | MixedLineBarChartProps.ThresholdSeries;
5
+ series: MixedLineBarChartProps.LineDataSeries<T> | MixedLineBarChartProps.ThresholdSeries<T>;
6
6
  color: string;
7
7
  chartAreaClipPath: string;
8
8
  xScale: ChartScale;
9
9
  yScale: NumericChartScale;
10
10
  }
11
- export default function LineSeries<T>({ axis, series, color, xScale, yScale, chartAreaClipPath }: LineSeriesProps<T>): JSX.Element;
11
+ export default function LineSeries<T>({ axis, series, color, xScale, yScale, chartAreaClipPath }: LineSeriesProps<T>): JSX.Element | null;
12
12
  //# sourceMappingURL=line-series.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-series.d.ts","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/line-series.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAC9F,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,IAAI,EAAE,GAAG,GAAG,GAAG,CAAC;IAChB,MAAM,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,sBAAsB,CAAC,eAAe,CAAC;IAE1F,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAE1B,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAED,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAAE,eAAe,CAAC,CAAC,CAAC,eAoCnH"}
1
+ {"version":3,"file":"line-series.d.ts","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/line-series.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAC9F,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGtD,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,IAAI,EAAE,GAAG,GAAG,GAAG,CAAC;IAChB,MAAM,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,sBAAsB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAE7F,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAE1B,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAED,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAAE,eAAe,CAAC,CAAC,CAAC,sBA8CnH"}
@@ -3,14 +3,12 @@ import { __assign } from "tslib";
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import React from 'react';
5
5
  import { line } from 'd3-shape';
6
+ import { isXThreshold, isYThreshold } from './utils';
6
7
  export default function LineSeries(_a) {
8
+ var _b;
7
9
  var axis = _a.axis, series = _a.series, color = _a.color, xScale = _a.xScale, yScale = _a.yScale, chartAreaClipPath = _a.chartAreaClipPath;
8
- var commonProps = {
9
- 'aria-hidden': true,
10
- stroke: color,
11
- clipPath: "url(#".concat(chartAreaClipPath, ")")
12
- };
13
- // Ignore axis for line series as we only support horizontally-oriented lines.
10
+ var commonProps = { 'aria-hidden': true, stroke: color, clipPath: "url(#".concat(chartAreaClipPath, ")") };
11
+ // Render data path. The chart orientation is ignored as only horizontally-oriented lines are supported.
14
12
  if (series.type === 'line') {
15
13
  var lineGenerator = line()
16
14
  .x(function (d) {
@@ -29,11 +27,25 @@ export default function LineSeries(_a) {
29
27
  });
30
28
  return (React.createElement("path", __assign({}, commonProps, { d: lineGenerator(visibleData) || '' })));
31
29
  }
32
- else {
33
- var range = xScale.d3Scale.range();
30
+ // Render a horizontal line (vertical if chart orientation is inverted).
31
+ else if (isYThreshold(series)) {
32
+ var _c = xScale.d3Scale.range(), x1 = _c[0], x2 = _c[1];
34
33
  var y = yScale.d3Scale(series.y);
35
- var coordinates = axis === 'x' ? { x1: range[0], x2: range[1], y1: y, y2: y } : { x1: y, x2: y, y1: range[0], y2: range[1] };
34
+ var coordinates = axis === 'x' ? { x1: x1, x2: x2, y1: y, y2: y } : { x1: y, x2: y, y1: x1, y2: x2 };
35
+ return React.createElement("line", __assign({}, commonProps, coordinates));
36
+ }
37
+ // Render a vertical line (horizontal if chart orientation is inverted).
38
+ // The offset is necessary for categorical scale to render the line in the middle of the category bar.
39
+ else if (isXThreshold(series)) {
40
+ var _d = yScale.d3Scale.range(), y1 = _d[0], y2 = _d[1];
41
+ var xOffset = xScale.isCategorical() ? Math.max(0, xScale.d3Scale.bandwidth() - 1) / 2 : 0;
42
+ var x = ((_b = xScale.d3Scale(series.x)) !== null && _b !== void 0 ? _b : NaN) + xOffset;
43
+ var coordinates = axis === 'x' ? { x1: x, x2: x, y1: y1, y2: y2 } : { x1: y1, x2: y2, y1: x, y2: x };
36
44
  return React.createElement("line", __assign({}, commonProps, coordinates));
37
45
  }
46
+ // Bar series are handled separately.
47
+ else {
48
+ return null;
49
+ }
38
50
  }
39
51
  //# sourceMappingURL=line-series.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-series.js","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/line-series.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAgBhC,MAAM,CAAC,OAAO,UA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AE,CAAC;QACrC,IAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACnC,IAAM,WAAW,GACf,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7G,OAAO,yCAAU,WAAW,EAAM,WAAW,EAAI,CAAC;KACnD;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\n\nimport { line } from 'd3-shape';\n\nimport { ChartScale, NumericChartScale } from '../internal/components/cartesian-chart/scales';\nimport { MixedLineBarChartProps } from './interfaces';\n\nexport interface LineSeriesProps<T> {\n axis: 'x' | 'y';\n series: MixedLineBarChartProps.LineDataSeries<T> | MixedLineBarChartProps.ThresholdSeries;\n\n color: string;\n chartAreaClipPath: string;\n\n xScale: ChartScale;\n yScale: NumericChartScale;\n}\n\nexport default function LineSeries<T>({ axis, series, color, xScale, yScale, chartAreaClipPath }: LineSeriesProps<T>) {\n const commonProps = {\n 'aria-hidden': true,\n stroke: color,\n clipPath: `url(#${chartAreaClipPath})`,\n };\n\n // Ignore axis for line series as we only support horizontally-oriented lines.\n if (series.type === 'line') {\n const lineGenerator = line<MixedLineBarChartProps.Datum<T>>()\n .x((d: MixedLineBarChartProps.Datum<T>) => {\n let x = xScale.d3Scale(d.x as any) || 0;\n if (xScale.isCategorical()) {\n const offset = Math.max(0, xScale.d3Scale.bandwidth() - 1) / 2;\n x += offset;\n }\n return x;\n })\n .y((d: MixedLineBarChartProps.Datum<T>) => yScale.d3Scale(d.y) || 0);\n\n // Filter out any data that is not part of the xScale\n const visibleData = series.data.filter(({ x }) => xScale.d3Scale(x as any) !== undefined);\n\n return (\n <path\n {...commonProps}\n d={lineGenerator(visibleData as unknown as Array<MixedLineBarChartProps.Datum<T>>) || ''}\n />\n );\n } else {\n const range = xScale.d3Scale.range();\n const y = yScale.d3Scale(series.y);\n const coordinates =\n axis === 'x' ? { x1: range[0], x2: range[1], y1: y, y2: y } : { x1: y, x2: y, y1: range[0], y2: range[1] };\n return <line {...commonProps} {...coordinates} />;\n }\n}\n"]}
1
+ {"version":3,"file":"line-series.js","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/line-series.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAIhC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAarD,MAAM,CAAC,OAAO,UAAU,UAAU,CAAI,EAA8E;;QAA5E,IAAI,UAAA,EAAE,MAAM,YAAA,EAAE,KAAK,WAAA,EAAE,MAAM,YAAA,EAAE,MAAM,YAAA,EAAE,iBAAiB,uBAAA;IAC5F,IAAM,WAAW,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAQ,iBAAiB,MAAG,EAAE,CAAC;IAEnG,wGAAwG;IACxG,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,EAAE;QAC1B,IAAM,aAAa,GAAG,IAAI,EAAmC;aAC1D,CAAC,CAAC,UAAC,CAAkC;YACpC,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAQ,CAAC,IAAI,CAAC,CAAC;YACxC,IAAI,MAAM,CAAC,aAAa,EAAE,EAAE;gBAC1B,IAAM,MAAM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,CAAC,MAAM,CAAC,EAAE;QACvB,IAAA,KAAW,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAhC,EAAE,QAAA,EAAE,EAAE,QAA0B,CAAC;QACxC,IAAM,OAAO,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7F,IAAM,CAAC,GAAG,CAAC,MAAA,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAQ,CAAC,mCAAI,GAAG,CAAC,GAAG,OAAO,CAAC;QAC7D,IAAM,WAAW,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,IAAA,EAAE,EAAE,IAAA,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;QAC/F,OAAO,yCAAU,WAAW,EAAM,WAAW,EAAI,CAAC;KACnD;IACD,qCAAqC;SAChC;QACH,OAAO,IAAI,CAAC;KACb;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\n\nimport { line } from 'd3-shape';\n\nimport { ChartScale, NumericChartScale } from '../internal/components/cartesian-chart/scales';\nimport { MixedLineBarChartProps } from './interfaces';\nimport { isXThreshold, isYThreshold } from './utils';\n\nexport interface LineSeriesProps<T> {\n axis: 'x' | 'y';\n series: MixedLineBarChartProps.LineDataSeries<T> | MixedLineBarChartProps.ThresholdSeries<T>;\n\n color: string;\n chartAreaClipPath: string;\n\n xScale: ChartScale;\n yScale: NumericChartScale;\n}\n\nexport default function LineSeries<T>({ axis, series, color, xScale, yScale, chartAreaClipPath }: LineSeriesProps<T>) {\n const commonProps = { 'aria-hidden': true, stroke: color, clipPath: `url(#${chartAreaClipPath})` };\n\n // Render data path. The chart orientation is ignored as only horizontally-oriented lines are supported.\n if (series.type === 'line') {\n const lineGenerator = line<MixedLineBarChartProps.Datum<T>>()\n .x((d: MixedLineBarChartProps.Datum<T>) => {\n let x = xScale.d3Scale(d.x as any) || 0;\n if (xScale.isCategorical()) {\n const offset = Math.max(0, xScale.d3Scale.bandwidth() - 1) / 2;\n x += offset;\n }\n return x;\n })\n .y((d: MixedLineBarChartProps.Datum<T>) => yScale.d3Scale(d.y) || 0);\n\n // Filter out any data that is not part of the xScale\n const visibleData = series.data.filter(({ x }) => xScale.d3Scale(x as any) !== undefined);\n\n return (\n <path\n {...commonProps}\n d={lineGenerator(visibleData as unknown as Array<MixedLineBarChartProps.Datum<T>>) || ''}\n />\n );\n }\n // Render a horizontal line (vertical if chart orientation is inverted).\n else if (isYThreshold(series)) {\n const [x1, x2] = xScale.d3Scale.range();\n const y = yScale.d3Scale(series.y);\n const coordinates = axis === 'x' ? { x1, x2, y1: y, y2: y } : { x1: y, x2: y, y1: x1, y2: x2 };\n return <line {...commonProps} {...coordinates} />;\n }\n // Render a vertical line (horizontal if chart orientation is inverted).\n // The offset is necessary for categorical scale to render the line in the middle of the category bar.\n else if (isXThreshold(series)) {\n const [y1, y2] = yScale.d3Scale.range();\n const xOffset = xScale.isCategorical() ? Math.max(0, xScale.d3Scale.bandwidth() - 1) / 2 : 0;\n const x = (xScale.d3Scale(series.x as any) ?? NaN) + xOffset;\n const coordinates = axis === 'x' ? { x1: x, x2: x, y1, y2 } : { x1: y1, x2: y2, y1: x, y2: x };\n return <line {...commonProps} {...coordinates} />;\n }\n // Bar series are handled separately.\n else {\n return null;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"make-scaled-bar-groups.d.ts","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/make-scaled-bar-groups.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAA0B,MAAM,cAAc,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,MAAM,+CAA+C,CAAC;AAG3E,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,CAAC,EAAE,CAAC,CAAC;IACL,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE;QACR,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,CAAC,SAAS,cAAc,EAClE,MAAM,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,EAC7C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,GAAG,GAAG,GAAG,GACd,cAAc,CAAC,CAAC,CAAC,EAAE,CAmCrB"}
1
+ {"version":3,"file":"make-scaled-bar-groups.d.ts","sourceRoot":"","sources":["../../../src/mixed-line-bar-chart/make-scaled-bar-groups.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAA0B,MAAM,cAAc,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,MAAM,+CAA+C,CAAC;AAG3E,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,CAAC,EAAE,CAAC,CAAC;IACL,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE;QACR,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,CAAC,SAAS,cAAc,EAClE,MAAM,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,EAC7C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,GAAG,GAAG,GAAG,GACd,cAAc,CAAC,CAAC,CAAC,EAAE,CA0CrB"}
@@ -1,4 +1,4 @@
1
- import { matchesX } from './utils';
1
+ import { isDataSeries, isXThreshold, isYThreshold, matchesX } from './utils';
2
2
  /**
3
3
  * Creates a list of all bar (and mixed) groups in the series with their scaled positions.
4
4
  */
@@ -14,11 +14,18 @@ export default function makeScaledBarGroups(series, xScale, plotWidth, plotHeigh
14
14
  isValid: isValid,
15
15
  hasData: series.some(function (_a) {
16
16
  var series = _a.series;
17
- if (series.type === 'threshold') {
18
- // If there is a threshold series, every valid group will have a data point
17
+ // If there is a threshold series, every valid group will have a data point.
18
+ if (isYThreshold(series)) {
19
19
  return true;
20
20
  }
21
- return series.data.some(function (datum) { return matchesX(datum.x, x); });
21
+ // X-thresholds do not have associated value.
22
+ if (isXThreshold(series)) {
23
+ return false;
24
+ }
25
+ if (isDataSeries(series)) {
26
+ return series.data.some(function (datum) { return matchesX(datum.x, x); });
27
+ }
28
+ return false;
22
29
  }),
23
30
  position: axis === 'x'
24
31
  ? {