@lobehub/charts 5.3.1 → 5.5.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.mdx +52 -0
- package/es/AreaChart/index.mdx +49 -0
- package/es/BarChart/index.mdx +73 -0
- package/es/BarList/index.mdx +34 -0
- package/es/BenchmarkColumnChart/index.d.ts +140 -0
- package/es/BenchmarkColumnChart/index.js +686 -0
- package/es/BenchmarkColumnChart/index.mdx +66 -0
- package/es/BenchmarkColumnChart/styles.d.ts +16 -0
- package/es/BenchmarkColumnChart/styles.js +23 -0
- package/es/BenchmarkRankingChart/index.d.ts +87 -0
- package/es/BenchmarkRankingChart/index.js +448 -0
- package/es/BenchmarkRankingChart/index.mdx +59 -0
- package/es/BenchmarkRankingChart/styles.d.ts +33 -0
- package/es/BenchmarkRankingChart/styles.js +41 -0
- package/es/ComposedChart/index.mdx +43 -0
- package/es/DataBars/index.mdx +36 -0
- package/es/DonutChart/index.mdx +48 -0
- package/es/FunnelChart/index.mdx +21 -0
- package/es/Heatmaps/index.mdx +70 -0
- package/es/Legend/index.mdx +13 -0
- package/es/LineChart/index.mdx +49 -0
- package/es/RadarChart/index.mdx +52 -0
- package/es/ScatterChart/index.mdx +49 -0
- package/es/SparkChart/index.mdx +29 -0
- package/es/Tracker/index.mdx +41 -0
- package/es/common/ChartTooltip/ChartTooltipFrame.js +1 -1
- package/es/common/ChartTooltip/ChartTooltipRow.js +3 -1
- package/es/common/ChartTooltip/index.js +2 -0
- package/es/common/benchmark/index.d.ts +2 -0
- package/es/common/benchmark/index.js +1 -0
- package/es/common/benchmark/types.d.ts +117 -0
- package/es/common/benchmark/types.js +1 -0
- package/es/common/benchmark/utils.d.ts +56 -0
- package/es/common/benchmark/utils.js +159 -0
- package/es/index.d.ts +3 -0
- package/es/index.js +2 -0
- package/package.json +1 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: BenchmarkColumnChart
|
|
3
|
+
description: Vertical column chart for model benchmark comparisons with injectable brand icons and rotated labels.
|
|
4
|
+
category: Benchmark
|
|
5
|
+
order: 3
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
import DemoIndex from './demos/index.tsx?demo';
|
|
9
|
+
import DemoAccuracy from './demos/accuracy.tsx?demo';
|
|
10
|
+
import DemoLine from './demos/line.tsx?demo';
|
|
11
|
+
import DemoHighlighted from './demos/highlighted.tsx?demo';
|
|
12
|
+
|
|
13
|
+
<Demo of={DemoIndex} layout="bare" />
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Icons and brand colors are provided by the consumer. `@lobehub/icons` is only used in docs demos and is not a runtime dependency of `@lobehub/charts`.
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { BenchmarkColumnChart } from '@lobehub/charts';
|
|
21
|
+
import { Claude, OpenAI } from '@lobehub/icons';
|
|
22
|
+
|
|
23
|
+
export default () => (
|
|
24
|
+
<BenchmarkColumnChart
|
|
25
|
+
data={[
|
|
26
|
+
{
|
|
27
|
+
color: Claude.colorPrimary,
|
|
28
|
+
icon: <Claude.Avatar size={20} />,
|
|
29
|
+
name: 'Claude Fable 5.1\n(max with fallback)',
|
|
30
|
+
provider: 'Anthropic',
|
|
31
|
+
score: 57,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
color: OpenAI.colorPrimary,
|
|
35
|
+
icon: <OpenAI.Avatar size={20} />,
|
|
36
|
+
name: 'GPT-6 Astra\n(max)',
|
|
37
|
+
provider: 'OpenAI',
|
|
38
|
+
score: 55,
|
|
39
|
+
},
|
|
40
|
+
]}
|
|
41
|
+
height={360}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Accuracy with error bars
|
|
47
|
+
|
|
48
|
+
Use `accuracyFormatter`, `error`, and `showErrorBars` for AccuracyBar-style percentage and ± uncertainty display.
|
|
49
|
+
|
|
50
|
+
<Demo of={DemoAccuracy} />
|
|
51
|
+
|
|
52
|
+
## Line overlay + unranked
|
|
53
|
+
|
|
54
|
+
Pass a secondary `line` value to draw an overlay series (e.g. Pass¹). Mark items with `unranked: true` to place them after a dashed separator — the line does not connect into unranked points. Override color with `lineColor` (defaults to `theme.gold`). Pass `false` or `''` for `barName` / `lineName` / `unrankedLabel` to hide that header item.
|
|
55
|
+
|
|
56
|
+
<Demo of={DemoLine} />
|
|
57
|
+
|
|
58
|
+
## Highlighted items
|
|
59
|
+
|
|
60
|
+
Set `highlighted: true` on a record to accent its axis label / rank with `highlightColor` (defaults to `theme.gold`). Bar fill colors are unchanged.
|
|
61
|
+
|
|
62
|
+
<Demo of={DemoHighlighted} />
|
|
63
|
+
|
|
64
|
+
## API
|
|
65
|
+
|
|
66
|
+
<Api name="BenchmarkColumnChart" />
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const styles: {
|
|
2
|
+
chartHeader: string;
|
|
3
|
+
container: string;
|
|
4
|
+
gridLines: string;
|
|
5
|
+
iconWrap: string;
|
|
6
|
+
label: string;
|
|
7
|
+
legend: string;
|
|
8
|
+
legendBars: string;
|
|
9
|
+
legendItem: string;
|
|
10
|
+
legendLine: string;
|
|
11
|
+
lineLabel: string;
|
|
12
|
+
rank: string;
|
|
13
|
+
tickLabel: string;
|
|
14
|
+
unrankedLabel: string;
|
|
15
|
+
valueLabel: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14;
|
|
2
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
|
+
import { createStaticStyles } from 'antd-style';
|
|
4
|
+
export var styles = createStaticStyles(function (_ref) {
|
|
5
|
+
var css = _ref.css,
|
|
6
|
+
cssVar = _ref.cssVar;
|
|
7
|
+
return {
|
|
8
|
+
chartHeader: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n pointer-events: none;\n\n position: absolute;\n z-index: 2;\n top: 8px;\n right: 0;\n left: 0;\n\n display: flex;\n gap: 16px;\n align-items: flex-start;\n justify-content: space-between;\n\n padding-inline: var(--benchmark-header-pad-inline, 48px);\n "]))),
|
|
9
|
+
container: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n overflow: auto visible;\n\n .recharts-wrapper,\n .recharts-surface {\n overflow: visible;\n }\n\n /* stylelint-disable-next-line selector-class-pattern -- recharts internal class */\n .recharts-errorBar {\n mix-blend-mode: difference;\n }\n "]))),
|
|
10
|
+
gridLines: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n stroke: ", ";\n stroke-dasharray: 4 4;\n stroke-width: 1;\n "])), cssVar.colorBorderSecondary),
|
|
11
|
+
iconWrap: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n overflow: visible;\n display: flex;\n align-items: center;\n justify-content: center;\n\n width: 100%;\n height: 100%;\n "]))),
|
|
12
|
+
label: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n font-size: 12px;\n line-height: 16px;\n fill: ", ";\n "])), cssVar.colorTextDescription),
|
|
13
|
+
legend: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n display: flex;\n flex-flow: column nowrap;\n gap: 6px;\n align-items: flex-start;\n\n min-width: 0;\n\n font-size: 12px;\n line-height: 16px;\n color: ", ";\n "])), cssVar.colorTextSecondary),
|
|
14
|
+
legendBars: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n display: inline-block;\n width: 14px;\n height: 10px;\n border-radius: 2px;\n "]))),
|
|
15
|
+
legendItem: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n display: inline-flex;\n gap: 6px;\n align-items: center;\n "]))),
|
|
16
|
+
legendLine: css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n display: inline-block;\n width: 16px;\n height: 0;\n border-top: 2px solid ", ";\n "])), cssVar.colorTextSecondary),
|
|
17
|
+
lineLabel: css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n pointer-events: none;\n font-family: 'Geist Mono', SFMono-Regular, Consolas, 'Liberation Mono', monospace;\n font-weight: 500;\n "]))),
|
|
18
|
+
rank: css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n justify-content: center;\n\n width: 100%;\n height: 100%;\n\n font-family: 'Geist Mono', SFMono-Regular, Consolas, 'Liberation Mono', monospace;\n font-size: 14px;\n font-variant-numeric: tabular-nums;\n line-height: 1.3;\n color: ", ";\n text-align: left;\n\n fill: ", ";\n "])), cssVar.colorTextQuaternary, cssVar.colorTextQuaternary),
|
|
19
|
+
tickLabel: css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n font-size: var(--benchmark-label-font-size, 11px);\n line-height: 1.25;\n fill: ", ";\n "])), cssVar.colorTextSecondary),
|
|
20
|
+
unrankedLabel: css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n flex-shrink: 0;\n\n max-width: 42%;\n\n font-size: 12px;\n line-height: 16px;\n color: ", ";\n text-align: right;\n "])), cssVar.colorTextDescription),
|
|
21
|
+
valueLabel: css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n pointer-events: none;\n font-family: 'Geist Mono', SFMono-Regular, Consolas, 'Liberation Mono', monospace;\n font-size: var(--benchmark-value-label-font-size, 12px);\n font-weight: 600;\n "])))
|
|
22
|
+
};
|
|
23
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type BenchmarkBaseProps, type NormalizedBenchmarkItem } from "../common/benchmark";
|
|
3
|
+
export interface BenchmarkRankingChartProps extends BenchmarkBaseProps {
|
|
4
|
+
/**
|
|
5
|
+
* Thickness of the horizontal score bar
|
|
6
|
+
* @default 24
|
|
7
|
+
*/
|
|
8
|
+
barSize?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Fallback bar color when an item has no color
|
|
11
|
+
*/
|
|
12
|
+
color?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Text accent color when an item has `highlighted: true` (does not change bar fill)
|
|
15
|
+
* @default theme.gold
|
|
16
|
+
*/
|
|
17
|
+
highlightColor?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Font size for the model name
|
|
20
|
+
* @default 14
|
|
21
|
+
*/
|
|
22
|
+
labelFontSize?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Display width of the left label (icon + name + provider).
|
|
25
|
+
* Omit to size to the longest label.
|
|
26
|
+
*/
|
|
27
|
+
labelWidth?: number | string;
|
|
28
|
+
/**
|
|
29
|
+
* Override domain max used for bar scaling
|
|
30
|
+
*/
|
|
31
|
+
maxValue?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Custom rank renderer. Receives the normalized item; default is `#${rank}`.
|
|
34
|
+
*/
|
|
35
|
+
renderRank?: (item: NormalizedBenchmarkItem) => ReactNode;
|
|
36
|
+
/**
|
|
37
|
+
* Height of each ranking row
|
|
38
|
+
* @default 40
|
|
39
|
+
*/
|
|
40
|
+
rowHeight?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Show AccuracyBar-style horizontal error bars
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
showErrorBars?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Show vertical grid lines in the plot
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
showGridLines?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Show rank on the left (default `#1`, `#2`, ...)
|
|
53
|
+
* @default true
|
|
54
|
+
*/
|
|
55
|
+
showRank?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Show tooltip on row hover
|
|
58
|
+
* @default true
|
|
59
|
+
*/
|
|
60
|
+
showTooltip?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Show numeric score labels on the right
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
showValueLabel?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Show X value axis line + ticks under the bars
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
showXAxis?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Show Y axis line along the plot
|
|
73
|
+
* @default true
|
|
74
|
+
*/
|
|
75
|
+
showYAxis?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Font size for the numeric score
|
|
78
|
+
* @default 14
|
|
79
|
+
*/
|
|
80
|
+
valueLabelFontSize?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Optional X axis title under the ticks
|
|
83
|
+
*/
|
|
84
|
+
xAxisLabel?: string;
|
|
85
|
+
}
|
|
86
|
+
declare const BenchmarkRankingChart: import("react").ForwardRefExoticComponent<BenchmarkRankingChartProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
87
|
+
export default BenchmarkRankingChart;
|
|
@@ -0,0 +1,448 @@
|
|
|
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", "color", "highlightColor", "valueFormatter", "accuracyFormatter", "errorFormatter", "showError", "showErrorBars", "showAnimation", "onValueChange", "sortOrder", "className", "style", "loading", "width", "height", "noDataText", "barSize", "rowHeight", "labelWidth", "labelFontSize", "valueLabelFontSize", "maxValue", "renderRank", "showRank", "showValueLabel", "showTooltip", "showGridLines", "showXAxis", "showYAxis", "xAxisLabel"];
|
|
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
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."); }
|
|
12
|
+
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; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
17
|
+
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."); }
|
|
18
|
+
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); }
|
|
19
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
20
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
21
|
+
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; }
|
|
22
|
+
import { A, Flexbox, Skeleton } from '@lobehub/ui';
|
|
23
|
+
import { Tooltip } from 'antd';
|
|
24
|
+
import { cssVar, cx, useTheme } from 'antd-style';
|
|
25
|
+
import { forwardRef, useMemo, useState } from 'react';
|
|
26
|
+
import ChartTooltip from "../common/ChartTooltip";
|
|
27
|
+
import NoData from "../common/NoData";
|
|
28
|
+
import { defaultBenchmarkErrorFormatter, defaultBenchmarkValueFormatter, formatBenchmarkAccuracyDisplay, getBenchmarkBarPercent, normalizeBenchmarkData } from "../common/benchmark";
|
|
29
|
+
import { styles } from "./styles";
|
|
30
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
31
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
32
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
33
|
+
var prefixCls = 'ant';
|
|
34
|
+
var getAxisTicks = function getAxisTicks(max) {
|
|
35
|
+
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4;
|
|
36
|
+
if (max <= 0) return [0];
|
|
37
|
+
var raw = max / count;
|
|
38
|
+
var magnitude = Math.pow(10, Math.floor(Math.log10(raw)));
|
|
39
|
+
var normalized = raw / magnitude;
|
|
40
|
+
var stepBase = normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10;
|
|
41
|
+
var step = stepBase * magnitude;
|
|
42
|
+
var ticks = [];
|
|
43
|
+
for (var value = 0; value <= max + step / 1000; value += step) {
|
|
44
|
+
ticks.push(Math.min(Number(value.toFixed(6)), max));
|
|
45
|
+
}
|
|
46
|
+
if (ticks.at(-1) !== max) ticks.push(max);
|
|
47
|
+
return _toConsumableArray(new Set(ticks));
|
|
48
|
+
};
|
|
49
|
+
var BenchmarkRankingChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
50
|
+
var theme = useTheme();
|
|
51
|
+
var _props$data = props.data,
|
|
52
|
+
data = _props$data === void 0 ? [] : _props$data,
|
|
53
|
+
index = props.index,
|
|
54
|
+
valueKey = props.valueKey,
|
|
55
|
+
providerKey = props.providerKey,
|
|
56
|
+
iconKey = props.iconKey,
|
|
57
|
+
colorKey = props.colorKey,
|
|
58
|
+
errorKey = props.errorKey,
|
|
59
|
+
renderIcon = props.renderIcon,
|
|
60
|
+
_props$color = props.color,
|
|
61
|
+
color = _props$color === void 0 ? cssVar.colorPrimary : _props$color,
|
|
62
|
+
highlightColor = props.highlightColor,
|
|
63
|
+
_props$valueFormatter = props.valueFormatter,
|
|
64
|
+
valueFormatter = _props$valueFormatter === void 0 ? defaultBenchmarkValueFormatter : _props$valueFormatter,
|
|
65
|
+
accuracyFormatter = props.accuracyFormatter,
|
|
66
|
+
_props$errorFormatter = props.errorFormatter,
|
|
67
|
+
errorFormatter = _props$errorFormatter === void 0 ? defaultBenchmarkErrorFormatter : _props$errorFormatter,
|
|
68
|
+
_props$showError = props.showError,
|
|
69
|
+
showError = _props$showError === void 0 ? true : _props$showError,
|
|
70
|
+
_props$showErrorBars = props.showErrorBars,
|
|
71
|
+
showErrorBars = _props$showErrorBars === void 0 ? true : _props$showErrorBars,
|
|
72
|
+
_props$showAnimation = props.showAnimation,
|
|
73
|
+
showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
|
|
74
|
+
onValueChange = props.onValueChange,
|
|
75
|
+
_props$sortOrder = props.sortOrder,
|
|
76
|
+
sortOrder = _props$sortOrder === void 0 ? 'descending' : _props$sortOrder,
|
|
77
|
+
className = props.className,
|
|
78
|
+
style = props.style,
|
|
79
|
+
loading = props.loading,
|
|
80
|
+
_props$width = props.width,
|
|
81
|
+
width = _props$width === void 0 ? '100%' : _props$width,
|
|
82
|
+
height = props.height,
|
|
83
|
+
noDataText = props.noDataText,
|
|
84
|
+
_props$barSize = props.barSize,
|
|
85
|
+
barSize = _props$barSize === void 0 ? 24 : _props$barSize,
|
|
86
|
+
_props$rowHeight = props.rowHeight,
|
|
87
|
+
rowHeight = _props$rowHeight === void 0 ? 40 : _props$rowHeight,
|
|
88
|
+
labelWidth = props.labelWidth,
|
|
89
|
+
_props$labelFontSize = props.labelFontSize,
|
|
90
|
+
labelFontSize = _props$labelFontSize === void 0 ? 14 : _props$labelFontSize,
|
|
91
|
+
_props$valueLabelFont = props.valueLabelFontSize,
|
|
92
|
+
valueLabelFontSize = _props$valueLabelFont === void 0 ? 14 : _props$valueLabelFont,
|
|
93
|
+
maxValue = props.maxValue,
|
|
94
|
+
renderRank = props.renderRank,
|
|
95
|
+
_props$showRank = props.showRank,
|
|
96
|
+
showRank = _props$showRank === void 0 ? true : _props$showRank,
|
|
97
|
+
_props$showValueLabel = props.showValueLabel,
|
|
98
|
+
showValueLabel = _props$showValueLabel === void 0 ? true : _props$showValueLabel,
|
|
99
|
+
_props$showTooltip = props.showTooltip,
|
|
100
|
+
showTooltip = _props$showTooltip === void 0 ? true : _props$showTooltip,
|
|
101
|
+
_props$showGridLines = props.showGridLines,
|
|
102
|
+
showGridLines = _props$showGridLines === void 0 ? true : _props$showGridLines,
|
|
103
|
+
_props$showXAxis = props.showXAxis,
|
|
104
|
+
showXAxis = _props$showXAxis === void 0 ? false : _props$showXAxis,
|
|
105
|
+
_props$showYAxis = props.showYAxis,
|
|
106
|
+
showYAxis = _props$showYAxis === void 0 ? true : _props$showYAxis,
|
|
107
|
+
xAxisLabel = props.xAxisLabel,
|
|
108
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
109
|
+
var resolvedHighlightColor = highlightColor !== null && highlightColor !== void 0 ? highlightColor : theme.gold;
|
|
110
|
+
var _useState = useState(),
|
|
111
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
112
|
+
activeKey = _useState2[0],
|
|
113
|
+
setActiveKey = _useState2[1];
|
|
114
|
+
var enableErrorBars = showError && showErrorBars;
|
|
115
|
+
var displayFormatter = accuracyFormatter !== null && accuracyFormatter !== void 0 ? accuracyFormatter : valueFormatter;
|
|
116
|
+
var items = useMemo(function () {
|
|
117
|
+
return normalizeBenchmarkData({
|
|
118
|
+
colorKey: colorKey,
|
|
119
|
+
data: data,
|
|
120
|
+
errorKey: errorKey,
|
|
121
|
+
iconKey: iconKey,
|
|
122
|
+
index: index,
|
|
123
|
+
providerKey: providerKey,
|
|
124
|
+
renderIcon: renderIcon,
|
|
125
|
+
sortOrder: sortOrder,
|
|
126
|
+
valueKey: valueKey
|
|
127
|
+
});
|
|
128
|
+
}, [colorKey, data, errorKey, iconKey, index, providerKey, renderIcon, sortOrder, valueKey]);
|
|
129
|
+
var resolvedMaxValue = useMemo(function () {
|
|
130
|
+
if (typeof maxValue === 'number') return maxValue;
|
|
131
|
+
return Math.max.apply(Math, _toConsumableArray(items.map(function (item) {
|
|
132
|
+
var _item$error;
|
|
133
|
+
return item.value + (enableErrorBars ? (_item$error = item.error) !== null && _item$error !== void 0 ? _item$error : 0 : 0);
|
|
134
|
+
})).concat([0]));
|
|
135
|
+
}, [enableErrorBars, items, maxValue]);
|
|
136
|
+
var axisTicks = useMemo(function () {
|
|
137
|
+
return getAxisTicks(resolvedMaxValue);
|
|
138
|
+
}, [resolvedMaxValue]);
|
|
139
|
+
var hasLabelWidth = labelWidth !== undefined && labelWidth !== null && labelWidth !== '';
|
|
140
|
+
var labelWidthStyle = typeof labelWidth === 'number' ? "".concat(labelWidth, "px") : labelWidth;
|
|
141
|
+
var gridTicks = axisTicks.filter(function (tick) {
|
|
142
|
+
return tick > 0 && tick < resolvedMaxValue;
|
|
143
|
+
});
|
|
144
|
+
if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Block, {
|
|
145
|
+
active: true,
|
|
146
|
+
height: height !== null && height !== void 0 ? height : 280,
|
|
147
|
+
width: width
|
|
148
|
+
});
|
|
149
|
+
var handleClick = function handleClick(item) {
|
|
150
|
+
if (!onValueChange) return;
|
|
151
|
+
if (activeKey === item.key) {
|
|
152
|
+
setActiveKey(undefined);
|
|
153
|
+
onValueChange(null);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
setActiveKey(item.key);
|
|
157
|
+
var payload = _objectSpread(_objectSpread({}, item.original), {}, {
|
|
158
|
+
eventType: 'row',
|
|
159
|
+
rank: item.rank,
|
|
160
|
+
value: item.value
|
|
161
|
+
});
|
|
162
|
+
onValueChange(payload);
|
|
163
|
+
};
|
|
164
|
+
var renderRowTooltip = function renderRowTooltip(item, child, key) {
|
|
165
|
+
var _item$color;
|
|
166
|
+
var fillTrigger = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
167
|
+
var trigger = /*#__PURE__*/_jsx("div", {
|
|
168
|
+
className: styles.tooltipTrigger,
|
|
169
|
+
style: fillTrigger ? undefined : {
|
|
170
|
+
minWidth: 'max-content',
|
|
171
|
+
width: 'auto'
|
|
172
|
+
},
|
|
173
|
+
children: child
|
|
174
|
+
});
|
|
175
|
+
if (!showTooltip) return /*#__PURE__*/_jsx("div", {
|
|
176
|
+
children: trigger
|
|
177
|
+
}, key);
|
|
178
|
+
var modelName = String(item.name).replaceAll('\n', ' ');
|
|
179
|
+
var metricName = accuracyFormatter ? 'Accuracy' : 'Score';
|
|
180
|
+
var title = item.provider ? String(item.provider) : metricName;
|
|
181
|
+
var swatch = (_item$color = item.color) !== null && _item$color !== void 0 ? _item$color : color;
|
|
182
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
183
|
+
arrow: false,
|
|
184
|
+
mouseEnterDelay: 0.05,
|
|
185
|
+
styles: {
|
|
186
|
+
container: {
|
|
187
|
+
background: 'transparent',
|
|
188
|
+
boxShadow: 'none',
|
|
189
|
+
maxWidth: 'none',
|
|
190
|
+
padding: 0,
|
|
191
|
+
width: 'max-content'
|
|
192
|
+
},
|
|
193
|
+
root: {
|
|
194
|
+
maxWidth: 'none'
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
title: /*#__PURE__*/_jsx(ChartTooltip, {
|
|
198
|
+
active: true,
|
|
199
|
+
categoryColors: new Map([[modelName, swatch]]),
|
|
200
|
+
label: title,
|
|
201
|
+
payload: [{
|
|
202
|
+
color: swatch,
|
|
203
|
+
dataKey: '__value',
|
|
204
|
+
name: modelName,
|
|
205
|
+
value: item.value
|
|
206
|
+
}],
|
|
207
|
+
valueFormatter: function valueFormatter(val) {
|
|
208
|
+
if (!showError || item.error === undefined || item.error === null) {
|
|
209
|
+
return displayFormatter(Number(val));
|
|
210
|
+
}
|
|
211
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
212
|
+
children: [displayFormatter(Number(val)), /*#__PURE__*/_jsxs("span", {
|
|
213
|
+
style: {
|
|
214
|
+
color: cssVar.colorTextSecondary
|
|
215
|
+
},
|
|
216
|
+
children: [' ', "\xB1 ", errorFormatter(Number(item.error))]
|
|
217
|
+
})]
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}),
|
|
221
|
+
children: trigger
|
|
222
|
+
}, key);
|
|
223
|
+
};
|
|
224
|
+
var toPercent = function toPercent(value) {
|
|
225
|
+
return resolvedMaxValue <= 0 ? 0 : Math.max(0, Math.min(100, value / resolvedMaxValue * 100));
|
|
226
|
+
};
|
|
227
|
+
return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
|
|
228
|
+
className: cx(styles.container, className),
|
|
229
|
+
gap: 0,
|
|
230
|
+
horizontal: true,
|
|
231
|
+
ref: ref,
|
|
232
|
+
style: _objectSpread({
|
|
233
|
+
'--benchmark-label-font-size': "".concat(labelFontSize, "px"),
|
|
234
|
+
'--benchmark-subtitle-font-size': "".concat(Math.max(10, labelFontSize - 2), "px"),
|
|
235
|
+
'--benchmark-value-label-font-size': "".concat(valueLabelFontSize, "px"),
|
|
236
|
+
'minHeight': height,
|
|
237
|
+
'position': 'relative'
|
|
238
|
+
}, style),
|
|
239
|
+
width: width
|
|
240
|
+
}, rest), {}, {
|
|
241
|
+
children: [/*#__PURE__*/_jsxs(Flexbox, {
|
|
242
|
+
className: styles.labelColumn,
|
|
243
|
+
gap: 8,
|
|
244
|
+
style: {
|
|
245
|
+
flex: hasLabelWidth ? "0 0 ".concat(labelWidthStyle) : '0 0 auto',
|
|
246
|
+
minWidth: hasLabelWidth ? 0 : 'max-content',
|
|
247
|
+
width: hasLabelWidth ? labelWidthStyle : 'auto'
|
|
248
|
+
},
|
|
249
|
+
width: hasLabelWidth ? labelWidth : 'auto',
|
|
250
|
+
children: [items.map(function (item) {
|
|
251
|
+
var textColor = item.highlighted ? resolvedHighlightColor : undefined;
|
|
252
|
+
return renderRowTooltip(item, /*#__PURE__*/_jsxs(Flexbox, {
|
|
253
|
+
align: "center",
|
|
254
|
+
className: styles.labelRow,
|
|
255
|
+
height: rowHeight,
|
|
256
|
+
horizontal: true,
|
|
257
|
+
onClick: function onClick() {
|
|
258
|
+
return handleClick(item);
|
|
259
|
+
},
|
|
260
|
+
style: {
|
|
261
|
+
cursor: onValueChange ? 'pointer' : 'default'
|
|
262
|
+
},
|
|
263
|
+
width: "100%",
|
|
264
|
+
children: [showRank ? /*#__PURE__*/_jsx("div", {
|
|
265
|
+
className: styles.rank,
|
|
266
|
+
style: textColor ? {
|
|
267
|
+
color: textColor
|
|
268
|
+
} : undefined,
|
|
269
|
+
children: renderRank ? renderRank(item) : "#".concat(item.rank)
|
|
270
|
+
}) : null, /*#__PURE__*/_jsxs(Flexbox, {
|
|
271
|
+
className: styles.identity,
|
|
272
|
+
horizontal: true,
|
|
273
|
+
children: [item.icon ? /*#__PURE__*/_jsx("div", {
|
|
274
|
+
className: styles.icon,
|
|
275
|
+
children: item.icon
|
|
276
|
+
}) : null, /*#__PURE__*/_jsxs("div", {
|
|
277
|
+
className: styles.labelStack,
|
|
278
|
+
children: [item.href ? /*#__PURE__*/_jsx(A, {
|
|
279
|
+
className: cx(styles.nameLink, styles.emphasis),
|
|
280
|
+
href: item.href,
|
|
281
|
+
onClick: function onClick(event) {
|
|
282
|
+
return event.stopPropagation();
|
|
283
|
+
},
|
|
284
|
+
style: textColor ? {
|
|
285
|
+
color: textColor
|
|
286
|
+
} : undefined,
|
|
287
|
+
target: item.target,
|
|
288
|
+
children: item.name
|
|
289
|
+
}) : /*#__PURE__*/_jsx("div", {
|
|
290
|
+
className: cx(styles.name, styles.emphasis),
|
|
291
|
+
style: textColor ? {
|
|
292
|
+
color: textColor
|
|
293
|
+
} : undefined,
|
|
294
|
+
children: item.name
|
|
295
|
+
}), item.provider ? /*#__PURE__*/_jsx("div", {
|
|
296
|
+
className: cx(styles.provider, styles.emphasis),
|
|
297
|
+
style: textColor ? {
|
|
298
|
+
color: textColor
|
|
299
|
+
} : undefined,
|
|
300
|
+
children: item.provider
|
|
301
|
+
}) : null]
|
|
302
|
+
})]
|
|
303
|
+
})]
|
|
304
|
+
}), "label-".concat(item.key), hasLabelWidth);
|
|
305
|
+
}), showXAxis ? /*#__PURE__*/_jsx("div", {
|
|
306
|
+
className: styles.axisLabelSpacer,
|
|
307
|
+
style: {
|
|
308
|
+
minHeight: xAxisLabel ? 44 : 28
|
|
309
|
+
}
|
|
310
|
+
}) : null]
|
|
311
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
312
|
+
className: styles.plot,
|
|
313
|
+
children: [showYAxis ? /*#__PURE__*/_jsx("div", {
|
|
314
|
+
className: styles.yAxisLine,
|
|
315
|
+
style: {
|
|
316
|
+
bottom: showXAxis ? xAxisLabel ? 44 : 28 : 0
|
|
317
|
+
}
|
|
318
|
+
}) : null, showGridLines ? gridTicks.map(function (tick) {
|
|
319
|
+
return /*#__PURE__*/_jsx("div", {
|
|
320
|
+
className: styles.gridLine,
|
|
321
|
+
style: {
|
|
322
|
+
bottom: showXAxis ? xAxisLabel ? 44 : 28 : 0,
|
|
323
|
+
left: "".concat(toPercent(tick), "%")
|
|
324
|
+
}
|
|
325
|
+
}, "grid-".concat(tick));
|
|
326
|
+
}) : null, /*#__PURE__*/_jsx(Flexbox, {
|
|
327
|
+
className: styles.plotRows,
|
|
328
|
+
gap: 8,
|
|
329
|
+
role: "list",
|
|
330
|
+
children: items.map(function (item) {
|
|
331
|
+
var _item$color2;
|
|
332
|
+
var barColor = (_item$color2 = item.color) !== null && _item$color2 !== void 0 ? _item$color2 : color;
|
|
333
|
+
var percent = getBenchmarkBarPercent(item.value, resolvedMaxValue);
|
|
334
|
+
var isActive = activeKey === item.key;
|
|
335
|
+
var display = formatBenchmarkAccuracyDisplay({
|
|
336
|
+
accuracyFormatter: accuracyFormatter,
|
|
337
|
+
error: item.error,
|
|
338
|
+
errorFormatter: errorFormatter,
|
|
339
|
+
showError: showError,
|
|
340
|
+
value: item.value,
|
|
341
|
+
valueFormatter: valueFormatter
|
|
342
|
+
});
|
|
343
|
+
var errorPct = enableErrorBars && item.error !== undefined && item.error !== null ? toPercent(item.error) : 0;
|
|
344
|
+
var errorLeft = Math.max(0, percent - errorPct);
|
|
345
|
+
var errorWidth = Math.min(100 - errorLeft, errorPct * 2);
|
|
346
|
+
return renderRowTooltip(item, /*#__PURE__*/_jsx(Flexbox, {
|
|
347
|
+
"aria-label": "Rank ".concat(item.rank, ": ").concat(String(item.name)).concat(item.provider ? " by ".concat(String(item.provider)) : '', ", score ").concat(display.text),
|
|
348
|
+
className: cx(styles.plotRow, onValueChange && styles.barHover),
|
|
349
|
+
height: rowHeight,
|
|
350
|
+
onClick: function onClick() {
|
|
351
|
+
return handleClick(item);
|
|
352
|
+
},
|
|
353
|
+
role: 'listitem',
|
|
354
|
+
style: {
|
|
355
|
+
cursor: onValueChange || showTooltip ? 'pointer' : 'default',
|
|
356
|
+
opacity: activeKey && !isActive ? 0.55 : 1
|
|
357
|
+
},
|
|
358
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
359
|
+
className: styles.barTrack,
|
|
360
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
361
|
+
className: cx("".concat(prefixCls, "-benchmark-ranking-bar"), styles.bar),
|
|
362
|
+
style: {
|
|
363
|
+
background: barColor,
|
|
364
|
+
height: barSize,
|
|
365
|
+
transition: showAnimation ? undefined : 'none',
|
|
366
|
+
width: "".concat(percent, "%")
|
|
367
|
+
}
|
|
368
|
+
}), errorPct > 0 ? /*#__PURE__*/_jsx("div", {
|
|
369
|
+
className: styles.errorBar,
|
|
370
|
+
"data-testid": "benchmark-error-bar",
|
|
371
|
+
style: {
|
|
372
|
+
left: "".concat(errorLeft, "%"),
|
|
373
|
+
width: "".concat(errorWidth, "%")
|
|
374
|
+
}
|
|
375
|
+
}) : null]
|
|
376
|
+
})
|
|
377
|
+
}), "plot-".concat(item.key));
|
|
378
|
+
})
|
|
379
|
+
}), showXAxis ? /*#__PURE__*/_jsxs("div", {
|
|
380
|
+
className: styles.xAxis,
|
|
381
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
382
|
+
className: styles.xAxisLine
|
|
383
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
384
|
+
className: styles.xAxisTicks,
|
|
385
|
+
children: axisTicks.map(function (tick) {
|
|
386
|
+
return /*#__PURE__*/_jsx("span", {
|
|
387
|
+
className: styles.xAxisTick,
|
|
388
|
+
style: {
|
|
389
|
+
left: "".concat(toPercent(tick), "%"),
|
|
390
|
+
transform: tick === 0 ? 'translateX(0)' : tick === resolvedMaxValue ? 'translateX(-100%)' : 'translateX(-50%)'
|
|
391
|
+
},
|
|
392
|
+
children: displayFormatter(tick)
|
|
393
|
+
}, tick);
|
|
394
|
+
})
|
|
395
|
+
}), xAxisLabel ? /*#__PURE__*/_jsx("div", {
|
|
396
|
+
className: styles.xAxisLabel,
|
|
397
|
+
children: xAxisLabel
|
|
398
|
+
}) : null]
|
|
399
|
+
}) : null]
|
|
400
|
+
}), showValueLabel ? /*#__PURE__*/_jsxs(Flexbox, {
|
|
401
|
+
className: styles.scoreColumn,
|
|
402
|
+
gap: 8,
|
|
403
|
+
children: [items.map(function (item) {
|
|
404
|
+
var textColor = item.highlighted ? resolvedHighlightColor : undefined;
|
|
405
|
+
var display = formatBenchmarkAccuracyDisplay({
|
|
406
|
+
accuracyFormatter: accuracyFormatter,
|
|
407
|
+
error: item.error,
|
|
408
|
+
errorFormatter: errorFormatter,
|
|
409
|
+
showError: showError && !enableErrorBars,
|
|
410
|
+
value: item.value,
|
|
411
|
+
valueFormatter: valueFormatter
|
|
412
|
+
});
|
|
413
|
+
return renderRowTooltip(item, /*#__PURE__*/_jsx(Flexbox, {
|
|
414
|
+
align: "center",
|
|
415
|
+
className: styles.scoreRow,
|
|
416
|
+
height: rowHeight,
|
|
417
|
+
horizontal: true,
|
|
418
|
+
justify: "flex-end",
|
|
419
|
+
onClick: function onClick() {
|
|
420
|
+
return handleClick(item);
|
|
421
|
+
},
|
|
422
|
+
style: {
|
|
423
|
+
cursor: onValueChange || showTooltip ? 'pointer' : 'default'
|
|
424
|
+
},
|
|
425
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
426
|
+
className: styles.score,
|
|
427
|
+
style: textColor ? {
|
|
428
|
+
color: textColor
|
|
429
|
+
} : undefined,
|
|
430
|
+
children: [displayFormatter(item.value), display.errorText ? /*#__PURE__*/_jsxs("span", {
|
|
431
|
+
className: styles.scoreError,
|
|
432
|
+
children: ["\xB1 ", display.errorText]
|
|
433
|
+
}) : null]
|
|
434
|
+
})
|
|
435
|
+
}), "score-".concat(item.key));
|
|
436
|
+
}), showXAxis ? /*#__PURE__*/_jsx("div", {
|
|
437
|
+
className: styles.axisLabelSpacer,
|
|
438
|
+
style: {
|
|
439
|
+
minHeight: xAxisLabel ? 44 : 28
|
|
440
|
+
}
|
|
441
|
+
}) : null]
|
|
442
|
+
}) : null, !data.length && /*#__PURE__*/_jsx(NoData, {
|
|
443
|
+
noDataText: noDataText
|
|
444
|
+
})]
|
|
445
|
+
}));
|
|
446
|
+
});
|
|
447
|
+
BenchmarkRankingChart.displayName = 'BenchmarkRankingChart';
|
|
448
|
+
export default BenchmarkRankingChart;
|