mirror of https://github.com/buster-so/buster.git
Merge pull request #306 from buster-so/nate/fix-broken-widths-measure
fix broken measure
This commit is contained in:
commit
62d92c92ac
|
@ -14,7 +14,7 @@ const getCanvasContext = () => {
|
|||
export const measureTextWidth = memoize(
|
||||
(text: string | number, font: any = {}) => {
|
||||
if (!isServer) {
|
||||
const { fontSize, fontFamily = 'sans-serif', fontWeight, fontStyle, fontVariant } = font;
|
||||
const { fontSize, fontFamily = 'Roobert_Pro', fontWeight, fontStyle, fontVariant } = font;
|
||||
const ctx = getCanvasContext();
|
||||
// @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/font
|
||||
ctx.font = [fontStyle, fontWeight, fontVariant, `${fontSize || 13.6}px`, fontFamily].join(
|
||||
|
|
|
@ -34,7 +34,7 @@ const getDefaultColumnWidth = (
|
|||
const longestString = rows.reduce((acc, curr) => {
|
||||
const currString = cellFormat(curr[field], field);
|
||||
if (!currString) return acc;
|
||||
return acc.length > currString.length ? acc : currString;
|
||||
return String(acc).length > String(currString).length ? acc : currString;
|
||||
}, headerString);
|
||||
const longestWidth = measureTextWidth(longestString).width + OFFSET;
|
||||
return clamp(longestWidth, MIN_COLUMN_WIDTH, MAX_COLUMN_WIDTH);
|
||||
|
|
Loading…
Reference in New Issue