@lobehub/charts 5.5.1 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/AccuracyBarChart/index.js +3 -3
- package/es/AreaChart/index.js +3 -3
- package/es/BarChart/index.js +3 -3
- package/es/BarList/index.js +3 -3
- package/es/BenchmarkColumnChart/index.js +3 -3
- package/es/BenchmarkRankingChart/index.js +11 -4
- package/es/BenchmarkScatterChart/index.d.ts +145 -0
- package/es/BenchmarkScatterChart/index.js +857 -0
- package/es/BenchmarkScatterChart/index.mdx +61 -0
- package/es/BenchmarkScatterChart/styles.d.ts +25 -0
- package/es/BenchmarkScatterChart/styles.js +33 -0
- package/es/BenchmarkScatterChart/utils.d.ts +55 -0
- package/es/BenchmarkScatterChart/utils.js +353 -0
- package/es/ComposedChart/index.js +3 -3
- package/es/DataBars/CategoryBar.js +2 -1
- package/es/DataBars/DeltaBar.js +2 -1
- package/es/DataBars/MarkerBar.js +2 -1
- package/es/DataBars/ProgressBar.js +2 -1
- package/es/DonutChart/index.js +3 -3
- package/es/FunnelChart/index.js +3 -3
- package/es/Heatmaps/Calendar.js +1 -1
- package/es/Heatmaps/index.js +2 -1
- package/es/Legend/LegendItem.js +2 -2
- package/es/Legend/ScrollButton.js +1 -1
- package/es/LineChart/index.js +3 -3
- package/es/RadarChart/index.js +3 -3
- package/es/ScatterChart/ScatterChartTooltip.js +2 -2
- package/es/ScatterChart/ScatterChartTooltipRow.js +3 -3
- package/es/ScatterChart/index.js +3 -3
- package/es/SparkChart/SparkAreaChart.js +3 -3
- package/es/SparkChart/SparkBarChart.js +3 -3
- package/es/SparkChart/SparkLineChart.js +3 -3
- package/es/Tracker/TrackerBlock.js +2 -1
- package/es/Tracker/index.js +2 -1
- package/es/common/ChartTooltip/ChartTooltipRow.js +3 -3
- package/es/common/ChartTooltip/index.js +2 -2
- package/es/common/NoData.js +5 -22
- package/es/common/benchmark/index.d.ts +1 -1
- package/es/common/benchmark/types.d.ts +6 -1
- package/es/index.d.ts +2 -1
- package/es/index.js +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,857 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
var _excluded = ["data", "index", "valueKey", "providerKey", "iconKey", "colorKey", "errorKey", "renderIcon", "valueFormatter", "accuracyFormatter", "errorFormatter", "showError", "showErrorBars", "showAnimation", "onValueChange", "className", "style", "loading", "width", "height", "noDataText", "highlightColor", "frontierColor", "frontierWidth", "iconSize", "markerSize", "labelFontSize", "valueLabelFontSize", "metrics", "metric", "defaultMetric", "onMetricChange", "minX", "maxX", "minY", "maxY", "showDominatedArea", "showFrontier", "showGridLines", "showLabels", "showLegend", "showTooltip", "showValueLabel", "showXAxis", "showYAxis", "xAxisLabel", "xDirection", "xFormatter", "xKey", "xScale", "yAxisLabel"];
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
13
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
14
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
15
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
18
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
19
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
20
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
22
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
23
|
+
import { A } from '@lobehub/ui';
|
|
24
|
+
import { Segmented, Skeleton, Tooltip } from '@lobehub/ui/base-ui';
|
|
25
|
+
import { useSize } from 'ahooks';
|
|
26
|
+
import { cssVar, cx, useTheme } from 'antd-style';
|
|
27
|
+
import { forwardRef, useMemo, useRef, useState } from 'react';
|
|
28
|
+
import ChartTooltip from "../common/ChartTooltip";
|
|
29
|
+
import NoData from "../common/NoData";
|
|
30
|
+
import { defaultBenchmarkErrorFormatter, defaultBenchmarkValueFormatter, normalizeBenchmarkData } from "../common/benchmark";
|
|
31
|
+
import { constructCategoryColors } from "../common/utils";
|
|
32
|
+
import { useThemeColorRange } from "../hooks/useThemeColorRange";
|
|
33
|
+
import { getTextWidth } from "../utils/getMaxLabelLength";
|
|
34
|
+
import { styles } from "./styles";
|
|
35
|
+
import { createScale, getParetoFrontier, placeLabels } from "./utils";
|
|
36
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
37
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
38
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
39
|
+
var labelPriority = function labelPriority(point, frontierKeys) {
|
|
40
|
+
return (frontierKeys.has(point.key) ? 0 : 2) + (point.item.highlighted ? 0 : 1);
|
|
41
|
+
};
|
|
42
|
+
var MARGIN_TOP = 12;
|
|
43
|
+
var MARGIN_RIGHT = 16;
|
|
44
|
+
var TICK_GAP = 8;
|
|
45
|
+
var AXIS_TITLE_SIZE = 22;
|
|
46
|
+
// Monospace glyph advance relative to font size (Geist Mono / SF Mono ≈ 0.6em)
|
|
47
|
+
var MONO_CHAR_RATIO = 0.62;
|
|
48
|
+
var renderShape = function renderShape(shape, color, size) {
|
|
49
|
+
var ring = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
50
|
+
var half = size / 2;
|
|
51
|
+
var node;
|
|
52
|
+
switch (shape) {
|
|
53
|
+
case 'square':
|
|
54
|
+
{
|
|
55
|
+
node = /*#__PURE__*/_jsx("rect", {
|
|
56
|
+
fill: color,
|
|
57
|
+
height: size * 0.84,
|
|
58
|
+
width: size * 0.84,
|
|
59
|
+
x: size * 0.08,
|
|
60
|
+
y: size * 0.08
|
|
61
|
+
});
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case 'diamond':
|
|
65
|
+
{
|
|
66
|
+
node = /*#__PURE__*/_jsx("path", {
|
|
67
|
+
d: "M".concat(half, ",0 L").concat(size, ",").concat(half, " L").concat(half, ",").concat(size, " L0,").concat(half, " Z"),
|
|
68
|
+
fill: color
|
|
69
|
+
});
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'triangle':
|
|
73
|
+
{
|
|
74
|
+
node = /*#__PURE__*/_jsx("path", {
|
|
75
|
+
d: "M".concat(half, ",0 L").concat(size, ",").concat(size * 0.9, " L0,").concat(size * 0.9, " Z"),
|
|
76
|
+
fill: color
|
|
77
|
+
});
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
default:
|
|
81
|
+
{
|
|
82
|
+
node = /*#__PURE__*/_jsx("circle", {
|
|
83
|
+
cx: half,
|
|
84
|
+
cy: half,
|
|
85
|
+
fill: color,
|
|
86
|
+
r: half
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return /*#__PURE__*/_jsx("svg", {
|
|
91
|
+
height: size,
|
|
92
|
+
style: {
|
|
93
|
+
display: 'block',
|
|
94
|
+
overflow: 'visible'
|
|
95
|
+
},
|
|
96
|
+
width: size,
|
|
97
|
+
children: ring ? /*#__PURE__*/_jsx("g", {
|
|
98
|
+
paintOrder: "stroke",
|
|
99
|
+
stroke: cssVar.colorBgContainer,
|
|
100
|
+
strokeWidth: 4,
|
|
101
|
+
children: node
|
|
102
|
+
}) : node
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
var toLabelText = function toLabelText(name) {
|
|
106
|
+
return String(name !== null && name !== void 0 ? name : '').replaceAll('\n', ' ');
|
|
107
|
+
};
|
|
108
|
+
var BenchmarkScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
109
|
+
var _metrics$length;
|
|
110
|
+
var theme = useTheme();
|
|
111
|
+
var themeColorRange = useThemeColorRange();
|
|
112
|
+
var _props$data = props.data,
|
|
113
|
+
data = _props$data === void 0 ? [] : _props$data,
|
|
114
|
+
index = props.index,
|
|
115
|
+
valueKey = props.valueKey,
|
|
116
|
+
providerKey = props.providerKey,
|
|
117
|
+
iconKey = props.iconKey,
|
|
118
|
+
colorKey = props.colorKey,
|
|
119
|
+
errorKey = props.errorKey,
|
|
120
|
+
renderIcon = props.renderIcon,
|
|
121
|
+
_props$valueFormatter = props.valueFormatter,
|
|
122
|
+
valueFormatter = _props$valueFormatter === void 0 ? defaultBenchmarkValueFormatter : _props$valueFormatter,
|
|
123
|
+
accuracyFormatter = props.accuracyFormatter,
|
|
124
|
+
_props$errorFormatter = props.errorFormatter,
|
|
125
|
+
errorFormatter = _props$errorFormatter === void 0 ? defaultBenchmarkErrorFormatter : _props$errorFormatter,
|
|
126
|
+
_props$showError = props.showError,
|
|
127
|
+
showError = _props$showError === void 0 ? true : _props$showError,
|
|
128
|
+
_props$showErrorBars = props.showErrorBars,
|
|
129
|
+
showErrorBars = _props$showErrorBars === void 0 ? true : _props$showErrorBars,
|
|
130
|
+
_props$showAnimation = props.showAnimation,
|
|
131
|
+
showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
|
|
132
|
+
onValueChange = props.onValueChange,
|
|
133
|
+
className = props.className,
|
|
134
|
+
style = props.style,
|
|
135
|
+
loading = props.loading,
|
|
136
|
+
_props$width = props.width,
|
|
137
|
+
width = _props$width === void 0 ? '100%' : _props$width,
|
|
138
|
+
_props$height = props.height,
|
|
139
|
+
height = _props$height === void 0 ? 420 : _props$height,
|
|
140
|
+
noDataText = props.noDataText,
|
|
141
|
+
highlightColor = props.highlightColor,
|
|
142
|
+
frontierColor = props.frontierColor,
|
|
143
|
+
_props$frontierWidth = props.frontierWidth,
|
|
144
|
+
frontierWidth = _props$frontierWidth === void 0 ? 2 : _props$frontierWidth,
|
|
145
|
+
_props$iconSize = props.iconSize,
|
|
146
|
+
iconSize = _props$iconSize === void 0 ? 20 : _props$iconSize,
|
|
147
|
+
_props$markerSize = props.markerSize,
|
|
148
|
+
markerSize = _props$markerSize === void 0 ? 12 : _props$markerSize,
|
|
149
|
+
_props$labelFontSize = props.labelFontSize,
|
|
150
|
+
labelFontSize = _props$labelFontSize === void 0 ? 12 : _props$labelFontSize,
|
|
151
|
+
_props$valueLabelFont = props.valueLabelFontSize,
|
|
152
|
+
valueLabelFontSize = _props$valueLabelFont === void 0 ? 11 : _props$valueLabelFont,
|
|
153
|
+
metrics = props.metrics,
|
|
154
|
+
metric = props.metric,
|
|
155
|
+
defaultMetric = props.defaultMetric,
|
|
156
|
+
onMetricChange = props.onMetricChange,
|
|
157
|
+
minX = props.minX,
|
|
158
|
+
maxX = props.maxX,
|
|
159
|
+
minY = props.minY,
|
|
160
|
+
maxY = props.maxY,
|
|
161
|
+
_props$showDominatedA = props.showDominatedArea,
|
|
162
|
+
showDominatedArea = _props$showDominatedA === void 0 ? true : _props$showDominatedA,
|
|
163
|
+
_props$showFrontier = props.showFrontier,
|
|
164
|
+
showFrontier = _props$showFrontier === void 0 ? true : _props$showFrontier,
|
|
165
|
+
_props$showGridLines = props.showGridLines,
|
|
166
|
+
showGridLines = _props$showGridLines === void 0 ? true : _props$showGridLines,
|
|
167
|
+
_props$showLabels = props.showLabels,
|
|
168
|
+
showLabels = _props$showLabels === void 0 ? true : _props$showLabels,
|
|
169
|
+
_props$showLegend = props.showLegend,
|
|
170
|
+
showLegend = _props$showLegend === void 0 ? true : _props$showLegend,
|
|
171
|
+
_props$showTooltip = props.showTooltip,
|
|
172
|
+
showTooltip = _props$showTooltip === void 0 ? true : _props$showTooltip,
|
|
173
|
+
_props$showValueLabel = props.showValueLabel,
|
|
174
|
+
showValueLabel = _props$showValueLabel === void 0 ? true : _props$showValueLabel,
|
|
175
|
+
_props$showXAxis = props.showXAxis,
|
|
176
|
+
showXAxis = _props$showXAxis === void 0 ? true : _props$showXAxis,
|
|
177
|
+
_props$showYAxis = props.showYAxis,
|
|
178
|
+
showYAxis = _props$showYAxis === void 0 ? true : _props$showYAxis,
|
|
179
|
+
xAxisLabel = props.xAxisLabel,
|
|
180
|
+
_props$xDirection = props.xDirection,
|
|
181
|
+
xDirection = _props$xDirection === void 0 ? 'lower' : _props$xDirection,
|
|
182
|
+
_props$xFormatter = props.xFormatter,
|
|
183
|
+
xFormatter = _props$xFormatter === void 0 ? defaultBenchmarkValueFormatter : _props$xFormatter,
|
|
184
|
+
_props$xKey = props.xKey,
|
|
185
|
+
xKey = _props$xKey === void 0 ? 'x' : _props$xKey,
|
|
186
|
+
_props$xScale = props.xScale,
|
|
187
|
+
xScale = _props$xScale === void 0 ? 'linear' : _props$xScale,
|
|
188
|
+
yAxisLabel = props.yAxisLabel,
|
|
189
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
190
|
+
var plotRef = useRef(null);
|
|
191
|
+
var size = useSize(plotRef);
|
|
192
|
+
var _useState = useState(defaultMetric),
|
|
193
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
194
|
+
innerMetric = _useState2[0],
|
|
195
|
+
setInnerMetric = _useState2[1];
|
|
196
|
+
var _useState3 = useState(),
|
|
197
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
198
|
+
hoverKey = _useState4[0],
|
|
199
|
+
setHoverKey = _useState4[1];
|
|
200
|
+
var _useState5 = useState(),
|
|
201
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
202
|
+
selectedKey = _useState6[0],
|
|
203
|
+
setSelectedKey = _useState6[1];
|
|
204
|
+
var resolvedHighlightColor = highlightColor !== null && highlightColor !== void 0 ? highlightColor : theme.gold;
|
|
205
|
+
var resolvedFrontierColor = frontierColor !== null && frontierColor !== void 0 ? frontierColor : theme.orange;
|
|
206
|
+
var yFormatter = accuracyFormatter !== null && accuracyFormatter !== void 0 ? accuracyFormatter : valueFormatter;
|
|
207
|
+
var yName = yAxisLabel || (accuracyFormatter ? 'Accuracy' : 'Score');
|
|
208
|
+
var activeMetric = useMemo(function () {
|
|
209
|
+
if (metrics !== null && metrics !== void 0 && metrics.length) {
|
|
210
|
+
var _metrics$find, _found$axisLabel, _found$direction, _found$formatter, _found$max, _found$min, _found$scale;
|
|
211
|
+
var key = metric !== null && metric !== void 0 ? metric : innerMetric;
|
|
212
|
+
var found = (_metrics$find = metrics.find(function (m) {
|
|
213
|
+
return m.key === key;
|
|
214
|
+
})) !== null && _metrics$find !== void 0 ? _metrics$find : metrics[0];
|
|
215
|
+
return {
|
|
216
|
+
axisLabel: (_found$axisLabel = found.axisLabel) !== null && _found$axisLabel !== void 0 ? _found$axisLabel : found.label,
|
|
217
|
+
direction: (_found$direction = found.direction) !== null && _found$direction !== void 0 ? _found$direction : 'lower',
|
|
218
|
+
formatter: (_found$formatter = found.formatter) !== null && _found$formatter !== void 0 ? _found$formatter : defaultBenchmarkValueFormatter,
|
|
219
|
+
key: found.key,
|
|
220
|
+
label: found.label,
|
|
221
|
+
max: (_found$max = found.max) !== null && _found$max !== void 0 ? _found$max : maxX,
|
|
222
|
+
min: (_found$min = found.min) !== null && _found$min !== void 0 ? _found$min : minX,
|
|
223
|
+
scale: (_found$scale = found.scale) !== null && _found$scale !== void 0 ? _found$scale : 'linear'
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
axisLabel: xAxisLabel,
|
|
228
|
+
direction: xDirection,
|
|
229
|
+
formatter: xFormatter,
|
|
230
|
+
key: xKey,
|
|
231
|
+
label: xAxisLabel || 'X',
|
|
232
|
+
max: maxX,
|
|
233
|
+
min: minX,
|
|
234
|
+
scale: xScale
|
|
235
|
+
};
|
|
236
|
+
}, [innerMetric, maxX, metric, metrics, minX, xAxisLabel, xDirection, xFormatter, xKey, xScale]);
|
|
237
|
+
var items = useMemo(function () {
|
|
238
|
+
return normalizeBenchmarkData({
|
|
239
|
+
colorKey: colorKey,
|
|
240
|
+
data: data,
|
|
241
|
+
errorKey: errorKey,
|
|
242
|
+
iconKey: iconKey,
|
|
243
|
+
index: index,
|
|
244
|
+
providerKey: providerKey,
|
|
245
|
+
renderIcon: renderIcon,
|
|
246
|
+
sortOrder: 'descending',
|
|
247
|
+
valueKey: valueKey
|
|
248
|
+
});
|
|
249
|
+
}, [colorKey, data, errorKey, iconKey, index, providerKey, renderIcon, valueKey]);
|
|
250
|
+
var categoryColors = useMemo(function () {
|
|
251
|
+
return constructCategoryColors(items.map(function (item) {
|
|
252
|
+
return String(item.key);
|
|
253
|
+
}), themeColorRange);
|
|
254
|
+
}, [items, themeColorRange]);
|
|
255
|
+
var points = useMemo(function () {
|
|
256
|
+
return items.map(function (item) {
|
|
257
|
+
var _ref, _item$color;
|
|
258
|
+
return {
|
|
259
|
+
color: (_ref = (_item$color = item.color) !== null && _item$color !== void 0 ? _item$color : categoryColors.get(String(item.key))) !== null && _ref !== void 0 ? _ref : cssVar.colorPrimary,
|
|
260
|
+
item: item,
|
|
261
|
+
key: item.key,
|
|
262
|
+
x: Number(item.original[activeMetric.key]),
|
|
263
|
+
y: item.value
|
|
264
|
+
};
|
|
265
|
+
}).filter(function (p) {
|
|
266
|
+
return Number.isFinite(p.x) && Number.isFinite(p.y) && (activeMetric.scale !== 'log' || p.x > 0);
|
|
267
|
+
});
|
|
268
|
+
}, [activeMetric.key, activeMetric.scale, categoryColors, items]);
|
|
269
|
+
var frontier = useMemo(function () {
|
|
270
|
+
return showFrontier ? getParetoFrontier(points, activeMetric.direction) : [];
|
|
271
|
+
}, [activeMetric.direction, points, showFrontier]);
|
|
272
|
+
var frontierKeys = useMemo(function () {
|
|
273
|
+
return new Set(frontier.map(function (p) {
|
|
274
|
+
return p.key;
|
|
275
|
+
}));
|
|
276
|
+
}, [frontier]);
|
|
277
|
+
var enableErrorBars = showError && showErrorBars;
|
|
278
|
+
var yValues = useMemo(function () {
|
|
279
|
+
return points.flatMap(function (p) {
|
|
280
|
+
return enableErrorBars && p.item.error ? [p.y - p.item.error, p.y + p.item.error] : [p.y];
|
|
281
|
+
});
|
|
282
|
+
}, [enableErrorBars, points]);
|
|
283
|
+
var labelSizes = useMemo(function () {
|
|
284
|
+
var map = new Map();
|
|
285
|
+
if (!showLabels) return map;
|
|
286
|
+
var nameScale = labelFontSize / 12 * 1.1;
|
|
287
|
+
var _iterator = _createForOfIteratorHelper(points),
|
|
288
|
+
_step;
|
|
289
|
+
try {
|
|
290
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
291
|
+
var p = _step.value;
|
|
292
|
+
var nameWidth = getTextWidth(toLabelText(p.item.name)) * nameScale;
|
|
293
|
+
var valueWidth = showValueLabel ? "".concat(yFormatter(p.y), " \xB7 ").concat(activeMetric.formatter(p.x)).length * valueLabelFontSize * MONO_CHAR_RATIO : 0;
|
|
294
|
+
map.set(p.key, {
|
|
295
|
+
height: Math.ceil(labelFontSize * 1.3 + (showValueLabel ? valueLabelFontSize * 1.3 : 0)),
|
|
296
|
+
width: Math.ceil(Math.max(nameWidth, valueWidth)) + 2
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
} catch (err) {
|
|
300
|
+
_iterator.e(err);
|
|
301
|
+
} finally {
|
|
302
|
+
_iterator.f();
|
|
303
|
+
}
|
|
304
|
+
return map;
|
|
305
|
+
}, [activeMetric, labelFontSize, points, showLabels, showValueLabel, valueLabelFontSize, yFormatter]);
|
|
306
|
+
var plotWidth = (size === null || size === void 0 ? void 0 : size.width) || (typeof width === 'number' ? width : 0);
|
|
307
|
+
var plotHeight = typeof height === 'number' ? height : 420;
|
|
308
|
+
var layout = useMemo(function () {
|
|
309
|
+
if (!plotWidth || !points.length) return null;
|
|
310
|
+
var probeY = createScale({
|
|
311
|
+
max: maxY,
|
|
312
|
+
min: minY,
|
|
313
|
+
range: [0, 1],
|
|
314
|
+
values: yValues
|
|
315
|
+
});
|
|
316
|
+
var yTickWidth = showYAxis ? Math.max.apply(Math, _toConsumableArray(probeY.ticks.map(function (t) {
|
|
317
|
+
return yFormatter(t).length * 12 * MONO_CHAR_RATIO;
|
|
318
|
+
})).concat([0])) : 0;
|
|
319
|
+
var left = (showYAxis ? yTickWidth + TICK_GAP + 4 : 4) + (yAxisLabel ? AXIS_TITLE_SIZE : 0);
|
|
320
|
+
var bottom = (showXAxis ? 26 : 4) + (activeMetric.axisLabel ? AXIS_TITLE_SIZE : 0);
|
|
321
|
+
var innerRight = plotWidth - MARGIN_RIGHT;
|
|
322
|
+
var innerBottom = plotHeight - bottom;
|
|
323
|
+
var xScaleObj = createScale({
|
|
324
|
+
max: activeMetric.max,
|
|
325
|
+
min: activeMetric.min,
|
|
326
|
+
range: [left, innerRight],
|
|
327
|
+
type: activeMetric.scale,
|
|
328
|
+
values: points.map(function (p) {
|
|
329
|
+
return p.x;
|
|
330
|
+
})
|
|
331
|
+
});
|
|
332
|
+
var yScaleObj = createScale({
|
|
333
|
+
max: maxY,
|
|
334
|
+
min: minY,
|
|
335
|
+
range: [innerBottom, MARGIN_TOP],
|
|
336
|
+
values: yValues
|
|
337
|
+
});
|
|
338
|
+
var positions = new Map();
|
|
339
|
+
var _iterator2 = _createForOfIteratorHelper(points),
|
|
340
|
+
_step2;
|
|
341
|
+
try {
|
|
342
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
343
|
+
var p = _step2.value;
|
|
344
|
+
positions.set(p.key, {
|
|
345
|
+
px: xScaleObj.map(p.x),
|
|
346
|
+
py: yScaleObj.map(p.y),
|
|
347
|
+
radius: (p.item.icon ? iconSize : markerSize) / 2
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
} catch (err) {
|
|
351
|
+
_iterator2.e(err);
|
|
352
|
+
} finally {
|
|
353
|
+
_iterator2.f();
|
|
354
|
+
}
|
|
355
|
+
var frontierPath = frontier.map(function (p, i) {
|
|
356
|
+
var pos = positions.get(p.key);
|
|
357
|
+
return "".concat(i === 0 ? 'M' : 'L').concat(pos.px.toFixed(2), ",").concat(pos.py.toFixed(2));
|
|
358
|
+
}).join(' ');
|
|
359
|
+
var labels = new Map();
|
|
360
|
+
if (showLabels) {
|
|
361
|
+
var lineBoxes = [];
|
|
362
|
+
for (var i = 1; i < frontier.length; i++) {
|
|
363
|
+
var a = positions.get(frontier[i - 1].key);
|
|
364
|
+
var b = positions.get(frontier[i].key);
|
|
365
|
+
var steps = Math.max(1, Math.ceil(Math.hypot(b.px - a.px, b.py - a.py) / 10));
|
|
366
|
+
for (var s = 0; s <= steps; s++) {
|
|
367
|
+
var t = s / steps;
|
|
368
|
+
lineBoxes.push({
|
|
369
|
+
height: 6,
|
|
370
|
+
width: 6,
|
|
371
|
+
x: a.px + (b.px - a.px) * t - 3,
|
|
372
|
+
y: a.py + (b.py - a.py) * t - 3
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
var ordered = _toConsumableArray(points).sort(function (a, b) {
|
|
377
|
+
return labelPriority(a, frontierKeys) - labelPriority(b, frontierKeys) || b.y - a.y;
|
|
378
|
+
});
|
|
379
|
+
var candidates = ordered.map(function (p) {
|
|
380
|
+
var _labelSizes$get;
|
|
381
|
+
var pos = positions.get(p.key);
|
|
382
|
+
var labelSize = (_labelSizes$get = labelSizes.get(p.key)) !== null && _labelSizes$get !== void 0 ? _labelSizes$get : {
|
|
383
|
+
height: 16,
|
|
384
|
+
width: 40
|
|
385
|
+
};
|
|
386
|
+
return _objectSpread(_objectSpread({}, labelSize), {}, {
|
|
387
|
+
key: p.key
|
|
388
|
+
}, pos);
|
|
389
|
+
});
|
|
390
|
+
labels = placeLabels(candidates, {
|
|
391
|
+
height: innerBottom,
|
|
392
|
+
width: plotWidth - left + MARGIN_RIGHT,
|
|
393
|
+
x: left,
|
|
394
|
+
y: 0
|
|
395
|
+
}, {
|
|
396
|
+
lines: lineBoxes
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
bottom: bottom,
|
|
401
|
+
frontierPath: frontierPath,
|
|
402
|
+
innerBottom: innerBottom,
|
|
403
|
+
innerRight: innerRight,
|
|
404
|
+
labels: labels,
|
|
405
|
+
left: left,
|
|
406
|
+
positions: positions,
|
|
407
|
+
xScale: xScaleObj,
|
|
408
|
+
yScale: yScaleObj
|
|
409
|
+
};
|
|
410
|
+
}, [activeMetric, frontier, frontierKeys, iconSize, labelSizes, markerSize, maxY, minY, plotHeight, plotWidth, points, showLabels, showXAxis, showYAxis, yAxisLabel, yFormatter, yValues]);
|
|
411
|
+
if (loading || !data) return /*#__PURE__*/_jsx(Skeleton, {
|
|
412
|
+
height: plotHeight,
|
|
413
|
+
width: width
|
|
414
|
+
});
|
|
415
|
+
var focusKey = hoverKey !== null && hoverKey !== void 0 ? hoverKey : selectedKey;
|
|
416
|
+
var focusPoint = focusKey === undefined ? undefined : points.find(function (point) {
|
|
417
|
+
return point.key === focusKey;
|
|
418
|
+
});
|
|
419
|
+
var dominatedKeys = new Set();
|
|
420
|
+
if (showDominatedArea && focusPoint) {
|
|
421
|
+
var _iterator3 = _createForOfIteratorHelper(points),
|
|
422
|
+
_step3;
|
|
423
|
+
try {
|
|
424
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
425
|
+
var point = _step3.value;
|
|
426
|
+
if (point.key === focusPoint.key || point.y > focusPoint.y) continue;
|
|
427
|
+
var worseX = activeMetric.direction === 'lower' ? point.x >= focusPoint.x : point.x <= focusPoint.x;
|
|
428
|
+
if (worseX) dominatedKeys.add(point.key);
|
|
429
|
+
}
|
|
430
|
+
} catch (err) {
|
|
431
|
+
_iterator3.e(err);
|
|
432
|
+
} finally {
|
|
433
|
+
_iterator3.f();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
var getEmphasis = function getEmphasis(key) {
|
|
437
|
+
if (focusKey === undefined || key === focusKey) return 'normal';
|
|
438
|
+
if (!showDominatedArea) return 'dimmed';
|
|
439
|
+
return dominatedKeys.has(key) ? 'dominated' : 'normal';
|
|
440
|
+
};
|
|
441
|
+
var isDimmed = function isDimmed(key) {
|
|
442
|
+
return getEmphasis(key) !== 'normal';
|
|
443
|
+
};
|
|
444
|
+
var animatedCls = showAnimation ? undefined : styles.noTransition;
|
|
445
|
+
var handleClick = function handleClick(item) {
|
|
446
|
+
if (!onValueChange) return;
|
|
447
|
+
if (selectedKey === item.key) {
|
|
448
|
+
setSelectedKey(undefined);
|
|
449
|
+
onValueChange(null);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
setSelectedKey(item.key);
|
|
453
|
+
var payload = _objectSpread(_objectSpread({}, item.original), {}, {
|
|
454
|
+
eventType: 'point',
|
|
455
|
+
rank: item.rank,
|
|
456
|
+
value: item.value
|
|
457
|
+
});
|
|
458
|
+
onValueChange(payload);
|
|
459
|
+
};
|
|
460
|
+
var handleMetricChange = function handleMetricChange(key) {
|
|
461
|
+
if (metric === undefined) setInnerMetric(key);
|
|
462
|
+
onMetricChange === null || onMetricChange === void 0 || onMetricChange(key);
|
|
463
|
+
};
|
|
464
|
+
var renderTooltip = function renderTooltip(point, child) {
|
|
465
|
+
if (!showTooltip) return child;
|
|
466
|
+
var item = point.item;
|
|
467
|
+
var rows = [];
|
|
468
|
+
if (metrics !== null && metrics !== void 0 && metrics.length) {
|
|
469
|
+
var _iterator4 = _createForOfIteratorHelper(metrics),
|
|
470
|
+
_step4;
|
|
471
|
+
try {
|
|
472
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
473
|
+
var _m$formatter;
|
|
474
|
+
var m = _step4.value;
|
|
475
|
+
var _value2 = Number(item.original[m.key]);
|
|
476
|
+
if (!Number.isFinite(_value2)) continue;
|
|
477
|
+
rows.push({
|
|
478
|
+
format: (_m$formatter = m.formatter) !== null && _m$formatter !== void 0 ? _m$formatter : defaultBenchmarkValueFormatter,
|
|
479
|
+
name: m.label,
|
|
480
|
+
value: _value2
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
} catch (err) {
|
|
484
|
+
_iterator4.e(err);
|
|
485
|
+
} finally {
|
|
486
|
+
_iterator4.f();
|
|
487
|
+
}
|
|
488
|
+
} else {
|
|
489
|
+
rows.push({
|
|
490
|
+
format: activeMetric.formatter,
|
|
491
|
+
name: activeMetric.label,
|
|
492
|
+
value: point.x
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
rows.reverse();
|
|
496
|
+
rows.push({
|
|
497
|
+
format: function format(v) {
|
|
498
|
+
return showError && item.error !== undefined ? "".concat(yFormatter(v), " \xB1 ").concat(errorFormatter(item.error)) : yFormatter(v);
|
|
499
|
+
},
|
|
500
|
+
name: yName,
|
|
501
|
+
value: point.y
|
|
502
|
+
});
|
|
503
|
+
var formatters = new Map(rows.map(function (row) {
|
|
504
|
+
return [row.name, row.format];
|
|
505
|
+
}));
|
|
506
|
+
var modelName = toLabelText(item.name);
|
|
507
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
508
|
+
arrow: false,
|
|
509
|
+
mouseEnterDelay: 0.05,
|
|
510
|
+
mouseLeaveDelay: 0,
|
|
511
|
+
styles: {
|
|
512
|
+
container: {
|
|
513
|
+
background: 'transparent',
|
|
514
|
+
boxShadow: 'none',
|
|
515
|
+
maxWidth: 'none',
|
|
516
|
+
padding: 0,
|
|
517
|
+
pointerEvents: 'none',
|
|
518
|
+
width: 'max-content'
|
|
519
|
+
},
|
|
520
|
+
content: {
|
|
521
|
+
color: cssVar.colorText,
|
|
522
|
+
fontSize: cssVar.fontSize,
|
|
523
|
+
lineHeight: cssVar.lineHeight,
|
|
524
|
+
maxWidth: 'none',
|
|
525
|
+
overflow: 'visible',
|
|
526
|
+
padding: 0
|
|
527
|
+
},
|
|
528
|
+
root: {
|
|
529
|
+
maxWidth: 'none',
|
|
530
|
+
pointerEvents: 'none'
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
title: /*#__PURE__*/_jsx(ChartTooltip, {
|
|
534
|
+
active: true,
|
|
535
|
+
categoryColors: new Map(rows.map(function (row) {
|
|
536
|
+
return [row.name, point.color];
|
|
537
|
+
})),
|
|
538
|
+
label: item.provider ? "".concat(modelName, " \xB7 ").concat(String(item.provider)) : modelName,
|
|
539
|
+
payload: rows.map(function (row) {
|
|
540
|
+
return {
|
|
541
|
+
dataKey: row.name,
|
|
542
|
+
name: row.name,
|
|
543
|
+
value: row.value
|
|
544
|
+
};
|
|
545
|
+
}),
|
|
546
|
+
valueFormatter: function valueFormatter(value, name) {
|
|
547
|
+
var _formatters$get;
|
|
548
|
+
return ((_formatters$get = formatters.get(name !== null && name !== void 0 ? name : '')) !== null && _formatters$get !== void 0 ? _formatters$get : String)(Number(value));
|
|
549
|
+
}
|
|
550
|
+
}),
|
|
551
|
+
children: child
|
|
552
|
+
});
|
|
553
|
+
};
|
|
554
|
+
var renderMarker = function renderMarker(point, markerSizePx) {
|
|
555
|
+
var ring = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
556
|
+
return point.item.icon ? /*#__PURE__*/_jsx("span", {
|
|
557
|
+
className: ring ? styles.markerIconRing : undefined,
|
|
558
|
+
style: {
|
|
559
|
+
alignItems: 'center',
|
|
560
|
+
display: 'flex',
|
|
561
|
+
flexShrink: 0,
|
|
562
|
+
height: iconSize,
|
|
563
|
+
justifyContent: 'center',
|
|
564
|
+
transform: markerSizePx === iconSize ? undefined : "scale(".concat(markerSizePx / iconSize, ")"),
|
|
565
|
+
width: iconSize
|
|
566
|
+
},
|
|
567
|
+
children: point.item.icon
|
|
568
|
+
}) : renderShape(point.item.original.shape, point.color, markerSizePx, ring);
|
|
569
|
+
};
|
|
570
|
+
var hasMetricSwitch = ((_metrics$length = metrics === null || metrics === void 0 ? void 0 : metrics.length) !== null && _metrics$length !== void 0 ? _metrics$length : 0) > 1;
|
|
571
|
+
return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
|
|
572
|
+
className: cx(styles.container, className),
|
|
573
|
+
ref: ref,
|
|
574
|
+
style: _objectSpread({
|
|
575
|
+
'--benchmark-label-font-size': "".concat(labelFontSize, "px"),
|
|
576
|
+
'--benchmark-value-label-font-size': "".concat(valueLabelFontSize, "px"),
|
|
577
|
+
'width': width
|
|
578
|
+
}, style)
|
|
579
|
+
}, rest), {}, {
|
|
580
|
+
children: [showLegend && points.length > 0 || hasMetricSwitch ? /*#__PURE__*/_jsxs("div", {
|
|
581
|
+
className: styles.header,
|
|
582
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
583
|
+
className: styles.legend,
|
|
584
|
+
children: showLegend ? points.map(function (point) {
|
|
585
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
586
|
+
className: styles.legendItem,
|
|
587
|
+
onClick: function onClick() {
|
|
588
|
+
return handleClick(point.item);
|
|
589
|
+
},
|
|
590
|
+
onMouseEnter: function onMouseEnter() {
|
|
591
|
+
return setHoverKey(point.key);
|
|
592
|
+
},
|
|
593
|
+
onMouseLeave: function onMouseLeave() {
|
|
594
|
+
return setHoverKey(undefined);
|
|
595
|
+
},
|
|
596
|
+
style: {
|
|
597
|
+
color: point.item.highlighted ? resolvedHighlightColor : undefined,
|
|
598
|
+
cursor: onValueChange ? 'pointer' : undefined,
|
|
599
|
+
opacity: isDimmed(point.key) ? 0.4 : 1
|
|
600
|
+
},
|
|
601
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
602
|
+
className: styles.legendMarker,
|
|
603
|
+
children: renderMarker(point, 12)
|
|
604
|
+
}), toLabelText(point.item.name)]
|
|
605
|
+
}, "legend-".concat(point.key));
|
|
606
|
+
}) : null
|
|
607
|
+
}), hasMetricSwitch ? /*#__PURE__*/_jsx(Segmented, {
|
|
608
|
+
onChange: function onChange(value) {
|
|
609
|
+
return handleMetricChange(String(value));
|
|
610
|
+
},
|
|
611
|
+
options: metrics.map(function (m) {
|
|
612
|
+
return {
|
|
613
|
+
label: m.label,
|
|
614
|
+
value: m.key
|
|
615
|
+
};
|
|
616
|
+
}),
|
|
617
|
+
size: "small",
|
|
618
|
+
value: activeMetric.key
|
|
619
|
+
}) : null]
|
|
620
|
+
}) : null, /*#__PURE__*/_jsxs("div", {
|
|
621
|
+
className: styles.plot,
|
|
622
|
+
ref: plotRef,
|
|
623
|
+
style: {
|
|
624
|
+
height: plotHeight
|
|
625
|
+
},
|
|
626
|
+
children: [!points.length ? /*#__PURE__*/_jsx(NoData, {
|
|
627
|
+
noDataText: noDataText
|
|
628
|
+
}) : null, layout ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
629
|
+
children: [/*#__PURE__*/_jsxs("svg", {
|
|
630
|
+
height: plotHeight,
|
|
631
|
+
role: "img",
|
|
632
|
+
style: {
|
|
633
|
+
display: 'block',
|
|
634
|
+
overflow: 'visible'
|
|
635
|
+
},
|
|
636
|
+
width: plotWidth,
|
|
637
|
+
children: [showGridLines ? /*#__PURE__*/_jsxs("g", {
|
|
638
|
+
children: [layout.yScale.ticks.map(function (tick) {
|
|
639
|
+
var y = layout.yScale.map(tick);
|
|
640
|
+
return /*#__PURE__*/_jsx("line", {
|
|
641
|
+
className: styles.gridLine,
|
|
642
|
+
x1: layout.left,
|
|
643
|
+
x2: layout.innerRight,
|
|
644
|
+
y1: y,
|
|
645
|
+
y2: y
|
|
646
|
+
}, "gy-".concat(tick));
|
|
647
|
+
}), layout.xScale.ticks.map(function (tick) {
|
|
648
|
+
var x = layout.xScale.map(tick);
|
|
649
|
+
return /*#__PURE__*/_jsx("line", {
|
|
650
|
+
className: styles.gridLine,
|
|
651
|
+
x1: x,
|
|
652
|
+
x2: x,
|
|
653
|
+
y1: MARGIN_TOP,
|
|
654
|
+
y2: layout.innerBottom
|
|
655
|
+
}, "gx-".concat(tick));
|
|
656
|
+
})]
|
|
657
|
+
}) : null, showYAxis ? /*#__PURE__*/_jsx("g", {
|
|
658
|
+
children: layout.yScale.ticks.map(function (tick) {
|
|
659
|
+
return /*#__PURE__*/_jsx("text", {
|
|
660
|
+
className: styles.tickLabel,
|
|
661
|
+
dominantBaseline: "middle",
|
|
662
|
+
textAnchor: "end",
|
|
663
|
+
x: layout.left - TICK_GAP,
|
|
664
|
+
y: layout.yScale.map(tick),
|
|
665
|
+
children: yFormatter(tick)
|
|
666
|
+
}, "ty-".concat(tick));
|
|
667
|
+
})
|
|
668
|
+
}) : null, showXAxis ? /*#__PURE__*/_jsxs("g", {
|
|
669
|
+
children: [/*#__PURE__*/_jsx("line", {
|
|
670
|
+
className: styles.axisLine,
|
|
671
|
+
x1: layout.left,
|
|
672
|
+
x2: layout.innerRight,
|
|
673
|
+
y1: layout.innerBottom,
|
|
674
|
+
y2: layout.innerBottom
|
|
675
|
+
}), layout.xScale.ticks.map(function (tick) {
|
|
676
|
+
return /*#__PURE__*/_jsx("text", {
|
|
677
|
+
className: styles.tickLabel,
|
|
678
|
+
dominantBaseline: "hanging",
|
|
679
|
+
textAnchor: "middle",
|
|
680
|
+
x: layout.xScale.map(tick),
|
|
681
|
+
y: layout.innerBottom + TICK_GAP,
|
|
682
|
+
children: activeMetric.formatter(tick)
|
|
683
|
+
}, "tx-".concat(tick));
|
|
684
|
+
})]
|
|
685
|
+
}) : null, yAxisLabel ? /*#__PURE__*/_jsx("text", {
|
|
686
|
+
className: styles.axisLabel,
|
|
687
|
+
dominantBaseline: "hanging",
|
|
688
|
+
textAnchor: "middle",
|
|
689
|
+
transform: "rotate(-90, 0, ".concat((MARGIN_TOP + layout.innerBottom) / 2, ")"),
|
|
690
|
+
x: 0,
|
|
691
|
+
y: (MARGIN_TOP + layout.innerBottom) / 2,
|
|
692
|
+
children: yAxisLabel
|
|
693
|
+
}) : null, activeMetric.axisLabel ? /*#__PURE__*/_jsx("text", {
|
|
694
|
+
className: styles.axisLabel,
|
|
695
|
+
dominantBaseline: "auto",
|
|
696
|
+
textAnchor: "middle",
|
|
697
|
+
x: (layout.left + layout.innerRight) / 2,
|
|
698
|
+
y: plotHeight - 4,
|
|
699
|
+
children: activeMetric.axisLabel
|
|
700
|
+
}) : null, showDominatedArea && focusPoint ? function () {
|
|
701
|
+
var pos = layout.positions.get(focusPoint.key);
|
|
702
|
+
var toRight = activeMetric.direction === 'lower';
|
|
703
|
+
var x0 = toRight ? pos.px : layout.left;
|
|
704
|
+
var x1 = toRight ? layout.innerRight : pos.px;
|
|
705
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
706
|
+
className: styles.dominatedArea,
|
|
707
|
+
"data-testid": "benchmark-scatter-dominated-area",
|
|
708
|
+
children: [/*#__PURE__*/_jsx("rect", {
|
|
709
|
+
fill: resolvedFrontierColor,
|
|
710
|
+
fillOpacity: 0.08,
|
|
711
|
+
height: Math.max(0, layout.innerBottom - pos.py),
|
|
712
|
+
width: Math.max(0, x1 - x0),
|
|
713
|
+
x: x0,
|
|
714
|
+
y: pos.py
|
|
715
|
+
}), /*#__PURE__*/_jsx("line", {
|
|
716
|
+
className: styles.dominatedGuide,
|
|
717
|
+
x1: x0,
|
|
718
|
+
x2: x1,
|
|
719
|
+
y1: pos.py,
|
|
720
|
+
y2: pos.py
|
|
721
|
+
}), /*#__PURE__*/_jsx("line", {
|
|
722
|
+
className: styles.dominatedGuide,
|
|
723
|
+
x1: pos.px,
|
|
724
|
+
x2: pos.px,
|
|
725
|
+
y1: pos.py,
|
|
726
|
+
y2: layout.innerBottom
|
|
727
|
+
})]
|
|
728
|
+
});
|
|
729
|
+
}() : null, enableErrorBars ? points.map(function (point) {
|
|
730
|
+
var error = point.item.error;
|
|
731
|
+
if (!error) return null;
|
|
732
|
+
var pos = layout.positions.get(point.key);
|
|
733
|
+
var top = layout.yScale.map(point.y + error);
|
|
734
|
+
var bottom = layout.yScale.map(point.y - error);
|
|
735
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
736
|
+
className: styles.errorBar,
|
|
737
|
+
"data-testid": "benchmark-scatter-error-bar",
|
|
738
|
+
opacity: isDimmed(point.key) ? 0.25 : 0.7,
|
|
739
|
+
stroke: point.color,
|
|
740
|
+
children: [/*#__PURE__*/_jsx("line", {
|
|
741
|
+
x1: pos.px,
|
|
742
|
+
x2: pos.px,
|
|
743
|
+
y1: top,
|
|
744
|
+
y2: bottom
|
|
745
|
+
}), /*#__PURE__*/_jsx("line", {
|
|
746
|
+
x1: pos.px - 4,
|
|
747
|
+
x2: pos.px + 4,
|
|
748
|
+
y1: top,
|
|
749
|
+
y2: top
|
|
750
|
+
}), /*#__PURE__*/_jsx("line", {
|
|
751
|
+
x1: pos.px - 4,
|
|
752
|
+
x2: pos.px + 4,
|
|
753
|
+
y1: bottom,
|
|
754
|
+
y2: bottom
|
|
755
|
+
})]
|
|
756
|
+
}, "err-".concat(point.key));
|
|
757
|
+
}) : null, layout.frontierPath ? /*#__PURE__*/_jsx("path", {
|
|
758
|
+
className: styles.frontier,
|
|
759
|
+
d: layout.frontierPath,
|
|
760
|
+
"data-testid": "benchmark-scatter-frontier",
|
|
761
|
+
opacity: !showDominatedArea && focusKey !== undefined && !frontierKeys.has(focusKey) ? 0.35 : 1,
|
|
762
|
+
stroke: resolvedFrontierColor,
|
|
763
|
+
strokeWidth: frontierWidth,
|
|
764
|
+
style: showAnimation ? {
|
|
765
|
+
transition: "d 0.4s, opacity 0.2s"
|
|
766
|
+
} : undefined
|
|
767
|
+
}) : null]
|
|
768
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
769
|
+
className: styles.overlay,
|
|
770
|
+
children: [points.map(function (point) {
|
|
771
|
+
var pos = layout.positions.get(point.key);
|
|
772
|
+
var markerPx = point.item.icon ? iconSize : markerSize;
|
|
773
|
+
return /*#__PURE__*/_jsx("div", {
|
|
774
|
+
children: renderTooltip(point, /*#__PURE__*/_jsx("div", {
|
|
775
|
+
"aria-label": "".concat(toLabelText(point.item.name), ": ").concat(yFormatter(point.y), ", ").concat(activeMetric.formatter(point.x)),
|
|
776
|
+
className: cx(styles.marker, animatedCls),
|
|
777
|
+
onClick: function onClick() {
|
|
778
|
+
return handleClick(point.item);
|
|
779
|
+
},
|
|
780
|
+
onMouseEnter: function onMouseEnter() {
|
|
781
|
+
return setHoverKey(point.key);
|
|
782
|
+
},
|
|
783
|
+
onMouseLeave: function onMouseLeave() {
|
|
784
|
+
return setHoverKey(undefined);
|
|
785
|
+
},
|
|
786
|
+
role: "button",
|
|
787
|
+
style: {
|
|
788
|
+
cursor: onValueChange ? 'pointer' : 'default',
|
|
789
|
+
filter: getEmphasis(point.key) === 'dominated' ? 'grayscale(1)' : undefined,
|
|
790
|
+
height: markerPx,
|
|
791
|
+
left: pos.px,
|
|
792
|
+
opacity: {
|
|
793
|
+
dimmed: 0.25,
|
|
794
|
+
dominated: 0.5,
|
|
795
|
+
normal: 1
|
|
796
|
+
}[getEmphasis(point.key)],
|
|
797
|
+
top: pos.py,
|
|
798
|
+
width: markerPx
|
|
799
|
+
},
|
|
800
|
+
children: renderMarker(point, markerPx, true)
|
|
801
|
+
}))
|
|
802
|
+
}, "marker-".concat(point.key));
|
|
803
|
+
}), showLabels ? points.map(function (point) {
|
|
804
|
+
var label = layout.labels.get(point.key);
|
|
805
|
+
if (!label) return null;
|
|
806
|
+
var emphasis = getEmphasis(point.key);
|
|
807
|
+
var textColor = emphasis === 'dominated' ? cssVar.colorTextQuaternary : point.item.highlighted ? resolvedHighlightColor : undefined;
|
|
808
|
+
var isKeyLabel = emphasis !== 'dominated' && (frontierKeys.has(point.key) || point.item.highlighted || point.key === focusKey);
|
|
809
|
+
var align = label.placement.endsWith('left') ? 'right' : label.placement === 'top' || label.placement === 'bottom' ? 'center' : 'left';
|
|
810
|
+
var name = toLabelText(point.item.name);
|
|
811
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
812
|
+
className: cx(styles.label, animatedCls),
|
|
813
|
+
onClick: function onClick() {
|
|
814
|
+
return handleClick(point.item);
|
|
815
|
+
},
|
|
816
|
+
onMouseEnter: function onMouseEnter() {
|
|
817
|
+
return setHoverKey(point.key);
|
|
818
|
+
},
|
|
819
|
+
onMouseLeave: function onMouseLeave() {
|
|
820
|
+
return setHoverKey(undefined);
|
|
821
|
+
},
|
|
822
|
+
style: {
|
|
823
|
+
cursor: onValueChange ? 'pointer' : 'default',
|
|
824
|
+
height: label.height,
|
|
825
|
+
left: label.x,
|
|
826
|
+
opacity: emphasis === 'dimmed' ? 0.25 : 1,
|
|
827
|
+
textAlign: align,
|
|
828
|
+
top: label.y,
|
|
829
|
+
width: label.width
|
|
830
|
+
},
|
|
831
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
832
|
+
className: cx(styles.labelName, isKeyLabel && styles.labelNameEmphasis),
|
|
833
|
+
style: textColor ? {
|
|
834
|
+
color: textColor
|
|
835
|
+
} : undefined,
|
|
836
|
+
children: point.item.href ? /*#__PURE__*/_jsx(A, {
|
|
837
|
+
className: styles.labelNameLink,
|
|
838
|
+
href: point.item.href,
|
|
839
|
+
onClick: function onClick(event) {
|
|
840
|
+
return event.stopPropagation();
|
|
841
|
+
},
|
|
842
|
+
target: point.item.target,
|
|
843
|
+
children: name
|
|
844
|
+
}) : name
|
|
845
|
+
}), showValueLabel ? /*#__PURE__*/_jsxs("div", {
|
|
846
|
+
className: styles.labelValue,
|
|
847
|
+
children: [yFormatter(point.y), " \xB7 ", activeMetric.formatter(point.x)]
|
|
848
|
+
}) : null]
|
|
849
|
+
}, "label-".concat(point.key));
|
|
850
|
+
}) : null]
|
|
851
|
+
})]
|
|
852
|
+
}) : null]
|
|
853
|
+
})]
|
|
854
|
+
}));
|
|
855
|
+
});
|
|
856
|
+
BenchmarkScatterChart.displayName = 'BenchmarkScatterChart';
|
|
857
|
+
export default BenchmarkScatterChart;
|