@lobehub/charts 5.5.1 → 5.6.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/BenchmarkScatterChart/index.d.ts +145 -0
- package/es/BenchmarkScatterChart/index.js +850 -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/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 +3 -3
|
@@ -0,0 +1,850 @@
|
|
|
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, Skeleton } from '@lobehub/ui';
|
|
24
|
+
import { useSize } from 'ahooks';
|
|
25
|
+
import { Segmented, Tooltip } from 'antd';
|
|
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.Block, {
|
|
412
|
+
active: true,
|
|
413
|
+
height: plotHeight,
|
|
414
|
+
width: width
|
|
415
|
+
});
|
|
416
|
+
var focusKey = hoverKey !== null && hoverKey !== void 0 ? hoverKey : selectedKey;
|
|
417
|
+
var focusPoint = focusKey === undefined ? undefined : points.find(function (point) {
|
|
418
|
+
return point.key === focusKey;
|
|
419
|
+
});
|
|
420
|
+
var dominatedKeys = new Set();
|
|
421
|
+
if (showDominatedArea && focusPoint) {
|
|
422
|
+
var _iterator3 = _createForOfIteratorHelper(points),
|
|
423
|
+
_step3;
|
|
424
|
+
try {
|
|
425
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
426
|
+
var point = _step3.value;
|
|
427
|
+
if (point.key === focusPoint.key || point.y > focusPoint.y) continue;
|
|
428
|
+
var worseX = activeMetric.direction === 'lower' ? point.x >= focusPoint.x : point.x <= focusPoint.x;
|
|
429
|
+
if (worseX) dominatedKeys.add(point.key);
|
|
430
|
+
}
|
|
431
|
+
} catch (err) {
|
|
432
|
+
_iterator3.e(err);
|
|
433
|
+
} finally {
|
|
434
|
+
_iterator3.f();
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
var getEmphasis = function getEmphasis(key) {
|
|
438
|
+
if (focusKey === undefined || key === focusKey) return 'normal';
|
|
439
|
+
if (!showDominatedArea) return 'dimmed';
|
|
440
|
+
return dominatedKeys.has(key) ? 'dominated' : 'normal';
|
|
441
|
+
};
|
|
442
|
+
var isDimmed = function isDimmed(key) {
|
|
443
|
+
return getEmphasis(key) !== 'normal';
|
|
444
|
+
};
|
|
445
|
+
var animatedCls = showAnimation ? undefined : styles.noTransition;
|
|
446
|
+
var handleClick = function handleClick(item) {
|
|
447
|
+
if (!onValueChange) return;
|
|
448
|
+
if (selectedKey === item.key) {
|
|
449
|
+
setSelectedKey(undefined);
|
|
450
|
+
onValueChange(null);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
setSelectedKey(item.key);
|
|
454
|
+
var payload = _objectSpread(_objectSpread({}, item.original), {}, {
|
|
455
|
+
eventType: 'point',
|
|
456
|
+
rank: item.rank,
|
|
457
|
+
value: item.value
|
|
458
|
+
});
|
|
459
|
+
onValueChange(payload);
|
|
460
|
+
};
|
|
461
|
+
var handleMetricChange = function handleMetricChange(key) {
|
|
462
|
+
if (metric === undefined) setInnerMetric(key);
|
|
463
|
+
onMetricChange === null || onMetricChange === void 0 || onMetricChange(key);
|
|
464
|
+
};
|
|
465
|
+
var renderTooltip = function renderTooltip(point, child) {
|
|
466
|
+
if (!showTooltip) return child;
|
|
467
|
+
var item = point.item;
|
|
468
|
+
var rows = [];
|
|
469
|
+
if (metrics !== null && metrics !== void 0 && metrics.length) {
|
|
470
|
+
var _iterator4 = _createForOfIteratorHelper(metrics),
|
|
471
|
+
_step4;
|
|
472
|
+
try {
|
|
473
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
474
|
+
var _m$formatter;
|
|
475
|
+
var m = _step4.value;
|
|
476
|
+
var _value2 = Number(item.original[m.key]);
|
|
477
|
+
if (!Number.isFinite(_value2)) continue;
|
|
478
|
+
rows.push({
|
|
479
|
+
format: (_m$formatter = m.formatter) !== null && _m$formatter !== void 0 ? _m$formatter : defaultBenchmarkValueFormatter,
|
|
480
|
+
name: m.label,
|
|
481
|
+
value: _value2
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
} catch (err) {
|
|
485
|
+
_iterator4.e(err);
|
|
486
|
+
} finally {
|
|
487
|
+
_iterator4.f();
|
|
488
|
+
}
|
|
489
|
+
} else {
|
|
490
|
+
rows.push({
|
|
491
|
+
format: activeMetric.formatter,
|
|
492
|
+
name: activeMetric.label,
|
|
493
|
+
value: point.x
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
rows.reverse();
|
|
497
|
+
rows.push({
|
|
498
|
+
format: function format(v) {
|
|
499
|
+
return showError && item.error !== undefined ? "".concat(yFormatter(v), " \xB1 ").concat(errorFormatter(item.error)) : yFormatter(v);
|
|
500
|
+
},
|
|
501
|
+
name: yName,
|
|
502
|
+
value: point.y
|
|
503
|
+
});
|
|
504
|
+
var formatters = new Map(rows.map(function (row) {
|
|
505
|
+
return [row.name, row.format];
|
|
506
|
+
}));
|
|
507
|
+
var modelName = toLabelText(item.name);
|
|
508
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
509
|
+
arrow: false,
|
|
510
|
+
mouseEnterDelay: 0.05,
|
|
511
|
+
mouseLeaveDelay: 0,
|
|
512
|
+
styles: {
|
|
513
|
+
container: {
|
|
514
|
+
background: 'transparent',
|
|
515
|
+
boxShadow: 'none',
|
|
516
|
+
maxWidth: 'none',
|
|
517
|
+
padding: 0,
|
|
518
|
+
pointerEvents: 'none',
|
|
519
|
+
width: 'max-content'
|
|
520
|
+
},
|
|
521
|
+
root: {
|
|
522
|
+
maxWidth: 'none',
|
|
523
|
+
pointerEvents: 'none'
|
|
524
|
+
}
|
|
525
|
+
},
|
|
526
|
+
title: /*#__PURE__*/_jsx(ChartTooltip, {
|
|
527
|
+
active: true,
|
|
528
|
+
categoryColors: new Map(rows.map(function (row) {
|
|
529
|
+
return [row.name, point.color];
|
|
530
|
+
})),
|
|
531
|
+
label: item.provider ? "".concat(modelName, " \xB7 ").concat(String(item.provider)) : modelName,
|
|
532
|
+
payload: rows.map(function (row) {
|
|
533
|
+
return {
|
|
534
|
+
dataKey: row.name,
|
|
535
|
+
name: row.name,
|
|
536
|
+
value: row.value
|
|
537
|
+
};
|
|
538
|
+
}),
|
|
539
|
+
valueFormatter: function valueFormatter(value, name) {
|
|
540
|
+
var _formatters$get;
|
|
541
|
+
return ((_formatters$get = formatters.get(name !== null && name !== void 0 ? name : '')) !== null && _formatters$get !== void 0 ? _formatters$get : String)(Number(value));
|
|
542
|
+
}
|
|
543
|
+
}),
|
|
544
|
+
children: child
|
|
545
|
+
});
|
|
546
|
+
};
|
|
547
|
+
var renderMarker = function renderMarker(point, markerSizePx) {
|
|
548
|
+
var ring = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
549
|
+
return point.item.icon ? /*#__PURE__*/_jsx("span", {
|
|
550
|
+
className: ring ? styles.markerIconRing : undefined,
|
|
551
|
+
style: {
|
|
552
|
+
alignItems: 'center',
|
|
553
|
+
display: 'flex',
|
|
554
|
+
flexShrink: 0,
|
|
555
|
+
height: iconSize,
|
|
556
|
+
justifyContent: 'center',
|
|
557
|
+
transform: markerSizePx === iconSize ? undefined : "scale(".concat(markerSizePx / iconSize, ")"),
|
|
558
|
+
width: iconSize
|
|
559
|
+
},
|
|
560
|
+
children: point.item.icon
|
|
561
|
+
}) : renderShape(point.item.original.shape, point.color, markerSizePx, ring);
|
|
562
|
+
};
|
|
563
|
+
var hasMetricSwitch = ((_metrics$length = metrics === null || metrics === void 0 ? void 0 : metrics.length) !== null && _metrics$length !== void 0 ? _metrics$length : 0) > 1;
|
|
564
|
+
return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
|
|
565
|
+
className: cx(styles.container, className),
|
|
566
|
+
ref: ref,
|
|
567
|
+
style: _objectSpread({
|
|
568
|
+
'--benchmark-label-font-size': "".concat(labelFontSize, "px"),
|
|
569
|
+
'--benchmark-value-label-font-size': "".concat(valueLabelFontSize, "px"),
|
|
570
|
+
'width': width
|
|
571
|
+
}, style)
|
|
572
|
+
}, rest), {}, {
|
|
573
|
+
children: [showLegend && points.length > 0 || hasMetricSwitch ? /*#__PURE__*/_jsxs("div", {
|
|
574
|
+
className: styles.header,
|
|
575
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
576
|
+
className: styles.legend,
|
|
577
|
+
children: showLegend ? points.map(function (point) {
|
|
578
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
579
|
+
className: styles.legendItem,
|
|
580
|
+
onClick: function onClick() {
|
|
581
|
+
return handleClick(point.item);
|
|
582
|
+
},
|
|
583
|
+
onMouseEnter: function onMouseEnter() {
|
|
584
|
+
return setHoverKey(point.key);
|
|
585
|
+
},
|
|
586
|
+
onMouseLeave: function onMouseLeave() {
|
|
587
|
+
return setHoverKey(undefined);
|
|
588
|
+
},
|
|
589
|
+
style: {
|
|
590
|
+
color: point.item.highlighted ? resolvedHighlightColor : undefined,
|
|
591
|
+
cursor: onValueChange ? 'pointer' : undefined,
|
|
592
|
+
opacity: isDimmed(point.key) ? 0.4 : 1
|
|
593
|
+
},
|
|
594
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
595
|
+
className: styles.legendMarker,
|
|
596
|
+
children: renderMarker(point, 12)
|
|
597
|
+
}), toLabelText(point.item.name)]
|
|
598
|
+
}, "legend-".concat(point.key));
|
|
599
|
+
}) : null
|
|
600
|
+
}), hasMetricSwitch ? /*#__PURE__*/_jsx(Segmented, {
|
|
601
|
+
onChange: function onChange(value) {
|
|
602
|
+
return handleMetricChange(String(value));
|
|
603
|
+
},
|
|
604
|
+
options: metrics.map(function (m) {
|
|
605
|
+
return {
|
|
606
|
+
label: m.label,
|
|
607
|
+
value: m.key
|
|
608
|
+
};
|
|
609
|
+
}),
|
|
610
|
+
size: "small",
|
|
611
|
+
value: activeMetric.key
|
|
612
|
+
}) : null]
|
|
613
|
+
}) : null, /*#__PURE__*/_jsxs("div", {
|
|
614
|
+
className: styles.plot,
|
|
615
|
+
ref: plotRef,
|
|
616
|
+
style: {
|
|
617
|
+
height: plotHeight
|
|
618
|
+
},
|
|
619
|
+
children: [!points.length ? /*#__PURE__*/_jsx(NoData, {
|
|
620
|
+
noDataText: noDataText
|
|
621
|
+
}) : null, layout ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
622
|
+
children: [/*#__PURE__*/_jsxs("svg", {
|
|
623
|
+
height: plotHeight,
|
|
624
|
+
role: "img",
|
|
625
|
+
style: {
|
|
626
|
+
display: 'block',
|
|
627
|
+
overflow: 'visible'
|
|
628
|
+
},
|
|
629
|
+
width: plotWidth,
|
|
630
|
+
children: [showGridLines ? /*#__PURE__*/_jsxs("g", {
|
|
631
|
+
children: [layout.yScale.ticks.map(function (tick) {
|
|
632
|
+
var y = layout.yScale.map(tick);
|
|
633
|
+
return /*#__PURE__*/_jsx("line", {
|
|
634
|
+
className: styles.gridLine,
|
|
635
|
+
x1: layout.left,
|
|
636
|
+
x2: layout.innerRight,
|
|
637
|
+
y1: y,
|
|
638
|
+
y2: y
|
|
639
|
+
}, "gy-".concat(tick));
|
|
640
|
+
}), layout.xScale.ticks.map(function (tick) {
|
|
641
|
+
var x = layout.xScale.map(tick);
|
|
642
|
+
return /*#__PURE__*/_jsx("line", {
|
|
643
|
+
className: styles.gridLine,
|
|
644
|
+
x1: x,
|
|
645
|
+
x2: x,
|
|
646
|
+
y1: MARGIN_TOP,
|
|
647
|
+
y2: layout.innerBottom
|
|
648
|
+
}, "gx-".concat(tick));
|
|
649
|
+
})]
|
|
650
|
+
}) : null, showYAxis ? /*#__PURE__*/_jsx("g", {
|
|
651
|
+
children: layout.yScale.ticks.map(function (tick) {
|
|
652
|
+
return /*#__PURE__*/_jsx("text", {
|
|
653
|
+
className: styles.tickLabel,
|
|
654
|
+
dominantBaseline: "middle",
|
|
655
|
+
textAnchor: "end",
|
|
656
|
+
x: layout.left - TICK_GAP,
|
|
657
|
+
y: layout.yScale.map(tick),
|
|
658
|
+
children: yFormatter(tick)
|
|
659
|
+
}, "ty-".concat(tick));
|
|
660
|
+
})
|
|
661
|
+
}) : null, showXAxis ? /*#__PURE__*/_jsxs("g", {
|
|
662
|
+
children: [/*#__PURE__*/_jsx("line", {
|
|
663
|
+
className: styles.axisLine,
|
|
664
|
+
x1: layout.left,
|
|
665
|
+
x2: layout.innerRight,
|
|
666
|
+
y1: layout.innerBottom,
|
|
667
|
+
y2: layout.innerBottom
|
|
668
|
+
}), layout.xScale.ticks.map(function (tick) {
|
|
669
|
+
return /*#__PURE__*/_jsx("text", {
|
|
670
|
+
className: styles.tickLabel,
|
|
671
|
+
dominantBaseline: "hanging",
|
|
672
|
+
textAnchor: "middle",
|
|
673
|
+
x: layout.xScale.map(tick),
|
|
674
|
+
y: layout.innerBottom + TICK_GAP,
|
|
675
|
+
children: activeMetric.formatter(tick)
|
|
676
|
+
}, "tx-".concat(tick));
|
|
677
|
+
})]
|
|
678
|
+
}) : null, yAxisLabel ? /*#__PURE__*/_jsx("text", {
|
|
679
|
+
className: styles.axisLabel,
|
|
680
|
+
dominantBaseline: "hanging",
|
|
681
|
+
textAnchor: "middle",
|
|
682
|
+
transform: "rotate(-90, 0, ".concat((MARGIN_TOP + layout.innerBottom) / 2, ")"),
|
|
683
|
+
x: 0,
|
|
684
|
+
y: (MARGIN_TOP + layout.innerBottom) / 2,
|
|
685
|
+
children: yAxisLabel
|
|
686
|
+
}) : null, activeMetric.axisLabel ? /*#__PURE__*/_jsx("text", {
|
|
687
|
+
className: styles.axisLabel,
|
|
688
|
+
dominantBaseline: "auto",
|
|
689
|
+
textAnchor: "middle",
|
|
690
|
+
x: (layout.left + layout.innerRight) / 2,
|
|
691
|
+
y: plotHeight - 4,
|
|
692
|
+
children: activeMetric.axisLabel
|
|
693
|
+
}) : null, showDominatedArea && focusPoint ? function () {
|
|
694
|
+
var pos = layout.positions.get(focusPoint.key);
|
|
695
|
+
var toRight = activeMetric.direction === 'lower';
|
|
696
|
+
var x0 = toRight ? pos.px : layout.left;
|
|
697
|
+
var x1 = toRight ? layout.innerRight : pos.px;
|
|
698
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
699
|
+
className: styles.dominatedArea,
|
|
700
|
+
"data-testid": "benchmark-scatter-dominated-area",
|
|
701
|
+
children: [/*#__PURE__*/_jsx("rect", {
|
|
702
|
+
fill: resolvedFrontierColor,
|
|
703
|
+
fillOpacity: 0.08,
|
|
704
|
+
height: Math.max(0, layout.innerBottom - pos.py),
|
|
705
|
+
width: Math.max(0, x1 - x0),
|
|
706
|
+
x: x0,
|
|
707
|
+
y: pos.py
|
|
708
|
+
}), /*#__PURE__*/_jsx("line", {
|
|
709
|
+
className: styles.dominatedGuide,
|
|
710
|
+
x1: x0,
|
|
711
|
+
x2: x1,
|
|
712
|
+
y1: pos.py,
|
|
713
|
+
y2: pos.py
|
|
714
|
+
}), /*#__PURE__*/_jsx("line", {
|
|
715
|
+
className: styles.dominatedGuide,
|
|
716
|
+
x1: pos.px,
|
|
717
|
+
x2: pos.px,
|
|
718
|
+
y1: pos.py,
|
|
719
|
+
y2: layout.innerBottom
|
|
720
|
+
})]
|
|
721
|
+
});
|
|
722
|
+
}() : null, enableErrorBars ? points.map(function (point) {
|
|
723
|
+
var error = point.item.error;
|
|
724
|
+
if (!error) return null;
|
|
725
|
+
var pos = layout.positions.get(point.key);
|
|
726
|
+
var top = layout.yScale.map(point.y + error);
|
|
727
|
+
var bottom = layout.yScale.map(point.y - error);
|
|
728
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
729
|
+
className: styles.errorBar,
|
|
730
|
+
"data-testid": "benchmark-scatter-error-bar",
|
|
731
|
+
opacity: isDimmed(point.key) ? 0.25 : 0.7,
|
|
732
|
+
stroke: point.color,
|
|
733
|
+
children: [/*#__PURE__*/_jsx("line", {
|
|
734
|
+
x1: pos.px,
|
|
735
|
+
x2: pos.px,
|
|
736
|
+
y1: top,
|
|
737
|
+
y2: bottom
|
|
738
|
+
}), /*#__PURE__*/_jsx("line", {
|
|
739
|
+
x1: pos.px - 4,
|
|
740
|
+
x2: pos.px + 4,
|
|
741
|
+
y1: top,
|
|
742
|
+
y2: top
|
|
743
|
+
}), /*#__PURE__*/_jsx("line", {
|
|
744
|
+
x1: pos.px - 4,
|
|
745
|
+
x2: pos.px + 4,
|
|
746
|
+
y1: bottom,
|
|
747
|
+
y2: bottom
|
|
748
|
+
})]
|
|
749
|
+
}, "err-".concat(point.key));
|
|
750
|
+
}) : null, layout.frontierPath ? /*#__PURE__*/_jsx("path", {
|
|
751
|
+
className: styles.frontier,
|
|
752
|
+
d: layout.frontierPath,
|
|
753
|
+
"data-testid": "benchmark-scatter-frontier",
|
|
754
|
+
opacity: !showDominatedArea && focusKey !== undefined && !frontierKeys.has(focusKey) ? 0.35 : 1,
|
|
755
|
+
stroke: resolvedFrontierColor,
|
|
756
|
+
strokeWidth: frontierWidth,
|
|
757
|
+
style: showAnimation ? {
|
|
758
|
+
transition: "d 0.4s, opacity 0.2s"
|
|
759
|
+
} : undefined
|
|
760
|
+
}) : null]
|
|
761
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
762
|
+
className: styles.overlay,
|
|
763
|
+
children: [points.map(function (point) {
|
|
764
|
+
var pos = layout.positions.get(point.key);
|
|
765
|
+
var markerPx = point.item.icon ? iconSize : markerSize;
|
|
766
|
+
return /*#__PURE__*/_jsx("div", {
|
|
767
|
+
children: renderTooltip(point, /*#__PURE__*/_jsx("div", {
|
|
768
|
+
"aria-label": "".concat(toLabelText(point.item.name), ": ").concat(yFormatter(point.y), ", ").concat(activeMetric.formatter(point.x)),
|
|
769
|
+
className: cx(styles.marker, animatedCls),
|
|
770
|
+
onClick: function onClick() {
|
|
771
|
+
return handleClick(point.item);
|
|
772
|
+
},
|
|
773
|
+
onMouseEnter: function onMouseEnter() {
|
|
774
|
+
return setHoverKey(point.key);
|
|
775
|
+
},
|
|
776
|
+
onMouseLeave: function onMouseLeave() {
|
|
777
|
+
return setHoverKey(undefined);
|
|
778
|
+
},
|
|
779
|
+
role: "button",
|
|
780
|
+
style: {
|
|
781
|
+
cursor: onValueChange ? 'pointer' : 'default',
|
|
782
|
+
filter: getEmphasis(point.key) === 'dominated' ? 'grayscale(1)' : undefined,
|
|
783
|
+
height: markerPx,
|
|
784
|
+
left: pos.px,
|
|
785
|
+
opacity: {
|
|
786
|
+
dimmed: 0.25,
|
|
787
|
+
dominated: 0.5,
|
|
788
|
+
normal: 1
|
|
789
|
+
}[getEmphasis(point.key)],
|
|
790
|
+
top: pos.py,
|
|
791
|
+
width: markerPx
|
|
792
|
+
},
|
|
793
|
+
children: renderMarker(point, markerPx, true)
|
|
794
|
+
}))
|
|
795
|
+
}, "marker-".concat(point.key));
|
|
796
|
+
}), showLabels ? points.map(function (point) {
|
|
797
|
+
var label = layout.labels.get(point.key);
|
|
798
|
+
if (!label) return null;
|
|
799
|
+
var emphasis = getEmphasis(point.key);
|
|
800
|
+
var textColor = emphasis === 'dominated' ? cssVar.colorTextQuaternary : point.item.highlighted ? resolvedHighlightColor : undefined;
|
|
801
|
+
var isKeyLabel = emphasis !== 'dominated' && (frontierKeys.has(point.key) || point.item.highlighted || point.key === focusKey);
|
|
802
|
+
var align = label.placement.endsWith('left') ? 'right' : label.placement === 'top' || label.placement === 'bottom' ? 'center' : 'left';
|
|
803
|
+
var name = toLabelText(point.item.name);
|
|
804
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
805
|
+
className: cx(styles.label, animatedCls),
|
|
806
|
+
onClick: function onClick() {
|
|
807
|
+
return handleClick(point.item);
|
|
808
|
+
},
|
|
809
|
+
onMouseEnter: function onMouseEnter() {
|
|
810
|
+
return setHoverKey(point.key);
|
|
811
|
+
},
|
|
812
|
+
onMouseLeave: function onMouseLeave() {
|
|
813
|
+
return setHoverKey(undefined);
|
|
814
|
+
},
|
|
815
|
+
style: {
|
|
816
|
+
cursor: onValueChange ? 'pointer' : 'default',
|
|
817
|
+
height: label.height,
|
|
818
|
+
left: label.x,
|
|
819
|
+
opacity: emphasis === 'dimmed' ? 0.25 : 1,
|
|
820
|
+
textAlign: align,
|
|
821
|
+
top: label.y,
|
|
822
|
+
width: label.width
|
|
823
|
+
},
|
|
824
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
825
|
+
className: cx(styles.labelName, isKeyLabel && styles.labelNameEmphasis),
|
|
826
|
+
style: textColor ? {
|
|
827
|
+
color: textColor
|
|
828
|
+
} : undefined,
|
|
829
|
+
children: point.item.href ? /*#__PURE__*/_jsx(A, {
|
|
830
|
+
className: styles.labelNameLink,
|
|
831
|
+
href: point.item.href,
|
|
832
|
+
onClick: function onClick(event) {
|
|
833
|
+
return event.stopPropagation();
|
|
834
|
+
},
|
|
835
|
+
target: point.item.target,
|
|
836
|
+
children: name
|
|
837
|
+
}) : name
|
|
838
|
+
}), showValueLabel ? /*#__PURE__*/_jsxs("div", {
|
|
839
|
+
className: styles.labelValue,
|
|
840
|
+
children: [yFormatter(point.y), " \xB7 ", activeMetric.formatter(point.x)]
|
|
841
|
+
}) : null]
|
|
842
|
+
}, "label-".concat(point.key));
|
|
843
|
+
}) : null]
|
|
844
|
+
})]
|
|
845
|
+
}) : null]
|
|
846
|
+
})]
|
|
847
|
+
}));
|
|
848
|
+
});
|
|
849
|
+
BenchmarkScatterChart.displayName = 'BenchmarkScatterChart';
|
|
850
|
+
export default BenchmarkScatterChart;
|