Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cartesian): timeslip preparation #1286

Merged
merged 42 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
52f16ad
chore: reverted earlier pr change
monfera Aug 5, 2021
74fdba5
refactor: simpler rendering code
monfera Aug 5, 2021
9ba5b74
refactor: simpler rendering code 2
monfera Aug 5, 2021
8981cbc
refactor: renderText is already wrapped in withContext
monfera Aug 5, 2021
6821d7a
refactor: withRotatedOrigin already wraps via withContext
monfera Aug 5, 2021
f0d5781
chore: no need for condition
monfera Aug 5, 2021
5c8f5d5
refactor: minor spread rework
monfera Aug 5, 2021
1cb5378
refactor: removed unneeded variable
monfera Aug 5, 2021
182467d
fix: removed unneeded type assertion and incompatible values
monfera Aug 5, 2021
88da853
chore: no need for type assertion
monfera Aug 6, 2021
0812b65
fix: remove duplicated property from the internal type
monfera Aug 6, 2021
aea4d6f
chore: unpublish getRadians
monfera Aug 6, 2021
56614ff
refactor: switched to clearer name
monfera Aug 6, 2021
6bf5217
refactor: transform simplification and centralization in one place
monfera Aug 6, 2021
c87253b
refactor: simpler type and fewer consing
monfera Aug 6, 2021
f80bd56
refactor: font augment
monfera Aug 6, 2021
4bbabfc
chore: removed unneeded save/restore pair
monfera Aug 6, 2021
a9d3149
refactor: minor
monfera Aug 6, 2021
86bb2d3
refactor: simpler rect
monfera Aug 6, 2021
6ab5a43
refactor: removed redundant rect op
monfera Aug 6, 2021
49ab439
refactor: minor rect simplifications
monfera Aug 6, 2021
02c1d5d
test: mock update noise
monfera Aug 6, 2021
c62e84a
refactor: rename
monfera Aug 6, 2021
4c11f79
fix: still render min stroke width
monfera Aug 6, 2021
48d9279
refactor: we never not call with fill and stroke
monfera Aug 6, 2021
bab9e01
refactor: spread rect properties
monfera Aug 6, 2021
a90af82
refactor: spread some other properties
monfera Aug 6, 2021
7dcd02a
fix: brush update
monfera Aug 6, 2021
68fcf6d
fix: discontinued million by million sized pattern fill
monfera Aug 7, 2021
e33c2ab
test: mock updates
monfera Aug 7, 2021
82619f6
refactor: minor rename
monfera Aug 7, 2021
aced8f6
refactor: dry for transform
monfera Aug 7, 2021
a3acdec
refactor: single use non documentational variable inlined and returns…
monfera Aug 7, 2021
11cee41
refactor: flipped if for common case
monfera Aug 7, 2021
39425e0
refactor: single element curlies removed
monfera Aug 7, 2021
9351126
fix: restored lineCap
monfera Aug 7, 2021
b738caa
Merge remote-tracking branch 'origin/master' into timeslip-prep
monfera Aug 16, 2021
d1d1bdd
chore: merge of rect change from #1281 into this pr
monfera Aug 16, 2021
6837ebb
chore: also check the width
monfera Aug 16, 2021
b8608c3
test: also check the width vrt image update
monfera Aug 16, 2021
9eb6665
Merge branch 'master' into timeslip-prep
nickofthyme Aug 16, 2021
8437716
Merge branch 'master' into timeslip-prep
monfera Aug 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 11 additions & 8 deletions packages/charts/api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,12 @@ export type FitConfig = {
endValue?: number | 'nearest';
};

// @public (undocumented)
export const FONT_STYLES: readonly ["normal", "italic", "oblique", "inherit", "initial", "unset"];

// @public (undocumented)
export type FontStyle = typeof FONT_STYLES[number];

nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
// @public
export interface GeometryStateStyle {
opacity: number;
Expand Down Expand Up @@ -900,7 +906,6 @@ export interface HeatmapConfig {
label: Font & {
fontSize: Pixels;
maxWidth: Pixels | 'fill';
fill: string;
align: TextAlign;
baseline: TextBaseline;
visible: boolean;
Expand Down Expand Up @@ -959,7 +964,6 @@ export interface HeatmapConfig {
name: string;
fontSize: Pixels;
width: Pixels | 'auto';
fill: string;
align: TextAlign;
baseline: TextBaseline;
visible: boolean;
Expand All @@ -973,7 +977,6 @@ export interface HeatmapConfig {
width: Pixels | 'auto' | {
max: Pixels;
};
fill: string;
baseline: TextBaseline;
visible: boolean;
padding: number | {
Expand Down Expand Up @@ -1996,7 +1999,7 @@ export interface TextStyle {
// (undocumented)
fontSize: number;
// (undocumented)
fontStyle?: string;
fontStyle?: FontStyle;
// (undocumented)
padding: number | SimplePadding;
}
Expand Down Expand Up @@ -2253,7 +2256,7 @@ export interface WordcloudConfigs {
// (undocumented)
fontFamily: string;
// (undocumented)
fontStyle: string;
fontStyle: FontStyle;
// (undocumented)
fontWeight: number;
// (undocumented)
Expand Down Expand Up @@ -2294,7 +2297,7 @@ export interface WordcloudSpec extends Spec {
// (undocumented)
fontFamily: string;
// (undocumented)
fontStyle: string;
fontStyle: FontStyle;
// (undocumented)
fontWeight: number;
// (undocumented)
Expand Down Expand Up @@ -2368,8 +2371,8 @@ export type YDomainRange = YDomainBase & DomainRange & LogScaleOptions;
// Warnings were encountered during analysis:
//
// src/chart_types/heatmap/layout/types/config_types.ts:20:13 - (ae-forgotten-export) The symbol "SizeRatio" needs to be exported by the entry point index.d.ts
// src/chart_types/heatmap/layout/types/config_types.ts:52:5 - (ae-forgotten-export) The symbol "TextAlign" needs to be exported by the entry point index.d.ts
// src/chart_types/heatmap/layout/types/config_types.ts:53:5 - (ae-forgotten-export) The symbol "TextBaseline" needs to be exported by the entry point index.d.ts
// src/chart_types/heatmap/layout/types/config_types.ts:51:5 - (ae-forgotten-export) The symbol "TextAlign" needs to be exported by the entry point index.d.ts
// src/chart_types/heatmap/layout/types/config_types.ts:52:5 - (ae-forgotten-export) The symbol "TextBaseline" needs to be exported by the entry point index.d.ts
// src/chart_types/partition_chart/layout/types/config_types.ts:139:5 - (ae-forgotten-export) The symbol "TimeMs" needs to be exported by the entry point index.d.ts
// src/chart_types/partition_chart/layout/types/config_types.ts:140:5 - (ae-forgotten-export) The symbol "AnimKeyframe" needs to be exported by the entry point index.d.ts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const config: Config = {
name: 'X Value',
visible: true,
width: 'auto',
fill: 'black',
fontSize: 12,
fontFamily: 'Sans-Serif',
fontStyle: 'normal',
Expand All @@ -58,7 +57,6 @@ export const config: Config = {
name: 'Y Value',
visible: true,
width: 'auto',
fill: 'black',
fontSize: 12,
fontFamily: 'Sans-Serif',
fontStyle: 'normal',
Expand Down Expand Up @@ -91,7 +89,6 @@ export const config: Config = {
label: {
visible: true,
maxWidth: 'fill',
fill: 'black',
fontSize: 10,
fontFamily: 'Sans-Serif',
fontStyle: 'normal',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export interface Config {
name: string;
fontSize: Pixels;
width: Pixels | 'auto';
fill: string;
align: TextAlign;
baseline: TextBaseline;
visible: boolean;
Expand All @@ -59,7 +58,6 @@ export interface Config {
name: string;
fontSize: Pixels;
width: Pixels | 'auto' | { max: Pixels };
fill: string;
baseline: TextBaseline;
visible: boolean;
padding: number | { left?: number; right?: number; top?: number; bottom?: number };
Expand All @@ -86,7 +84,6 @@ export interface Config {
label: Font & {
fontSize: Pixels;
maxWidth: Pixels | 'fill';
fill: string;
align: TextAlign;
baseline: TextBaseline;
visible: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { $Values as Values } from 'utility-types';

import { Pixels, PointObject, Rectangle } from '../../../../common/geometry';
import { FontStyle } from '../../../../common/text_utils';
import { Color } from '../../../../utils/common';
import { config } from '../config/config';
import { Config } from './config_types';
Expand Down Expand Up @@ -58,7 +59,7 @@ export interface Configs {
endAngle: number;
exponent: number;
fontFamily: string;
fontStyle: string;
fontStyle: FontStyle;
fontWeight: number;
height: number;
maxFontSize: number;
Expand All @@ -81,7 +82,7 @@ export interface WordcloudViewModel {
padding: number;
fontWeight: number;
fontFamily: string;
fontStyle: string;
fontStyle: FontStyle;
minFontSize: number;
maxFontSize: number;
spiral: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/charts/src/chart_types/wordcloud/specs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';

import { ChartType } from '../..';
import { FontStyle } from '../../../common/text_utils';
import { Spec } from '../../../specs';
import { SpecType } from '../../../specs/constants';
import { getConnect, specComponentFactory } from '../../../state/spec_factory';
Expand Down Expand Up @@ -42,7 +43,7 @@ export interface WordcloudSpec extends Spec {
padding: number;
fontWeight: number;
fontFamily: string;
fontStyle: string;
fontStyle: FontStyle;
minFontSize: number;
maxFontSize: number;
spiral: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { renderTickLabel } from './tick_label';

/** @internal */
export interface AxisProps {
panelTitle?: string | undefined;
panelTitle?: string;
secondary?: boolean;
panelAnchor: Point;
axisStyle: AxisStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,103 +7,59 @@
*/

import { AxisProps } from '.';
import { Font, FontStyle } from '../../../../../common/text_utils';
import { withContext } from '../../../../../renderers/canvas';
import { AxisTick, getTickLabelProps } from '../../../utils/axis_utils';
import { renderText } from '../primitives/text';
import { renderDebugRectCenterRotated } from '../utils/debug';

/** @internal */
export function renderTickLabel(ctx: CanvasRenderingContext2D, tick: AxisTick, showTicks: boolean, props: AxisProps) {
const {
axisSpec: { position, labelFormat },
dimension: axisTicksDimensions,
size,
debug,
axisStyle,
} = props;
export function renderTickLabel(
ctx: CanvasRenderingContext2D,
tick: AxisTick,
showTicks: boolean,
{ axisSpec: { position, labelFormat }, dimension, size, debug, axisStyle }: AxisProps,
) {
const labelStyle = axisStyle.tickLabel;
const { rotation: tickLabelRotation, alignment, offset } = labelStyle;

const { maxLabelBboxWidth, maxLabelBboxHeight, maxLabelTextWidth, maxLabelTextHeight } = axisTicksDimensions;
const { x, y, offsetX, offsetY, textOffsetX, textOffsetY, horizontalAlign, verticalAlign } = getTickLabelProps(
const tickLabelProps = getTickLabelProps(
axisStyle,
tick.position,
position,
tickLabelRotation,
labelStyle.rotation,
size,
axisTicksDimensions,
dimension,
showTicks,
offset,
alignment,
labelStyle.offset,
labelStyle.alignment,
);

const center = { x: tickLabelProps.x + tickLabelProps.offsetX, y: tickLabelProps.y + tickLabelProps.offsetY };

if (debug) {
const { maxLabelBboxWidth, maxLabelBboxHeight, maxLabelTextWidth: width, maxLabelTextHeight: height } = dimension;
// full text container
renderDebugRectCenterRotated(
ctx,
{
x: x + offsetX,
y: y + offsetY,
},
{
x: x + offsetX,
y: y + offsetY,
height: maxLabelTextHeight,
width: maxLabelTextWidth,
},
undefined,
undefined,
tickLabelRotation,
);
renderDebugRectCenterRotated(ctx, center, { ...center, width, height }, undefined, undefined, labelStyle.rotation);
// rotated text container
if (![0, -90, 90, 180].includes(tickLabelRotation)) {
renderDebugRectCenterRotated(
ctx,
{
x: x + offsetX,
y: y + offsetY,
},
{
x: x + offsetX,
y: y + offsetY,
height: maxLabelBboxHeight,
width: maxLabelBboxWidth,
},
undefined,
undefined,
0,
);
if (labelStyle.rotation % 90 !== 0) {
renderDebugRectCenterRotated(ctx, center, { ...center, width: maxLabelBboxWidth, height: maxLabelBboxHeight });
}
}
const font: Font = {
fontFamily: labelStyle.fontFamily,
fontStyle: labelStyle.fontStyle ? (labelStyle.fontStyle as FontStyle) : 'normal',
fontVariant: 'normal',
fontWeight: 'normal',
textColor: labelStyle.fill,
textOpacity: 1,
};
withContext(ctx, (ctx) => {
renderText(
ctx,
{
x: x + offsetX,
y: y + offsetY,
},
labelFormat ? labelFormat(tick.value) : tick.label,
{
...font,
fontSize: labelStyle.fontSize,
fill: labelStyle.fill,
align: horizontalAlign as CanvasTextAlign,
baseline: verticalAlign as CanvasTextBaseline,
},
tickLabelRotation,
{
x: textOffsetX,
y: textOffsetY,
},
);
});

renderText(
ctx,
center,
labelFormat ? labelFormat(tick.value) : tick.label,
{
fontFamily: labelStyle.fontFamily,
fontStyle: labelStyle.fontStyle ?? 'normal',
fontVariant: 'normal',
fontWeight: 'normal',
textColor: labelStyle.fill,
textOpacity: 1,
fontSize: labelStyle.fontSize,
align: tickLabelProps.horizontalAlign,
baseline: tickLabelProps.verticalAlign,
},
labelStyle.rotation,
tickLabelProps.textOffsetX,
tickLabelProps.textOffsetY,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
* Side Public License, v 1.
*/

import { FontStyle } from '../../../../../common/text_utils';
import { Position } from '../../../../../utils/common';
import { getSimplePadding } from '../../../../../utils/dimensions';
import { AxisStyle } from '../../../../../utils/themes/theme'; // todo revise if it should rely on axis-anything
import { TextStyle } from '../../../../../utils/themes/theme'; // todo revise if it should rely on axis-anything
import { isHorizontalAxis } from '../../../utils/axis_type_utils';
import { getTitleDimension, shouldShowTicks } from '../../../utils/axis_utils';
import { AxisProps } from '../axes';
Expand Down Expand Up @@ -114,20 +113,14 @@ function renderHorizontalTitle(ctx: CanvasRenderingContext2D, props: PanelTitleP
}

/** @internal */
export function getFontStyle({
fontFamily,
fontStyle,
fill,
fontSize,
}: AxisStyle['axisTitle'] | AxisStyle['axisPanelTitle']): TextFont {
export function getFontStyle({ fontFamily, fontStyle, fill, fontSize }: TextStyle): TextFont {
return {
fontFamily,
fontVariant: 'normal',
fontStyle: fontStyle ? (fontStyle as FontStyle) : 'normal',
fontWeight: 'normal',
fontStyle: fontStyle ?? 'normal',
fontWeight: 'bold',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could introduce an API option for font weight instead, then this bold can go back into the theme

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea

textColor: fill,
textOpacity: 1,
fill,
align: 'center',
baseline: 'middle',
fontSize,
Expand Down
Loading