Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 22 additions & 21 deletions src/specBuilder/bar/barSpecBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
DEFAULT_CATEGORICAL_DIMENSION,
DEFAULT_COLOR,
DEFAULT_METRIC,
DEFAULT_OPACITY_RULE,
DEFAULT_SECONDARY_COLOR,
FILTERED_TABLE,
MARK_ID,
Expand Down Expand Up @@ -165,15 +166,15 @@ const defaultStackedMark: Mark = {
...defaultStackedYEncodings,
...defaultCornerRadiusEncodings,
fill: { scale: 'color', field: DEFAULT_COLOR },
fillOpacity: DEFAULT_OPACITY_RULE,
tooltip: undefined,
},
update: {
x: { scale: 'xBand', field: DEFAULT_CATEGORICAL_DIMENSION },
...defaultBarStrokeEncodings,
width: { scale: 'xBand', band: 1 },
cursor: undefined,
fillOpacity: [{ value: 1 }],
strokeOpacity: [{ value: 1 }],
opacity: [DEFAULT_OPACITY_RULE],
width: { scale: 'xBand', band: 1 },
x: { scale: 'xBand', field: DEFAULT_CATEGORICAL_DIMENSION },
},
},
};
Expand Down Expand Up @@ -269,7 +270,7 @@ describe('barSpecBuilder', () => {
addSignals([getUncontrolledHoverSignal('bar0'), defaultHoverSignal, defaultSelectSignal], {
...defaultBarProps,
children: [popover],
})
}),
).toStrictEqual([
getUncontrolledHoverSignal('bar0'),
defaultHoverSignal,
Expand Down Expand Up @@ -307,7 +308,7 @@ describe('barSpecBuilder', () => {
range: { signal: 'colors' },
domain: { data: TABLE, fields: [DEFAULT_COLOR] },
},
]
],
);
});

