Skip to content

Commit e9972e0

Browse files
committed
fix log scaled y axis in charts
1 parent 1b66b68 commit e9972e0

File tree

13 files changed

+1867
-1328
lines changed

13 files changed

+1867
-1328
lines changed

package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ui/.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
ASSET_PREFIX=https://neuralmagic.github.io/ui/dev
1+
ASSET_PREFIX=https://neuralmagic.github.io/guidellm/ui/dev
22
BASE_PATH=/ui/dev
33
NEXT_PUBLIC_USE_MOCK_API=true

src/ui/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
ASSET_PREFIX=http://localhost:3000
22
BASE_PATH=http://localhost:3000
33
NEXT_PUBLIC_USE_MOCK_API=true
4+
USE_MOCK_DATA=false

src/ui/.env.local

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ASSET_PREFIX=http://localhost:3000
2-
BASE_PATH=http://localhost:3000
1+
ASSET_PREFIX=http://localhost:3001
2+
BASE_PATH=http://localhost:3001
33
NEXT_PUBLIC_USE_MOCK_API=true
4-
USE_MOCK_DATA=true
4+
USE_MOCK_DATA=false

src/ui/.env.production

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
ASSET_PREFIX=https://neuralmagic.github.io/ui/latest
1+
ASSET_PREFIX=https://neuralmagic.github.io/guidellm/ui/latest
22
BASE_PATH=/ui/latest
33
NEXT_PUBLIC_USE_MOCK_API=true

src/ui/.env.staging

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
ASSET_PREFIX=https://neuralmagic.github.io/ui/release/latest
1+
ASSET_PREFIX=https://neuralmagic.github.io/guidellm/ui/release/latest
22
BASE_PATH=/ui/release/latest
33
NEXT_PUBLIC_USE_MOCK_API=true

src/ui/lib/components/Charts/DashedLine/DashedLine.component.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { DashedLineProps, ScaleType } from './DashedLine.interfaces';
77
import { spacedLogValues } from './helpers';
88

99
export const getMinTick = (data: readonly Serie[]) => {
10-
return Math.max(
10+
return Math.min(
1111
...data.map((lineData) =>
1212
Math.min(...lineData.data.map((point) => point.y as number))
1313
)
@@ -80,11 +80,16 @@ export const Component = ({
8080
let extraLeftAxisOptions = {};
8181
let extraYScaleOptions = {};
8282
if (yScaleType === ScaleType.log) {
83-
const ticks = spacedLogValues(getMinTick(data), getMaxTick(data), 6);
83+
const ticks = spacedLogValues(
84+
Math.floor(getMinTick(data)),
85+
Math.ceil(getMaxTick(data)),
86+
6
87+
);
8488
extraLeftAxisOptions = {
8589
tickValues: ticks,
8690
};
8791
extraYScaleOptions = {
92+
min: ticks[0],
8893
max: ticks[ticks.length - 1],
8994
};
9095
}

src/ui/lib/components/Charts/DashedLine/helpers.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ const allowedMultipliers = [
1313
1, 1.2, 1.4, 1.5, 1.6, 1.8, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 7.5, 8, 9, 10,
1414
];
1515

16+
export function roundDownNice(x: number) {
17+
if (x <= 0) {
18+
return x;
19+
}
20+
const exponent = Math.floor(Math.log10(x));
21+
const base = Math.pow(10, exponent);
22+
const fraction = x / base;
23+
for (const m of allowedMultipliers.slice().reverse()) {
24+
if (m <= fraction) {
25+
return Math.floor(m * base);
26+
}
27+
}
28+
return Math.floor(10 * base);
29+
}
30+
1631
export function roundUpNice(x: number) {
1732
if (x <= 0) {
1833
return x;
@@ -22,10 +37,10 @@ export function roundUpNice(x: number) {
2237
const fraction = x / base;
2338
for (const m of allowedMultipliers) {
2439
if (m >= fraction) {
25-
return Math.round(m * base);
40+
return Math.ceil(m * base);
2641
}
2742
}
28-
return Math.round(10 * base);
43+
return Math.ceil(10 * base);
2944
}
3045

3146
export function roundNearestNice(x: number) {
@@ -51,11 +66,14 @@ export function spacedLogValues(min: number, max: number, steps: number) {
5166
if (steps < 2) {
5267
return [];
5368
}
69+
if (steps > max - min) {
70+
steps = max - min + 1;
71+
}
5472

5573
if (min === 0) {
5674
const nonzeroCount = steps - 1;
57-
const exponent = Math.floor(Math.log10(max)) - (nonzeroCount - 1);
58-
const lowerNonZero = roundNearestNice(Math.pow(10, exponent));
75+
const exponent = Math.log10(max) / (nonzeroCount - 1);
76+
const lowerNonZero = roundDownNice(Math.pow(10, exponent));
5977
const upperTick = roundUpNice(max);
6078
const r = Math.pow(upperTick / lowerNonZero, 1 / (nonzeroCount - 1));
6179
const ticks = [0];
@@ -65,7 +83,7 @@ export function spacedLogValues(min: number, max: number, steps: number) {
6583
}
6684
return ticks;
6785
} else {
68-
const lowerTick = roundUpNice(min);
86+
const lowerTick = roundNearestNice(min);
6987
const upperTick = roundUpNice(max);
7088
const r = Math.pow(upperTick / lowerTick, 1 / (steps - 1));
7189
const ticks = [];

src/ui/lib/components/Charts/MetricLine/MetricLine.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export const Component: FC<MetricLineProps> = ({
5959
xScale={{ type: 'linear', min: minX }}
6060
yScale={{
6161
type: yScaleType,
62-
min: 'auto',
63-
max: 'auto',
62+
min: minY,
63+
max: maxY,
6464
...extraYScaleOptions,
6565
}}
6666
axisBottom={null}

src/ui/lib/components/PageHeader/PageHeader.component.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ const Component = () => {
3232
variant="metric2"
3333
withTooltip
3434
/>
35-
<SpecBadge
35+
{/*<SpecBadge
3636
label="Model size"
3737
value={data?.model?.size ? `${modelSize?.size} ${modelSize?.units}` : '0B'}
3838
variant="body1"
39-
/>
39+
/>*/}
4040
</HeaderCell>
4141
{/*<HeaderCell item xs={2} withDivider>*/}
4242
{/* <SpecBadge*/}
@@ -62,10 +62,10 @@ const Component = () => {
6262
{/* key="Version"*/}
6363
{/* />*/}
6464
{/*</HeaderCell>*/}
65-
<HeaderCell item xs={2} withDivider>
65+
{/*<HeaderCell item xs={2} withDivider>
6666
<SpecBadge label="Task" value={data?.task || 'n/a'} variant="metric2" />
67-
</HeaderCell>
68-
<HeaderCell item xs={3} withDivider>
67+
</HeaderCell>*/}
68+
{/*<HeaderCell item xs={3} withDivider>
6969
<SpecBadge
7070
label="Dataset"
7171
value={data?.dataset?.name || 'n/a'}
@@ -78,7 +78,7 @@ const Component = () => {
7878
</Link>
7979
}
8080
/>
81-
</HeaderCell>
81+
</HeaderCell>*/}
8282
<HeaderCell item xs={2} sx={{ paddingRight: 0 }}>
8383
<SpecBadge
8484
label="Time Stamp"

0 commit comments

Comments
 (0)