Skip to content

Commit

Permalink
simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Sep 1, 2023
1 parent 204d737 commit e2d1173
Showing 1 changed file with 6 additions and 32 deletions.
38 changes: 6 additions & 32 deletions src/marks/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function boxX(
barX(data, group({x1: "p25", x2: "p75"}, {x, y, fill, fillOpacity, ...options})),
tickX(data, group({x: "p50"}, {x, y, stroke, strokeOpacity, strokeWidth, sort, ...options})),
dot(data, map({x: oqr}, {x, y, z: y, stroke, strokeOpacity, ...options})),
tip && tipmark(data, pointerY(group({x: "median", title: boxStats}, {x, y, z: y, title: x, ...options})))
tip && tipmark(data, pointerY(group({x: "p50", title: boxStats}, {x, y, z: y, title: x, ...options})))
);
}

Expand All @@ -61,7 +61,7 @@ export function boxY(
barY(data, group({y1: "p25", y2: "p75"}, {x, y, fill, fillOpacity, ...options})),
tickY(data, group({y: "p50"}, {x, y, stroke, strokeOpacity, strokeWidth, sort, ...options})),
dot(data, map({y: oqr}, {x, y, z: x, stroke, strokeOpacity, ...options})),
tip && tipmark(data, pointerX(group({y: "median", title: boxStats}, {x, y, z: x, title: y, ...options})))
tip && tipmark(data, pointerX(group({y: "p50", title: boxStats}, {x, y, z: x, title: y, ...options})))
);
}

Expand Down Expand Up @@ -109,41 +109,15 @@ function boxStats(values) {
break;
}
}
let _loqr1 = 0;
let _hiqr2 = 0;
let _q1 = 0;
let _q2 = 0;
let _q3 = 0;
for (const d of V) {
switch (true) {
case d < loqr1:
_loqr1++;
// eslint-disable-next-line no-fallthrough
case d <= q1:
_q1++;
// eslint-disable-next-line no-fallthrough
case d <= q2:
_q2++;
// eslint-disable-next-line no-fallthrough
case d <= q3:
_q3++;
// eslint-disable-next-line no-fallthrough
case d <= hiqr2:
break;
default:
_hiqr2++;
}
}
const f = formatDefault;
return (
q1 === q3
? [f(q2)]
: [
loqr1 < q2 && `${f(_loqr1)}# < ${f(loqr1)}`,
q1 < q2 && `${_q1}# ≤ ${f(q1)}`,
`${_q2}# ≤ ${f(q2)}`,
q3 > q2 && `${_q3}# ≤ ${f(q3)}`,
hiqr2 > q2 && `${f(_hiqr2)}# > ${f(hiqr2)}`
q1 < q2 && `p25: ${f(q1)}`,
`p50: ${f(q2)}`,
q3 > q2 && `p75: ${f(q3)}`,
loqr1 < hiqr2 && `[${f(loqr1)}${f(hiqr2)}]`
]
)
.filter((d) => d)
Expand Down

0 comments on commit e2d1173

Please sign in to comment.