Expand All @@ -323,8 +324,8 @@ describe('barSpecBuilder', () => {
...defaultBarProps,
lineType: DEFAULT_COLOR,
opacity: DEFAULT_COLOR,
}
)
},
),
).toStrictEqual([
defaultColorScale,
{ domain: { data: TABLE, fields: [DEFAULT_COLOR] }, name: 'lineType', type: 'ordinal' },
Expand All @@ -341,7 +342,7 @@ describe('barSpecBuilder', () => {
trellis: 'event',
trellisOrientation: 'vertical',
trellisPadding: 0.5,
})
}),
).toStrictEqual([
defaultColorScale,
defaultMetricScale,
Expand Down Expand Up @@ -434,7 +435,7 @@ describe('barSpecBuilder', () => {
addMarks([], {
...defaultBarProps,
children: [...defaultBarProps.children, annotation],
})
}),
).toStrictEqual([...defaultStackedBarMarks, ...stackedAnnotationMarks]);
});
});
Expand Down Expand Up @@ -466,7 +467,7 @@ describe('barSpecBuilder', () => {
describe('existing data "table"', () => {
test('new transform should be added to the data table', () => {
expect(
addData(defaultData, { ...defaultBarProps, metric: 'views', dimension: 'browser' })
addData(defaultData, { ...defaultBarProps, metric: 'views', dimension: 'browser' }),
).toStrictEqual([
defaultTableData,
{
Expand Down Expand Up @@ -525,7 +526,7 @@ describe('barSpecBuilder', () => {
describe('transform already exists', () => {
test('no props, new transform should be pushed onto the end with default values', () => {
expect(
addData([{ ...defaultFilteredTableData, transform: defaultStackedTransforms }], defaultBarProps)
addData([{ ...defaultFilteredTableData, transform: defaultStackedTransforms }], defaultBarProps),
).toStrictEqual([
{
...defaultFilteredTableData,
Expand All @@ -541,7 +542,7 @@ describe('barSpecBuilder', () => {
const popover = createElement(ChartPopover);
expect(addData(baseData, { ...defaultBarProps, children: [popover] })[1]).toHaveProperty(
'transform',
defaultStackedTransforms
defaultStackedTransforms,
);
});
});
Expand All @@ -552,7 +553,7 @@ describe('barSpecBuilder', () => {
...defaultBarProps,
type: 'dodged',
color: [DEFAULT_COLOR, DEFAULT_SECONDARY_COLOR],
})
}),
).toStrictEqual([
defaultTableData,
{
Expand Down Expand Up @@ -594,7 +595,7 @@ describe('barSpecBuilder', () => {
});
test('stacked dodged', () => {
expect(
addData(defaultData, { ...defaultBarProps, color: [DEFAULT_COLOR, DEFAULT_SECONDARY_COLOR] })
addData(defaultData, { ...defaultBarProps, color: [DEFAULT_COLOR, DEFAULT_SECONDARY_COLOR] }),
).toStrictEqual([
defaultTableData,
{
Expand Down Expand Up @@ -676,7 +677,7 @@ describe('barSpecBuilder', () => {
});

expect(
getStackIdTransform({ ...defaultBarProps, type: 'dodged', opacity: DEFAULT_SECONDARY_COLOR })
getStackIdTransform({ ...defaultBarProps, type: 'dodged', opacity: DEFAULT_SECONDARY_COLOR }),
).toStrictEqual({
as: STACK_ID,
expr: `datum.${DEFAULT_CATEGORICAL_DIMENSION} + "," + datum.${DEFAULT_COLOR} + "," + datum.${DEFAULT_SECONDARY_COLOR}`,
Expand All @@ -688,7 +689,7 @@ describe('barSpecBuilder', () => {
describe('getDodgeGroupTransform()', () => {
test('should join facets together', () => {
expect(
getDodgeGroupTransform({ ...defaultBarProps, type: 'dodged', opacity: DEFAULT_SECONDARY_COLOR })
getDodgeGroupTransform({ ...defaultBarProps, type: 'dodged', opacity: DEFAULT_SECONDARY_COLOR }),
).toStrictEqual({
as: 'bar0_dodgeGroup',
expr: `datum.${DEFAULT_COLOR} + "," + datum.${DEFAULT_SECONDARY_COLOR}`,
Expand All @@ -700,18 +701,18 @@ describe('barSpecBuilder', () => {
describe('getRepeatedScale()', () => {
test('should return a linear scale if the bar and trellis orientations are the same', () => {
expect(
getRepeatedScale({ ...defaultBarProps, orientation: 'horizontal', trellisOrientation: 'horizontal' })
getRepeatedScale({ ...defaultBarProps, orientation: 'horizontal', trellisOrientation: 'horizontal' }),
).toHaveProperty('type', 'linear');
expect(
getRepeatedScale({ ...defaultBarProps, orientation: 'vertical', trellisOrientation: 'vertical' })
getRepeatedScale({ ...defaultBarProps, orientation: 'vertical', trellisOrientation: 'vertical' }),
).toHaveProperty('type', 'linear');
});
test('should return a band scale if the bar and trellis orientations are not the same', () => {
expect(
getRepeatedScale({ ...defaultBarProps, orientation: 'horizontal', trellisOrientation: 'vertical' })
getRepeatedScale({ ...defaultBarProps, orientation: 'horizontal', trellisOrientation: 'vertical' }),
).toHaveProperty('type', 'band');
expect(
getRepeatedScale({ ...defaultBarProps, orientation: 'vertical', trellisOrientation: 'horizontal' })
getRepeatedScale({ ...defaultBarProps, orientation: 'vertical', trellisOrientation: 'horizontal' }),
).toHaveProperty('type', 'band');
});
});
Expand Down
5 changes: 3 additions & 2 deletions src/specBuilder/bar/barTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
DEFAULT_COLOR,
DEFAULT_COLOR_SCHEME,
DEFAULT_METRIC,
DEFAULT_OPACITY_RULE,
DEFAULT_SECONDARY_COLOR,
FILTERED_TABLE,
HIGHLIGHT_CONTRAST_RATIO,
Expand Down Expand Up @@ -107,14 +108,14 @@ export const defaultDodgedCornerRadiusEncodings: RectEncodeEntry = {

export const defaultBarFillOpacity: ProductionRule<NumericValueRef> = [{ value: 1 }];

export const defaultBarPopoverFillOpacity: ProductionRule<NumericValueRef> = [
export const defaultBarPopoverOpacity: ProductionRule<NumericValueRef> = [
{
test: `!bar0_selectedId && bar0_hoveredId && bar0_hoveredId !== datum.${MARK_ID}`,
value: 1 / HIGHLIGHT_CONTRAST_RATIO,
},
{ test: `bar0_selectedId && bar0_selectedId !== datum.${MARK_ID}`, value: 1 / HIGHLIGHT_CONTRAST_RATIO },
{ test: `bar0_selectedId && bar0_selectedId === datum.${MARK_ID}`, value: 1 },
{ value: 1 },
DEFAULT_OPACITY_RULE,
];

export const stackedXScale = 'xBand';
Expand Down
Loading