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

fix: do not ignore config.title.angle/limit #7667

Merged
merged 2 commits into from Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compile/model.ts
Expand Up @@ -408,7 +408,7 @@ export abstract class Model {
const {encoding, ...titleNoEncoding} = this.title ?? ({} as TitleParams<SignalRef>);

const title: VgTitle = {
...extractTitleConfig(this.config.title).nonMark,
...extractTitleConfig(this.config.title).nonMarkTitleProperties,
...titleNoEncoding,
...(encoding ? {encode: {update: encoding}} : {})
};
Expand Down
15 changes: 10 additions & 5 deletions src/title.ts
Expand Up @@ -65,7 +65,8 @@ export interface TitleParams<ES extends ExprRef | SignalRef> extends TitleBase<E
export function extractTitleConfig(titleConfig: TitleConfig<SignalRef>): {
titleMarkConfig: MarkConfig<SignalRef>;
subtitleMarkConfig: MarkConfig<SignalRef>;
nonMark: BaseTitleNoValueRefs<SignalRef>;
/** These are non-mark title config that need to be hardcoded in the title directive. */
nonMarkTitleProperties: BaseTitleNoValueRefs<SignalRef>;
subtitle: BaseTitleNoValueRefs<SignalRef>;
} {
const {
Expand All @@ -74,6 +75,8 @@ export function extractTitleConfig(titleConfig: TitleConfig<SignalRef>): {
frame,
offset,
orient,
angle,
limit,

// color needs to be redirect to fill
color,
Expand All @@ -97,11 +100,13 @@ export function extractTitleConfig(titleConfig: TitleConfig<SignalRef>): {
};

// These are non-mark title config that need to be hardcoded
const nonMark: BaseTitleNoValueRefs<SignalRef> = {
const nonMarkTitleProperties: BaseTitleNoValueRefs<SignalRef> = {
...(anchor ? {anchor} : {}),
...(frame ? {frame} : {}),
...(offset ? {offset} : {}),
...(orient ? {orient} : {})
...(orient ? {orient} : {}),
...(angle !== undefined ? {angle} : {}),
...(limit !== undefined ? {limit} : {})
};

// subtitle part can stay in config.title since header titles do not use subtitle
Expand All @@ -115,9 +120,9 @@ export function extractTitleConfig(titleConfig: TitleConfig<SignalRef>): {
...(subtitlePadding ? {subtitlePadding} : {})
};

const subtitleMarkConfig = pick(titleMarkConfig, ['align', 'baseline', 'dx', 'dy', 'limit']);
const subtitleMarkConfig = pick(titleConfig, ['align', 'baseline', 'dx', 'dy', 'limit']);

return {titleMarkConfig, subtitleMarkConfig, nonMark, subtitle};
return {titleMarkConfig, subtitleMarkConfig, nonMarkTitleProperties: nonMarkTitleProperties, subtitle};
}

export function isText(v: any): v is Text {
Expand Down
1 change: 1 addition & 0 deletions test/config.test.ts
Expand Up @@ -166,6 +166,7 @@ describe('config', () => {
baseline: 'middle',
dx: 5,
dy: 5,
angle: 1,
limit: 5
},
boxplot: {
Expand Down
8 changes: 8 additions & 0 deletions test/title.test.ts
@@ -0,0 +1,8 @@
import {extractTitleConfig} from '../src/title';
describe('title', () => {
describe('extractTitleConfig', () => {
it('extract angle and limit of config.title as title property', () => {
expect(extractTitleConfig({angle: 1, limit: 5}).nonMarkTitleProperties).toEqual({angle: 1, limit: 5});
});
});
});