Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kanitw committed Feb 2, 2021
1 parent f6aa06f commit 22d160b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 36 deletions.
10 changes: 2 additions & 8 deletions src/channeldef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import {Predicate} from './predicate';
import {hasDiscreteDomain, isContinuousToDiscrete, Scale, SCALE_CATEGORY_INDEX} from './scale';
import {isSortByChannel, Sort, SortOrder} from './sort';
import {isFacetFieldDef} from './spec/facet';
import {StackOffset, StackProperties} from './stack';
import {StackOffset} from './stack';
import {
getTimeUnitParts,
isLocalSingleTimeUnit,
Expand Down Expand Up @@ -513,17 +513,13 @@ export interface PositionMixins {
export type PolarDef<F extends Field> = PositionFieldDefBase<F> | PositionDatumDefBase<F> | PositionValueDef;

export function getBandPosition({
channel,
fieldDef,
fieldDef2,
markDef: mark,
stack,
config
}: {
channel: Channel;
fieldDef: FieldDef<string> | DatumDef;
fieldDef2?: SecondaryChannelDef<string>;
stack: StackProperties;
markDef: MarkDef<Mark, SignalRef>;
config: Config<SignalRef>;
}): number {
Expand Down Expand Up @@ -593,17 +589,15 @@ export function getBandSize({
}

export function hasBandEnd(
channel: Channel,
fieldDef: FieldDef<string>,
fieldDef2: SecondaryChannelDef<string>,
stack: StackProperties,
markDef: MarkDef<Mark, SignalRef>,
config: Config<SignalRef>
): boolean {
if (isBinning(fieldDef.bin) || (fieldDef.timeUnit && isTypedFieldDef(fieldDef) && fieldDef.type === 'temporal')) {
// Need to check bandPosition because non-rect marks (e.g., point) with timeUnit
// doesn't have to use bandEnd if there is no bandPosition.
return getBandPosition({channel, fieldDef, fieldDef2, stack, markDef, config}) !== undefined;
return getBandPosition({fieldDef, fieldDef2, markDef, config}) !== undefined;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compile/data/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function addDimension(dims: Set<string>, channel: Channel, fieldDef: FieldDef<st
if (
isTypedFieldDef(fieldDef) &&
isUnitModel(model) &&
hasBandEnd(channel, fieldDef, channelDef2, model.stack, model.markDef, model.config)
hasBandEnd(fieldDef, channelDef2, model.markDef, model.config)
) {
dims.add(vgField(fieldDef, {}));
dims.add(vgField(fieldDef, {suffix: 'end'}));
Expand Down
2 changes: 0 additions & 2 deletions src/compile/mark/encode/valueref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,9 @@ export function midPoint({
bandPosition =
bandPosition ??
getBandPosition({
channel,
fieldDef: channelDef,
fieldDef2: channel2Def,
markDef,
stack,
config
});
const {bin, timeUnit, type} = channelDef;
Expand Down
2 changes: 0 additions & 2 deletions src/compile/scale/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,8 @@ function parseSingleChannelDomain(
fieldDef.timeUnit &&
util.contains(['time', 'utc'], scaleType) &&
hasBandEnd(
channel,
fieldDef,
isUnitModel(model) ? model.encoding[getSecondaryRangeChannel(channel)] : undefined,
model.stack,
model.markDef,
model.config
)
Expand Down
30 changes: 7 additions & 23 deletions test/compile/mark/bar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@ import {defaultBarConfig} from '../../../src/mark';
import {parseUnitModelWithScaleAndLayoutSize} from '../../util';

describe('Mark: Bar', () => {
describe('1D vertical', () => {
const model = parseUnitModelWithScaleAndLayoutSize({
data: {url: 'data/cars.json'},
mark: {type: 'bar', width: {band: 0.5}},
encoding: {
y: {type: 'quantitative', field: 'Acceleration', aggregate: 'mean'}
}
});
const props = bar.encodeEntry(model);

it('should draw bar, with y from zero to field value and with band value for x/width', () => {
expect(props.width).toEqual({mult: 0.5, field: {group: 'width'}});
expect(props.y).toEqual({scale: 'y', field: 'mean_Acceleration'});
expect(props.y2).toEqual({scale: 'y', value: 0});
expect(props.height).toBeUndefined();
});
});

describe('simple vertical', () => {
const model = parseUnitModelWithScaleAndLayoutSize({
data: {url: 'data/cars.json'},
Expand Down Expand Up @@ -757,20 +739,22 @@ describe('Mark: Bar', () => {

describe('1D vertical', () => {
const model = parseUnitModelWithScaleAndLayoutSize({
mark: 'bar',
encoding: {y: {type: 'quantitative', field: 'US_Gross', aggregate: 'sum'}},
data: {url: 'data/movies.json'}
data: {url: 'data/cars.json'},
mark: {type: 'bar', width: {band: 0.5}},
encoding: {
y: {type: 'quantitative', field: 'Acceleration', aggregate: 'mean'}
}
});
const props = bar.encodeEntry(model);

it('should have y end on axis, have no-height and have x-offset', () => {
expect(props.y).toEqual({scale: 'y', field: 'sum_US_Gross'});
expect(props.y).toEqual({scale: 'y', field: 'mean_Acceleration'});
expect(props.y2).toEqual({scale: 'y', value: 0});
expect(props.height).toBeUndefined();
expect(props.xc).toEqual({
mult: 0.5,
signal: 'width'
});
expect(props.width).toEqual({mult: 0.5, field: {group: 'width'}});
});
});

Expand Down

0 comments on commit 22d160b

Please sign in to comment.