@lobehub/charts 5.4.0 → 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/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/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,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: BenchmarkRankingChart
|
|
3
|
+
description: Horizontal leaderboard chart for model benchmark rankings with injectable brand icons.
|
|
4
|
+
category: Benchmark
|
|
5
|
+
order: 2
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
import DemoIndex from './demos/index.tsx?demo';
|
|
9
|
+
import DemoAccuracy from './demos/accuracy.tsx?demo';
|
|
10
|
+
import DemoHighlighted from './demos/highlighted.tsx?demo';
|
|
11
|
+
|
|
12
|
+
<Demo of={DemoIndex} layout="bare" />
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Pass model icons and brand colors from the consumer (e.g. `@lobehub/icons`). The chart package does not bundle icons or brand color logic.
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { BenchmarkRankingChart } from '@lobehub/charts';
|
|
20
|
+
import { Gemini, OpenAI } from '@lobehub/icons';
|
|
21
|
+
|
|
22
|
+
export default () => (
|
|
23
|
+
<BenchmarkRankingChart
|
|
24
|
+
data={[
|
|
25
|
+
{
|
|
26
|
+
color: Gemini.colorPrimary,
|
|
27
|
+
icon: <Gemini.Avatar size={22} />,
|
|
28
|
+
name: 'Gemini 3.8',
|
|
29
|
+
provider: 'Google',
|
|
30
|
+
score: 82.6,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
color: OpenAI.colorPrimary,
|
|
34
|
+
icon: <OpenAI.Avatar size={22} />,
|
|
35
|
+
name: 'GPT-6 Pro',
|
|
36
|
+
provider: 'OpenAI',
|
|
37
|
+
score: 73.9,
|
|
38
|
+
},
|
|
39
|
+
]}
|
|
40
|
+
labelWidth={280}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Accuracy with error bars
|
|
46
|
+
|
|
47
|
+
Use `accuracyFormatter`, `error`, and `showErrorBars` for AccuracyBar-style percentage, ± uncertainty, and horizontal error whiskers. Pass `labelWidth` to cap the left label column; omit it to fit the longest name. The X axis is off by default — set `showXAxis` / `showYAxis` to show coordinate axes.
|
|
48
|
+
|
|
49
|
+
<Demo of={DemoAccuracy} />
|
|
50
|
+
|
|
51
|
+
## Highlighted items
|
|
52
|
+
|
|
53
|
+
Set `highlighted: true` on a record to accent its name / provider / score with `highlightColor` (defaults to `theme.gold`). Bar fill colors are unchanged.
|
|
54
|
+
|
|
55
|
+
<Demo of={DemoHighlighted} />
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
<Api name="BenchmarkRankingChart" />
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const styles: {
|
|
2
|
+
axisLabelSpacer: string;
|
|
3
|
+
bar: string;
|
|
4
|
+
barHover: string;
|
|
5
|
+
barTrack: string;
|
|
6
|
+
container: string;
|
|
7
|
+
emphasis: string;
|
|
8
|
+
errorBar: string;
|
|
9
|
+
gridLine: string;
|
|
10
|
+
icon: string;
|
|
11
|
+
identity: string;
|
|
12
|
+
labelColumn: string;
|
|
13
|
+
labelRow: string;
|
|
14
|
+
labelStack: string;
|
|
15
|
+
name: string;
|
|
16
|
+
nameLink: string;
|
|
17
|
+
plot: string;
|
|
18
|
+
plotRow: string;
|
|
19
|
+
plotRows: string;
|
|
20
|
+
provider: string;
|
|
21
|
+
rank: string;
|
|
22
|
+
score: string;
|
|
23
|
+
scoreColumn: string;
|
|
24
|
+
scoreError: string;
|
|
25
|
+
scoreRow: string;
|
|
26
|
+
tooltipTrigger: string;
|
|
27
|
+
xAxis: string;
|
|
28
|
+
xAxisLabel: string;
|
|
29
|
+
xAxisLine: string;
|
|
30
|
+
xAxisTick: string;
|
|
31
|
+
xAxisTicks: string;
|
|
32
|
+
yAxisLine: string;
|
|
33
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18, _templateObject19, _templateObject20, _templateObject21, _templateObject22, _templateObject23, _templateObject24, _templateObject25, _templateObject26, _templateObject27, _templateObject28, _templateObject29, _templateObject30, _templateObject31;
|
|
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
|
+
var prefixCls = 'ant';
|
|
5
|
+
export var styles = createStaticStyles(function (_ref) {
|
|
6
|
+
var css = _ref.css,
|
|
7
|
+
cssVar = _ref.cssVar;
|
|
8
|
+
return {
|
|
9
|
+
axisLabelSpacer: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n flex-shrink: 0;\n width: 100%;\n "]))),
|
|
10
|
+
bar: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n top: 50%;\n left: 0;\n transform: translateY(-50%);\n\n max-width: 100%;\n border-radius: 0;\n\n transition: all 0.25s ", ";\n "])), cssVar.motionEaseInOut),
|
|
11
|
+
barHover: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n &:hover {\n .", "-benchmark-ranking-bar {\n filter: brightness(1.08);\n }\n }\n "])), prefixCls),
|
|
12
|
+
barTrack: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n overflow: visible;\n width: 100%;\n height: 100%;\n "]))),
|
|
13
|
+
container: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n align-items: stretch;\n min-width: 0;\n "]))),
|
|
14
|
+
emphasis: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n "]))),
|
|
15
|
+
errorBar: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n position: absolute;\n z-index: 2;\n top: 50%;\n transform: translateY(-50%);\n\n height: 0;\n border-top: 1.5px solid #fff;\n\n mix-blend-mode: difference;\n\n &::before,\n &::after {\n content: '';\n\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n\n width: 0;\n height: 10px;\n border-left: 1.5px solid #fff;\n }\n\n &::before {\n left: 0;\n }\n\n &::after {\n right: 0;\n }\n "]))),
|
|
16
|
+
gridLine: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n position: absolute;\n z-index: 0;\n top: 0;\n\n width: 0;\n border-left: 1px dashed ", ";\n "])), cssVar.colorBorderSecondary),
|
|
17
|
+
icon: css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n display: inline-flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n\n width: 24px;\n height: 24px;\n "]))),
|
|
18
|
+
identity: css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n display: flex;\n flex: 1;\n gap: 10px;\n align-items: center;\n\n min-width: 0;\n "]))),
|
|
19
|
+
labelColumn: css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n flex-shrink: 0;\n min-width: 0;\n padding-right: 16px;\n "]))),
|
|
20
|
+
labelRow: css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n min-width: 0;\n "]))),
|
|
21
|
+
labelStack: css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n display: flex;\n flex: 1;\n flex-direction: column;\n gap: 2px;\n justify-content: center;\n\n min-width: 0;\n "]))),
|
|
22
|
+
name: css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n overflow: hidden;\n\n font-size: var(--benchmark-label-font-size, 14px);\n font-weight: 600;\n line-height: 1.3;\n color: ", ";\n text-overflow: ellipsis;\n white-space: pre-line;\n "])), cssVar.colorText),
|
|
23
|
+
nameLink: css(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n overflow: hidden;\n\n font-size: var(--benchmark-label-font-size, 14px);\n font-weight: 600;\n line-height: 1.3;\n color: ", " !important;\n text-overflow: ellipsis;\n white-space: pre-line;\n\n &:hover {\n color: ", " !important;\n }\n "])), cssVar.colorText, cssVar.colorLinkHover),
|
|
24
|
+
plot: css(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n position: relative;\n overflow: visible;\n flex: 1;\n min-width: 80px;\n "]))),
|
|
25
|
+
plotRow: css(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["\n position: relative;\n width: 100%;\n min-width: 0;\n "]))),
|
|
26
|
+
plotRows: css(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n position: relative;\n z-index: 1;\n width: 100%;\n "]))),
|
|
27
|
+
provider: css(_templateObject19 || (_templateObject19 = _taggedTemplateLiteral(["\n overflow: hidden;\n\n font-size: var(--benchmark-subtitle-font-size, 12px);\n line-height: 1.3;\n color: ", ";\n text-overflow: ellipsis;\n white-space: nowrap;\n "])), cssVar.colorTextDescription),
|
|
28
|
+
rank: css(_templateObject20 || (_templateObject20 = _taggedTemplateLiteral(["\n flex-shrink: 0;\n\n min-width: 20px;\n margin-right: 12px;\n\n font-family: 'Geist Mono', SFMono-Regular, Consolas, 'Liberation Mono', monospace;\n font-size: var(--benchmark-value-label-font-size, 14px);\n font-variant-numeric: tabular-nums;\n line-height: 1.3;\n color: ", ";\n text-align: left;\n "])), cssVar.colorTextQuaternary),
|
|
29
|
+
score: css(_templateObject21 || (_templateObject21 = _taggedTemplateLiteral(["\n flex-shrink: 0;\n\n min-width: 40px;\n\n font-family: 'Geist Mono', SFMono-Regular, Consolas, 'Liberation Mono', monospace;\n font-size: var(--benchmark-value-label-font-size, 14px);\n font-weight: 600;\n font-variant-numeric: tabular-nums;\n line-height: 1.3;\n color: ", ";\n text-align: right;\n "])), cssVar.colorText),
|
|
30
|
+
scoreColumn: css(_templateObject22 || (_templateObject22 = _taggedTemplateLiteral(["\n flex-shrink: 0;\n min-width: 48px;\n padding-left: 16px;\n "]))),
|
|
31
|
+
scoreError: css(_templateObject23 || (_templateObject23 = _taggedTemplateLiteral(["\n margin-left: 4px;\n\n font-family: 'Geist Mono', SFMono-Regular, Consolas, 'Liberation Mono', monospace;\n font-size: calc(var(--benchmark-value-label-font-size, 14px) - 2px);\n font-weight: 400;\n color: ", ";\n "])), cssVar.colorTextSecondary),
|
|
32
|
+
scoreRow: css(_templateObject24 || (_templateObject24 = _taggedTemplateLiteral(["\n width: 100%;\n "]))),
|
|
33
|
+
tooltipTrigger: css(_templateObject25 || (_templateObject25 = _taggedTemplateLiteral(["\n width: 100%;\n min-width: 0;\n height: 100%;\n "]))),
|
|
34
|
+
xAxis: css(_templateObject26 || (_templateObject26 = _taggedTemplateLiteral(["\n position: relative;\n margin-top: 4px;\n padding-top: 0;\n "]))),
|
|
35
|
+
xAxisLabel: css(_templateObject27 || (_templateObject27 = _taggedTemplateLiteral(["\n margin-top: 8px;\n\n font-size: 12px;\n font-weight: 500;\n line-height: 16px;\n color: ", ";\n text-align: center;\n "])), cssVar.colorTextSecondary),
|
|
36
|
+
xAxisLine: css(_templateObject28 || (_templateObject28 = _taggedTemplateLiteral(["\n width: 100%;\n height: 0;\n border-top: 1px solid ", ";\n "])), cssVar.colorBorder),
|
|
37
|
+
xAxisTick: css(_templateObject29 || (_templateObject29 = _taggedTemplateLiteral(["\n position: absolute;\n top: 6px;\n\n font-family: 'Geist Mono', SFMono-Regular, Consolas, 'Liberation Mono', monospace;\n font-size: 12px;\n line-height: 16px;\n color: ", ";\n white-space: nowrap;\n "])), cssVar.colorTextDescription),
|
|
38
|
+
xAxisTicks: css(_templateObject30 || (_templateObject30 = _taggedTemplateLiteral(["\n position: relative;\n height: 22px;\n "]))),
|
|
39
|
+
yAxisLine: css(_templateObject31 || (_templateObject31 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n position: absolute;\n z-index: 2;\n top: 0;\n bottom: 0;\n left: 0;\n\n width: 0;\n border-left: 1px solid ", ";\n "])), cssVar.colorBorder)
|
|
40
|
+
};
|
|
41
|
+
});
|
|
@@ -17,7 +17,7 @@ export var styles = createStaticStyles(function (_ref) {
|
|
|
17
17
|
var css = _ref.css,
|
|
18
18
|
cssVar = _ref.cssVar;
|
|
19
19
|
return {
|
|
20
|
-
container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: hidden;\n\n border: 1px solid ", ";\n border-radius: ", ";\n\n background: ", ";\n box-shadow: ", ";\n "])), cssVar.colorBorderSecondary, cssVar.borderRadiusLG, cssVar.colorBgElevated, cssVar.boxShadow)
|
|
20
|
+
container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: hidden;\n\n width: max-content;\n min-width: 160px;\n border: 1px solid ", ";\n border-radius: ", ";\n\n background: ", ";\n box-shadow: ", ";\n "])), cssVar.colorBorderSecondary, cssVar.borderRadiusLG, cssVar.colorBgElevated, cssVar.boxShadow)
|
|
21
21
|
};
|
|
22
22
|
});
|
|
23
23
|
export var ChartTooltipFrame = /*#__PURE__*/memo(function (_ref2) {
|
|
@@ -11,7 +11,7 @@ var styles = createStaticStyles(function (_ref) {
|
|
|
11
11
|
var css = _ref.css,
|
|
12
12
|
cssVar = _ref.cssVar;
|
|
13
13
|
return {
|
|
14
|
-
number: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n font-weight: 500;\n "]))),
|
|
14
|
+
number: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n flex-shrink: 0;\n font-weight: 500;\n white-space: nowrap;\n "]))),
|
|
15
15
|
title: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n color: ", ";\n "])), cssVar.colorTextSecondary)
|
|
16
16
|
};
|
|
17
17
|
});
|
|
@@ -24,10 +24,12 @@ var ChartTooltipRow = /*#__PURE__*/memo(function (_ref2) {
|
|
|
24
24
|
gap: 32,
|
|
25
25
|
horizontal: true,
|
|
26
26
|
justify: 'space-between',
|
|
27
|
+
width: 'max-content',
|
|
27
28
|
children: [/*#__PURE__*/_jsxs(Flexbox, {
|
|
28
29
|
align: 'center',
|
|
29
30
|
gap: 8,
|
|
30
31
|
horizontal: true,
|
|
32
|
+
width: 'auto',
|
|
31
33
|
children: [/*#__PURE__*/_jsx(Icon, {
|
|
32
34
|
color: color,
|
|
33
35
|
fill: color,
|
|
@@ -31,6 +31,7 @@ var ChartTooltip = function ChartTooltip(_ref2) {
|
|
|
31
31
|
className: cx(styles.header),
|
|
32
32
|
paddingBlock: 8,
|
|
33
33
|
paddingInline: 16,
|
|
34
|
+
width: 'auto',
|
|
34
35
|
children: /*#__PURE__*/_jsx(Typography.Paragraph, {
|
|
35
36
|
ellipsis: true,
|
|
36
37
|
style: {
|
|
@@ -46,6 +47,7 @@ var ChartTooltip = function ChartTooltip(_ref2) {
|
|
|
46
47
|
flexDirection: 'column-reverse',
|
|
47
48
|
marginTop: 4
|
|
48
49
|
},
|
|
50
|
+
width: 'auto',
|
|
49
51
|
children: filteredPayload.map(function (_ref3, idx) {
|
|
50
52
|
var _categoryColors$get;
|
|
51
53
|
var value = _ref3.value,
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { BenchmarkBaseProps, BenchmarkEventProps, BenchmarkFieldKeys, BenchmarkRecord, BenchmarkRenderIcon, NormalizedBenchmarkItem, } from './types';
|
|
2
|
+
export { DEFAULT_BENCHMARK_KEYS, defaultBenchmarkAccuracyFormatter, defaultBenchmarkErrorFormatter, defaultBenchmarkValueFormatter, formatBenchmarkAccuracyDisplay, getBenchmarkBarPercent, getBenchmarkIcon, getBenchmarkLabelMetrics, getBenchmarkMaxValue, normalizeBenchmarkData, resolveBenchmarkKeys, splitBenchmarkLabel, } from './utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DEFAULT_BENCHMARK_KEYS, defaultBenchmarkAccuracyFormatter, defaultBenchmarkErrorFormatter, defaultBenchmarkValueFormatter, formatBenchmarkAccuracyDisplay, getBenchmarkBarPercent, getBenchmarkIcon, getBenchmarkLabelMetrics, getBenchmarkMaxValue, normalizeBenchmarkData, resolveBenchmarkKeys, splitBenchmarkLabel } from "./utils";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import type { NoDataProps } from "../NoData";
|
|
3
|
+
import type { ValueFormatter } from "../../types/charts";
|
|
4
|
+
export interface BenchmarkRecord {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
color?: string;
|
|
7
|
+
error?: number;
|
|
8
|
+
highlighted?: boolean;
|
|
9
|
+
href?: string;
|
|
10
|
+
icon?: ReactNode;
|
|
11
|
+
key?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Secondary line-series value (e.g. Pass¹ overall rate)
|
|
14
|
+
*/
|
|
15
|
+
line?: number;
|
|
16
|
+
name?: ReactNode;
|
|
17
|
+
provider?: ReactNode;
|
|
18
|
+
rank?: number;
|
|
19
|
+
score?: number;
|
|
20
|
+
target?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Place item after a visual separator; line series does not connect into it
|
|
23
|
+
*/
|
|
24
|
+
unranked?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export type BenchmarkRenderIcon = (record: BenchmarkRecord, index: number) => ReactNode;
|
|
27
|
+
export type BenchmarkEventProps = (BenchmarkRecord & {
|
|
28
|
+
eventType: 'bar' | 'row';
|
|
29
|
+
value: number;
|
|
30
|
+
}) | null | undefined;
|
|
31
|
+
export interface BenchmarkFieldKeys {
|
|
32
|
+
/**
|
|
33
|
+
* Per-item bar color field
|
|
34
|
+
* @default 'color'
|
|
35
|
+
*/
|
|
36
|
+
colorKey?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Error / uncertainty field (AccuracyBar-style ± display)
|
|
39
|
+
* @default 'error'
|
|
40
|
+
*/
|
|
41
|
+
errorKey?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Icon field; value should be a ReactNode provided by the consumer
|
|
44
|
+
* @default 'icon'
|
|
45
|
+
*/
|
|
46
|
+
iconKey?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Model / entry name field
|
|
49
|
+
* @default 'name'
|
|
50
|
+
*/
|
|
51
|
+
index?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Secondary line-series field
|
|
54
|
+
* @default 'line'
|
|
55
|
+
*/
|
|
56
|
+
lineKey?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Provider / organization field
|
|
59
|
+
* @default 'provider'
|
|
60
|
+
*/
|
|
61
|
+
providerKey?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Numeric score field
|
|
64
|
+
* @default 'score'
|
|
65
|
+
*/
|
|
66
|
+
valueKey?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface BenchmarkBaseProps extends BenchmarkFieldKeys, Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
69
|
+
/**
|
|
70
|
+
* Accuracy-style value formatter (e.g. `52.0%`). Falls back to `valueFormatter`.
|
|
71
|
+
*/
|
|
72
|
+
accuracyFormatter?: (value: number) => string;
|
|
73
|
+
data?: BenchmarkRecord[];
|
|
74
|
+
/**
|
|
75
|
+
* Formats the ± error segment
|
|
76
|
+
* @default (n) => n.toFixed(1)
|
|
77
|
+
*/
|
|
78
|
+
errorFormatter?: (value: number) => string;
|
|
79
|
+
height?: string | number;
|
|
80
|
+
/**
|
|
81
|
+
* Text accent color when an item has `highlighted: true` (does not change bar fill)
|
|
82
|
+
* @default theme.gold
|
|
83
|
+
*/
|
|
84
|
+
highlightColor?: string;
|
|
85
|
+
loading?: boolean;
|
|
86
|
+
noDataText?: NoDataProps['noDataText'];
|
|
87
|
+
onValueChange?: (value: BenchmarkEventProps) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Optional icon renderer that overrides `iconKey`
|
|
90
|
+
*/
|
|
91
|
+
renderIcon?: BenchmarkRenderIcon;
|
|
92
|
+
showAnimation?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Show AccuracyBar-style ± error next to values / error bars
|
|
95
|
+
* @default true
|
|
96
|
+
*/
|
|
97
|
+
showError?: boolean;
|
|
98
|
+
sortOrder?: 'ascending' | 'descending' | 'none';
|
|
99
|
+
valueFormatter?: ValueFormatter;
|
|
100
|
+
width?: string | number;
|
|
101
|
+
}
|
|
102
|
+
export interface NormalizedBenchmarkItem {
|
|
103
|
+
color?: string;
|
|
104
|
+
error?: number;
|
|
105
|
+
highlighted?: boolean;
|
|
106
|
+
href?: string;
|
|
107
|
+
icon?: ReactNode;
|
|
108
|
+
key: string | number;
|
|
109
|
+
lineValue?: number;
|
|
110
|
+
name: ReactNode;
|
|
111
|
+
original: BenchmarkRecord;
|
|
112
|
+
provider?: ReactNode;
|
|
113
|
+
rank: number;
|
|
114
|
+
target?: string;
|
|
115
|
+
unranked?: boolean;
|
|
116
|
+
value: number;
|
|
117
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { BenchmarkFieldKeys, BenchmarkRecord, BenchmarkRenderIcon, NormalizedBenchmarkItem } from './types';
|
|
3
|
+
export declare const DEFAULT_BENCHMARK_KEYS: {
|
|
4
|
+
readonly colorKey: "color";
|
|
5
|
+
readonly errorKey: "error";
|
|
6
|
+
readonly iconKey: "icon";
|
|
7
|
+
readonly index: "name";
|
|
8
|
+
readonly lineKey: "line";
|
|
9
|
+
readonly providerKey: "provider";
|
|
10
|
+
readonly valueKey: "score";
|
|
11
|
+
};
|
|
12
|
+
export declare const resolveBenchmarkKeys: (keys?: BenchmarkFieldKeys) => {
|
|
13
|
+
colorKey: string;
|
|
14
|
+
errorKey: string;
|
|
15
|
+
iconKey: string;
|
|
16
|
+
index: string;
|
|
17
|
+
lineKey: string;
|
|
18
|
+
providerKey: string;
|
|
19
|
+
valueKey: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const getBenchmarkIcon: (record: BenchmarkRecord, iconKey: string, renderIcon?: BenchmarkRenderIcon, index?: number) => import("react").ReactNode;
|
|
22
|
+
export declare const normalizeBenchmarkData: ({ colorKey, data, errorKey, iconKey, index, lineKey, providerKey, renderIcon, sortOrder, valueKey, }: BenchmarkFieldKeys & {
|
|
23
|
+
data: BenchmarkRecord[];
|
|
24
|
+
renderIcon?: BenchmarkRenderIcon | undefined;
|
|
25
|
+
sortOrder?: "none" | "ascending" | "descending" | undefined;
|
|
26
|
+
}) => NormalizedBenchmarkItem[];
|
|
27
|
+
export declare const getBenchmarkMaxValue: (items: NormalizedBenchmarkItem[], maxValue?: number) => number;
|
|
28
|
+
export declare const getBenchmarkBarPercent: (value: number, maxValue: number, minPercent?: number) => number;
|
|
29
|
+
export declare const defaultBenchmarkValueFormatter: (value: number) => string;
|
|
30
|
+
export declare const defaultBenchmarkAccuracyFormatter: (value: number) => string;
|
|
31
|
+
export declare const defaultBenchmarkErrorFormatter: (value: number) => string;
|
|
32
|
+
export declare const formatBenchmarkAccuracyDisplay: ({ accuracyFormatter, error, errorFormatter, showError, value, valueFormatter, }: {
|
|
33
|
+
accuracyFormatter?: ((value: number) => string) | undefined;
|
|
34
|
+
error?: number | undefined;
|
|
35
|
+
errorFormatter?: ((value: number) => string) | undefined;
|
|
36
|
+
showError?: boolean | undefined;
|
|
37
|
+
value: number;
|
|
38
|
+
valueFormatter?: ((value: number) => string) | undefined;
|
|
39
|
+
}) => {
|
|
40
|
+
errorText: undefined;
|
|
41
|
+
main: string;
|
|
42
|
+
text: string;
|
|
43
|
+
} | {
|
|
44
|
+
errorText: string;
|
|
45
|
+
main: string;
|
|
46
|
+
text: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Split a label into lines. Supports `\n` / `\r\n`.
|
|
50
|
+
*/
|
|
51
|
+
export declare const splitBenchmarkLabel: (label: unknown) => string[];
|
|
52
|
+
export declare const getBenchmarkLabelMetrics: (label: unknown) => {
|
|
53
|
+
lineCount: number;
|
|
54
|
+
lines: string[];
|
|
55
|
+
longestWidth: number;
|
|
56
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
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."); }
|
|
3
|
+
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); }
|
|
4
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
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; }
|
|
7
|
+
import { getTextWidth } from "../../utils/getMaxLabelLength";
|
|
8
|
+
export var DEFAULT_BENCHMARK_KEYS = {
|
|
9
|
+
colorKey: 'color',
|
|
10
|
+
errorKey: 'error',
|
|
11
|
+
iconKey: 'icon',
|
|
12
|
+
index: 'name',
|
|
13
|
+
lineKey: 'line',
|
|
14
|
+
providerKey: 'provider',
|
|
15
|
+
valueKey: 'score'
|
|
16
|
+
};
|
|
17
|
+
export var resolveBenchmarkKeys = function resolveBenchmarkKeys() {
|
|
18
|
+
var _keys$colorKey, _keys$errorKey, _keys$iconKey, _keys$index, _keys$lineKey, _keys$providerKey, _keys$valueKey;
|
|
19
|
+
var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
20
|
+
return {
|
|
21
|
+
colorKey: (_keys$colorKey = keys.colorKey) !== null && _keys$colorKey !== void 0 ? _keys$colorKey : DEFAULT_BENCHMARK_KEYS.colorKey,
|
|
22
|
+
errorKey: (_keys$errorKey = keys.errorKey) !== null && _keys$errorKey !== void 0 ? _keys$errorKey : DEFAULT_BENCHMARK_KEYS.errorKey,
|
|
23
|
+
iconKey: (_keys$iconKey = keys.iconKey) !== null && _keys$iconKey !== void 0 ? _keys$iconKey : DEFAULT_BENCHMARK_KEYS.iconKey,
|
|
24
|
+
index: (_keys$index = keys.index) !== null && _keys$index !== void 0 ? _keys$index : DEFAULT_BENCHMARK_KEYS.index,
|
|
25
|
+
lineKey: (_keys$lineKey = keys.lineKey) !== null && _keys$lineKey !== void 0 ? _keys$lineKey : DEFAULT_BENCHMARK_KEYS.lineKey,
|
|
26
|
+
providerKey: (_keys$providerKey = keys.providerKey) !== null && _keys$providerKey !== void 0 ? _keys$providerKey : DEFAULT_BENCHMARK_KEYS.providerKey,
|
|
27
|
+
valueKey: (_keys$valueKey = keys.valueKey) !== null && _keys$valueKey !== void 0 ? _keys$valueKey : DEFAULT_BENCHMARK_KEYS.valueKey
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export var getBenchmarkIcon = function getBenchmarkIcon(record, iconKey, renderIcon) {
|
|
31
|
+
var index = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
32
|
+
if (renderIcon) return renderIcon(record, index);
|
|
33
|
+
return record[iconKey];
|
|
34
|
+
};
|
|
35
|
+
export var normalizeBenchmarkData = function normalizeBenchmarkData(_ref) {
|
|
36
|
+
var colorKey = _ref.colorKey,
|
|
37
|
+
data = _ref.data,
|
|
38
|
+
errorKey = _ref.errorKey,
|
|
39
|
+
iconKey = _ref.iconKey,
|
|
40
|
+
index = _ref.index,
|
|
41
|
+
lineKey = _ref.lineKey,
|
|
42
|
+
providerKey = _ref.providerKey,
|
|
43
|
+
renderIcon = _ref.renderIcon,
|
|
44
|
+
_ref$sortOrder = _ref.sortOrder,
|
|
45
|
+
sortOrder = _ref$sortOrder === void 0 ? 'descending' : _ref$sortOrder,
|
|
46
|
+
valueKey = _ref.valueKey;
|
|
47
|
+
var keys = resolveBenchmarkKeys({
|
|
48
|
+
colorKey: colorKey,
|
|
49
|
+
errorKey: errorKey,
|
|
50
|
+
iconKey: iconKey,
|
|
51
|
+
index: index,
|
|
52
|
+
lineKey: lineKey,
|
|
53
|
+
providerKey: providerKey,
|
|
54
|
+
valueKey: valueKey
|
|
55
|
+
});
|
|
56
|
+
var sorted = sortOrder === 'none' ? _toConsumableArray(data) : _toConsumableArray(data).sort(function (a, b) {
|
|
57
|
+
var _a$keys$valueKey, _b$keys$valueKey;
|
|
58
|
+
var aUnranked = Boolean(a.unranked);
|
|
59
|
+
var bUnranked = Boolean(b.unranked);
|
|
60
|
+
if (aUnranked !== bUnranked) return aUnranked ? 1 : -1;
|
|
61
|
+
var aValue = Number((_a$keys$valueKey = a[keys.valueKey]) !== null && _a$keys$valueKey !== void 0 ? _a$keys$valueKey : 0);
|
|
62
|
+
var bValue = Number((_b$keys$valueKey = b[keys.valueKey]) !== null && _b$keys$valueKey !== void 0 ? _b$keys$valueKey : 0);
|
|
63
|
+
return sortOrder === 'ascending' ? aValue - bValue : bValue - aValue;
|
|
64
|
+
});
|
|
65
|
+
return sorted.map(function (record, idx) {
|
|
66
|
+
var _ref2, _record$keys$index, _record$keys$valueKey, _record$keys$lineKey, _record$keys$colorKey, _record$key, _record$keys$provider;
|
|
67
|
+
var name = (_ref2 = (_record$keys$index = record[keys.index]) !== null && _record$keys$index !== void 0 ? _record$keys$index : record.name) !== null && _ref2 !== void 0 ? _ref2 : '';
|
|
68
|
+
var value = Number((_record$keys$valueKey = record[keys.valueKey]) !== null && _record$keys$valueKey !== void 0 ? _record$keys$valueKey : 0);
|
|
69
|
+
var rank = typeof record.rank === 'number' ? record.rank : idx + 1;
|
|
70
|
+
var rawError = record[keys.errorKey];
|
|
71
|
+
var error = rawError === undefined || rawError === null || rawError === '' ? undefined : Number(rawError);
|
|
72
|
+
var rawLine = (_record$keys$lineKey = record[keys.lineKey]) !== null && _record$keys$lineKey !== void 0 ? _record$keys$lineKey : record.line;
|
|
73
|
+
var lineValue = rawLine === undefined || rawLine === null || rawLine === '' ? undefined : Number(rawLine);
|
|
74
|
+
return {
|
|
75
|
+
color: (_record$keys$colorKey = record[keys.colorKey]) !== null && _record$keys$colorKey !== void 0 ? _record$keys$colorKey : record.color,
|
|
76
|
+
error: Number.isFinite(error) ? error : undefined,
|
|
77
|
+
highlighted: Boolean(record.highlighted),
|
|
78
|
+
href: record.href,
|
|
79
|
+
icon: getBenchmarkIcon(record, keys.iconKey, renderIcon, idx),
|
|
80
|
+
key: (_record$key = record.key) !== null && _record$key !== void 0 ? _record$key : name === '' || name === undefined || name === null ? idx : String(name),
|
|
81
|
+
lineValue: Number.isFinite(lineValue) ? lineValue : undefined,
|
|
82
|
+
name: name,
|
|
83
|
+
original: record,
|
|
84
|
+
provider: (_record$keys$provider = record[keys.providerKey]) !== null && _record$keys$provider !== void 0 ? _record$keys$provider : record.provider,
|
|
85
|
+
rank: rank,
|
|
86
|
+
target: record.target,
|
|
87
|
+
unranked: Boolean(record.unranked),
|
|
88
|
+
value: value
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
export var getBenchmarkMaxValue = function getBenchmarkMaxValue(items, maxValue) {
|
|
93
|
+
if (typeof maxValue === 'number') return maxValue;
|
|
94
|
+
return Math.max.apply(Math, _toConsumableArray(items.flatMap(function (item) {
|
|
95
|
+
var _item$lineValue;
|
|
96
|
+
return [item.value, (_item$lineValue = item.lineValue) !== null && _item$lineValue !== void 0 ? _item$lineValue : 0];
|
|
97
|
+
})).concat([0]));
|
|
98
|
+
};
|
|
99
|
+
export var getBenchmarkBarPercent = function getBenchmarkBarPercent(value, maxValue) {
|
|
100
|
+
var minPercent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
|
|
101
|
+
if (maxValue <= 0 || value <= 0) return 0;
|
|
102
|
+
return Math.max(value / maxValue * 100, minPercent);
|
|
103
|
+
};
|
|
104
|
+
export var defaultBenchmarkValueFormatter = function defaultBenchmarkValueFormatter(value) {
|
|
105
|
+
if (Number.isInteger(value)) return String(value);
|
|
106
|
+
return value.toFixed(1);
|
|
107
|
+
};
|
|
108
|
+
export var defaultBenchmarkAccuracyFormatter = function defaultBenchmarkAccuracyFormatter(value) {
|
|
109
|
+
return "".concat(value.toFixed(1), "%");
|
|
110
|
+
};
|
|
111
|
+
export var defaultBenchmarkErrorFormatter = function defaultBenchmarkErrorFormatter(value) {
|
|
112
|
+
return value.toFixed(1);
|
|
113
|
+
};
|
|
114
|
+
export var formatBenchmarkAccuracyDisplay = function formatBenchmarkAccuracyDisplay(_ref3) {
|
|
115
|
+
var accuracyFormatter = _ref3.accuracyFormatter,
|
|
116
|
+
error = _ref3.error,
|
|
117
|
+
_ref3$errorFormatter = _ref3.errorFormatter,
|
|
118
|
+
errorFormatter = _ref3$errorFormatter === void 0 ? defaultBenchmarkErrorFormatter : _ref3$errorFormatter,
|
|
119
|
+
_ref3$showError = _ref3.showError,
|
|
120
|
+
showError = _ref3$showError === void 0 ? true : _ref3$showError,
|
|
121
|
+
value = _ref3.value,
|
|
122
|
+
_ref3$valueFormatter = _ref3.valueFormatter,
|
|
123
|
+
valueFormatter = _ref3$valueFormatter === void 0 ? defaultBenchmarkValueFormatter : _ref3$valueFormatter;
|
|
124
|
+
var formatValue = accuracyFormatter !== null && accuracyFormatter !== void 0 ? accuracyFormatter : valueFormatter;
|
|
125
|
+
var main = formatValue(value);
|
|
126
|
+
if (!showError || error === undefined || error === null || Number.isNaN(error)) {
|
|
127
|
+
return {
|
|
128
|
+
errorText: undefined,
|
|
129
|
+
main: main,
|
|
130
|
+
text: main
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
var errorText = errorFormatter(error);
|
|
134
|
+
return {
|
|
135
|
+
errorText: errorText,
|
|
136
|
+
main: main,
|
|
137
|
+
text: "".concat(main, " \xB1 ").concat(errorText)
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Split a label into lines. Supports `\n` / `\r\n`.
|
|
143
|
+
*/
|
|
144
|
+
export var splitBenchmarkLabel = function splitBenchmarkLabel(label) {
|
|
145
|
+
var text = String(label !== null && label !== void 0 ? label : '');
|
|
146
|
+
if (!text) return [''];
|
|
147
|
+
return text.split(/\r?\n/);
|
|
148
|
+
};
|
|
149
|
+
export var getBenchmarkLabelMetrics = function getBenchmarkLabelMetrics(label) {
|
|
150
|
+
var lines = splitBenchmarkLabel(label);
|
|
151
|
+
var longestWidth = lines.reduce(function (max, line) {
|
|
152
|
+
return Math.max(max, getTextWidth(line));
|
|
153
|
+
}, 0);
|
|
154
|
+
return {
|
|
155
|
+
lineCount: Math.max(lines.length, 1),
|
|
156
|
+
lines: lines,
|
|
157
|
+
longestWidth: longestWidth
|
|
158
|
+
};
|
|
159
|
+
};
|
package/es/index.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ export { default as AccuracyBarChart, type AccuracyBarChartProps } from './Accur
|
|
|
2
2
|
export { default as AreaChart, type AreaChartProps } from './AreaChart';
|
|
3
3
|
export { default as BarChart, type BarChartProps } from './BarChart';
|
|
4
4
|
export { type Bar, default as BarList, type BarListProps } from './BarList';
|
|
5
|
+
export { default as BenchmarkColumnChart, type BenchmarkColumnChartProps, } from './BenchmarkColumnChart';
|
|
6
|
+
export { default as BenchmarkRankingChart, type BenchmarkRankingChartProps, } from './BenchmarkRankingChart';
|
|
7
|
+
export type { BenchmarkEventProps, BenchmarkFieldKeys, BenchmarkRecord, BenchmarkRenderIcon, } from './common/benchmark';
|
|
5
8
|
export { default as ChartTooltip, type ChartTooltipProps } from './common/ChartTooltip';
|
|
6
9
|
export { default as ChartTooltipFrame } from './common/ChartTooltip/ChartTooltipFrame';
|
|
7
10
|
export { default as ChartTooltipRow } from './common/ChartTooltip/ChartTooltipRow';
|
package/es/index.js
CHANGED
|
@@ -2,6 +2,8 @@ export { default as AccuracyBarChart } from "./AccuracyBarChart";
|
|
|
2
2
|
export { default as AreaChart } from "./AreaChart";
|
|
3
3
|
export { default as BarChart } from "./BarChart";
|
|
4
4
|
export { default as BarList } from "./BarList";
|
|
5
|
+
export { default as BenchmarkColumnChart } from "./BenchmarkColumnChart";
|
|
6
|
+
export { default as BenchmarkRankingChart } from "./BenchmarkRankingChart";
|
|
5
7
|
export { default as ChartTooltip } from "./common/ChartTooltip";
|
|
6
8
|
export { default as ChartTooltipFrame } from "./common/ChartTooltip/ChartTooltipFrame";
|
|
7
9
|
export { default as ChartTooltipRow } from "./common/ChartTooltip/ChartTooltipRow";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/charts",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "React modern charts components built on recharts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"dayjs": "^1.11.21",
|
|
34
34
|
"fast-deep-equal": "^3.1.3",
|
|
35
35
|
"lucide-react": "^0.562.0",
|
|
36
|
-
"polished": "^4.3.1",
|
|
37
36
|
"recharts": "^2.15.4"
|
|
38
37
|
},
|
|
39
38
|
"peerDependencies": {
|