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(
|
export const measureTextWidth = memoize(
|
||||||
(text: string | number, font: any = {}) => {
|
(text: string | number, font: any = {}) => {
|
||||||
if (!isServer) {
|
if (!isServer) {
|
||||||
const { fontSize, fontFamily = 'sans-serif', fontWeight, fontStyle, fontVariant } = font;
|
const { fontSize, fontFamily = 'Roobert_Pro', fontWeight, fontStyle, fontVariant } = font;
|
||||||
const ctx = getCanvasContext();
|
const ctx = getCanvasContext();
|
||||||
// @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/font
|
// @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/font
|
||||||
ctx.font = [fontStyle, fontWeight, fontVariant, `${fontSize || 13.6}px`, fontFamily].join(
|
ctx.font = [fontStyle, fontWeight, fontVariant, `${fontSize || 13.6}px`, fontFamily].join(
|
||||||
|
|
|
@ -34,7 +34,7 @@ const getDefaultColumnWidth = (
|
||||||
const longestString = rows.reduce((acc, curr) => {
|
const longestString = rows.reduce((acc, curr) => {
|
||||||
const currString = cellFormat(curr[field], field);
|
const currString = cellFormat(curr[field], field);
|
||||||
if (!currString) return acc;
|
if (!currString) return acc;
|
||||||
return acc.length > currString.length ? acc : currString;
|
return String(acc).length > String(currString).length ? acc : currString;
|
||||||
}, headerString);
|
}, headerString);
|
||||||
const longestWidth = measureTextWidth(longestString).width + OFFSET;
|
const longestWidth = measureTextWidth(longestString).width + OFFSET;
|
||||||
return clamp(longestWidth, MIN_COLUMN_WIDTH, MAX_COLUMN_WIDTH);
|
return clamp(longestWidth, MIN_COLUMN_WIDTH, MAX_COLUMN_WIDTH);
|
||||||
|
|
Loading…
Reference in New Issue