Skip to content

Commit

Permalink
feat: add dimension type (apache#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw authored Mar 11, 2019
1 parent 8c3f8b0 commit e4a22ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/superset-ui-dimension/src/computeMaxFontSize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import getTextDimension, { GetTextDimensionInput } from './getTextDimension';
import { Dimension } from './types';

function decreaseSizeUntil(
startSize: number,
computeDimension: (size: number) => { height: number; width: number },
condition: (dimension: { height: number; width: number }) => boolean,
computeDimension: (size: number) => Dimension,
condition: (dimension: Dimension) => boolean,
): number {
let size = startSize;
let dimension = computeDimension(size);
Expand Down
6 changes: 3 additions & 3 deletions packages/superset-ui-dimension/src/getTextDimension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextStyle } from './types';
import { TextStyle, Dimension } from './types';

const SVG_NS = 'http://www.w3.org/2000/svg';
const STYLE_FIELDS: (keyof TextStyle)[] = [
Expand All @@ -21,8 +21,8 @@ const DEFAULT_DIMENSION = { height: 20, width: 100 };

export default function getTextDimension(
input: GetTextDimensionInput,
defaultDimension = DEFAULT_DIMENSION,
) {
defaultDimension: Dimension = DEFAULT_DIMENSION,
): Dimension {
const { text, className, style = {}, container = document.body } = input;

const textNode = document.createElementNS(SVG_NS, 'text');
Expand Down
5 changes: 5 additions & 0 deletions packages/superset-ui-dimension/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ export interface Margin {
bottom: number;
right: number;
}

export interface Dimension {
width: number;
height: number;
}

0 comments on commit e4a22ad

Please sign in to comment.