Skip to content

Commit

Permalink
Merge pull request #443 from deneb-viz/bugfix/erroneous-config
Browse files Browse the repository at this point in the history
fix: correct config for inbuilt templates (#434)
  • Loading branch information
dm-p committed May 17, 2024
2 parents 2d61b6a + 252859a commit d8001bc
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 48 deletions.
7 changes: 7 additions & 0 deletions src/features/template/included/vega-lite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { vlEmpty } from './vl-empty';
import { vlEmptyConfig } from './vl-empty-config';
import { vlBarSimple } from './vl-bar-simple';
import { vlBarInteractive } from './vl-bar-interactive';
import { powerbiTheme } from '../../../vega-extensibility';

/**
* Included Vega templates (for use in the create process).
Expand All @@ -22,3 +23,9 @@ export const VEGA_LITE_INCLUDED_TEMPLATES = [
vlBarSimple,
vlBarInteractive
];

/**
* Adds the Power BI themeing for Vega-Lite as a formatted string to templates that need it.
*/
export const getTemplatePowerBiConfigVl = () =>
JSON.stringify(powerbiTheme(), null, 2);
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const dataset: UsermetaDatasetField[] = [
export const vlBarInteractive = (): TopLevelSpec => ({
$schema: VEGA_LITE_SCHEMA_URL,
data: getDenebTemplateDatasetRef(),
config: {},
layer: [
{
mark: {
Expand Down
1 change: 0 additions & 1 deletion src/features/template/included/vega-lite/vl-bar-simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const dataset: UsermetaDatasetField[] = [
export const vlBarSimple = (): TopLevelSpec => ({
$schema: VEGA_LITE_SCHEMA_URL,
data: getDenebTemplateDatasetRef(),
config: {},
mark: {
type: 'bar'
},
Expand Down
19 changes: 10 additions & 9 deletions src/features/template/included/vega-lite/vl-empty-config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Config, TopLevelSpec } from 'vega-lite';
import { TopLevelSpec } from 'vega-lite';

import { VEGA_LITE_SCHEMA_URL } from '.';
import { VEGA_LITE_SCHEMA_URL, getTemplatePowerBiConfigVl } from '.';
import { getDenebTemplateDatasetRef, getNewIncludedTemplateMetadata } from '..';
import { powerbiTheme } from '../../../vega-extensibility/extensibility/powerbi-theme';

export const vlEmptyConfig = (): TopLevelSpec => ({
$schema: VEGA_LITE_SCHEMA_URL,
data: getDenebTemplateDatasetRef(),
config: { ...powerbiTheme() } as Config,
layer: [],
usermeta: getNewIncludedTemplateMetadata(
'vegaLite',
'[empty (with Power BI theming)]',
'Bare-minimum Vega-Lite template, with data-binding pre-populated. Contains configuration defaults for marks and axes to provide a Power BI-like look and feel.'
)
usermeta: {
...getNewIncludedTemplateMetadata(
'vegaLite',
'[empty (with Power BI theming)]',
'Bare-minimum Vega-Lite template, with data-binding pre-populated. Contains configuration defaults for marks and axes to provide a Power BI-like look and feel.'
),
config: getTemplatePowerBiConfigVl()
}
});
1 change: 0 additions & 1 deletion src/features/template/included/vega-lite/vl-empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { getDenebTemplateDatasetRef, getNewIncludedTemplateMetadata } from '..';
export const vlEmpty = (): TopLevelSpec => ({
$schema: VEGA_LITE_SCHEMA_URL,
data: getDenebTemplateDatasetRef(),
config: {},
layer: [],
usermeta: getNewIncludedTemplateMetadata(
'vegaLite',
Expand Down
16 changes: 11 additions & 5 deletions src/features/template/included/vega/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Vega-Lite templates that are included with Deneb.
* Vega templates that are included with Deneb.
*/
import { Config } from 'vega';
import { getDenebTemplateDatasetRef } from '..';
import { PROVIDER_RESOURCES } from '../../../../../config';
import { powerBiThemeVega } from '../../../vega-extensibility';

/**
* Schema URL for all templates.
Expand All @@ -21,9 +21,15 @@ export const getDenebTemplateVegaDatasetRef = () => [
/**
* For Vega, we need to add some extra configuration, so we'll do this here.
*/
export const getDenebTemplateVegaSpecificConfig = (): Config => ({
autosize: { contains: 'padding', type: 'fit' }
});
export const getDenebTemplateVegaSpecificConfig = (includeTheme = false) =>
JSON.stringify(
{
autosize: { contains: 'padding', type: 'fit' },
...(includeTheme && powerBiThemeVega())
},
null,
2
);

import { vEmpty } from './v-empty';
import { vEmptyConfig } from './v-empty-config';
Expand Down
4 changes: 2 additions & 2 deletions src/features/template/included/vega/v-bar-interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const dataset: UsermetaDatasetField[] = [
export const vBarInteractive = (): Spec => ({
$schema: VEGA_SCHEMA_URL,
data: getDenebTemplateVegaDatasetRef(),
config: { ...getDenebTemplateVegaSpecificConfig() },
scales: [
{
name: 'yscale',
Expand Down Expand Up @@ -153,7 +152,8 @@ export const vBarInteractive = (): Spec => ({
highlight: true,
selection: true,
dataPointLimit: PROPERTIES_DEFAULTS.vega.selectionMaxDataPoints
}
},
config: getDenebTemplateVegaSpecificConfig()
}
}
});
3 changes: 1 addition & 2 deletions src/features/template/included/vega/v-bar-simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const dataset: UsermetaDatasetField[] = [
export const vBarSimple = (): Spec => ({
$schema: VEGA_SCHEMA_URL,
data: getDenebTemplateVegaDatasetRef(),
config: { ...getDenebTemplateVegaSpecificConfig() },
scales: [
{
name: 'yscale',
Expand Down Expand Up @@ -102,6 +101,6 @@ export const vBarSimple = (): Spec => ({
'A simple bar chart for a category and a measure.',
'vBarSimple'
),
...{ dataset }
...{ dataset, config: getDenebTemplateVegaSpecificConfig() }
}
});
23 changes: 14 additions & 9 deletions src/features/template/included/vega/v-empty-config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { Config, Spec } from 'vega';
import { Spec } from 'vega';

import { getDenebTemplateVegaDatasetRef, VEGA_SCHEMA_URL } from '.';
import {
getDenebTemplateVegaDatasetRef,
getDenebTemplateVegaSpecificConfig,
VEGA_SCHEMA_URL
} from '.';
import { getNewIncludedTemplateMetadata } from '..';
import { powerBiThemeVega } from '../../../vega-extensibility/extensibility/powerbi-theme';

export const vEmptyConfig = (): Spec => ({
$schema: VEGA_SCHEMA_URL,
data: getDenebTemplateVegaDatasetRef(),
config: { ...powerBiThemeVega() } as Config,
marks: [],
usermeta: getNewIncludedTemplateMetadata(
'vega',
'[empty (with Power BI theming)]',
'Bare-minimum Vega template, with data-binding pre-populated. Contains configuration defaults for marks and axes to provide a Power BI-like look and feel.'
)
usermeta: {
...getNewIncludedTemplateMetadata(
'vega',
'[empty (with Power BI theming)]',
'Bare-minimum Vega template, with data-binding pre-populated. Contains configuration defaults for marks and axes to provide a Power BI-like look and feel.'
),
config: getDenebTemplateVegaSpecificConfig(true)
}
});
20 changes: 13 additions & 7 deletions src/features/template/included/vega/v-empty.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { Spec } from 'vega';

import { getDenebTemplateVegaDatasetRef, VEGA_SCHEMA_URL } from '.';
import {
getDenebTemplateVegaDatasetRef,
getDenebTemplateVegaSpecificConfig,
VEGA_SCHEMA_URL
} from '.';
import { getNewIncludedTemplateMetadata } from '..';

export const vEmpty = (): Spec => ({
$schema: VEGA_SCHEMA_URL,
data: getDenebTemplateVegaDatasetRef(),
config: {},
marks: [],
usermeta: getNewIncludedTemplateMetadata(
'vega',
'[empty]',
'Bare-minimum Vega template, with data-binding pre-populated. Has no additional configuration for styling.'
)
usermeta: {
...getNewIncludedTemplateMetadata(
'vega',
'[empty]',
'Bare-minimum Vega template, with data-binding pre-populated. Has no additional configuration for styling.'
),
config: getDenebTemplateVegaSpecificConfig()
}
});
2 changes: 1 addition & 1 deletion src/features/vega-extensibility/extensibility/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { registerCustomExpressions } from './expressions';
import { registerCustomSchemes } from './schemes';

export { getTemplateWithBasePowerBiTheme } from './powerbi-theme';
export { powerbiTheme, powerBiThemeVega } from './powerbi-theme';

/**
* Use declare and initialize the service to ensure that it is available for
Expand Down
12 changes: 2 additions & 10 deletions src/features/vega-extensibility/extensibility/powerbi-theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Config as VgConfig, Spec } from 'vega';
import { Config as VlConfig, TopLevelSpec } from 'vega-lite';
import merge from 'lodash/merge';
import { Config as VgConfig } from 'vega';
import { Config as VlConfig } from 'vega-lite';
import { interpolateHcl, interpolateRgbBasis, quantize } from 'd3';

import { ptToPx } from '../../../core/ui/dom';
Expand Down Expand Up @@ -90,13 +89,6 @@ export const powerBiThemeVega = () =>
}
} as VgConfig);

/**
* Merge supplied template with base theme config
*/
export const getTemplateWithBasePowerBiTheme = (
template: Spec | TopLevelSpec
): Spec | TopLevelSpec => merge(template, { config: powerbiTheme() });

/**
* Helper function to extract palette color by (zero-based) index.
*/
Expand Down

0 comments on commit d8001bc

Please sign in to comment.