Skip to content

Commit

Permalink
compiles again
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Jul 30, 2024
1 parent eb26d70 commit 2ecb1e3
Show file tree
Hide file tree
Showing 86 changed files with 470 additions and 417 deletions.
10 changes: 5 additions & 5 deletions site/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {compile, TopLevelSpec} from '../../src';
import {post} from './post';
import {runStreamingExample} from './streaming';

window['runStreamingExample'] = runStreamingExample;
window['embedExample'] = embedExample;
(window as any)['runStreamingExample'] = runStreamingExample;
(window as any)['embedExample'] = embedExample;

hljs.registerLanguage('javascript', javascript);
hljs.registerLanguage('typescript', typescript);
Expand Down Expand Up @@ -131,13 +131,13 @@ async function getSpec(el: d3.BaseType) {
}
}

window['changeSpec'] = (elId: string, newSpec: string) => {
(window as any)['changeSpec'] = (elId: string, newSpec: string) => {
const el = document.getElementById(elId);
select(el).attr('data-name', newSpec);
getSpec(el);
};

window['buildSpecOpts'] = (id: string, baseName: string) => {
(window as any)['buildSpecOpts'] = (id: string, baseName: string) => {
const oldName = select(`#${id}`).attr('data-name');
const prefixSel = select(`select[name=${id}]`);
const inputsSel = selectAll(`input[name=${id}]:checked`);
Expand All @@ -149,7 +149,7 @@ window['buildSpecOpts'] = (id: string, baseName: string) => {
.join('_');
const newName = baseName + prefix + (values ? `_${values}` : '');
if (oldName !== newName) {
window['changeSpec'](id, newName);
(window as any)['changeSpec'](id, newName);
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const POLAR_POSITION_CHANNEL_INDEX = {
export type PolarPositionChannel = keyof typeof POLAR_POSITION_CHANNEL_INDEX;

export function isPolarPositionChannel(c: Channel): c is PolarPositionChannel {
return c in POLAR_POSITION_CHANNEL_INDEX;
return hasOwnProperty(POLAR_POSITION_CHANNEL_INDEX, c);
}

const GEO_POSIITON_CHANNEL_INDEX = {
Expand All @@ -118,7 +118,7 @@ export function getPositionChannelFromLatLong(channel: GeoPositionChannel): Posi
}

export function isGeoPositionChannel(c: Channel): c is GeoPositionChannel {
return c in GEO_POSIITON_CHANNEL_INDEX;
return hasOwnProperty(GEO_POSIITON_CHANNEL_INDEX, c);
}

export const GEOPOSITION_CHANNELS = keys(GEO_POSIITON_CHANNEL_INDEX);
Expand Down Expand Up @@ -422,7 +422,7 @@ export const OFFSET_SCALE_CHANNELS = keys(OFFSET_SCALE_CHANNEL_INDEX);
export type OffsetScaleChannel = (typeof OFFSET_SCALE_CHANNELS)[0];

export function isXorYOffset(channel: Channel): channel is OffsetScaleChannel {
return channel in OFFSET_SCALE_CHANNEL_INDEX;
return hasOwnProperty(OFFSET_SCALE_CHANNEL_INDEX, channel);
}

// NON_POSITION_SCALE_CHANNEL = SCALE_CHANNELS without position / offset
Expand Down
58 changes: 29 additions & 29 deletions src/channeldef.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Gradient, hasOwnProperty, ScaleType, SignalRef, Text} from 'vega';
import {Gradient, ScaleType, SignalRef, Text} from 'vega';
import {isArray, isBoolean, isNumber, isString} from 'vega-util';
import {Aggregate, isAggregateOp, isArgmaxDef, isArgminDef, isCountingAggregateOp} from './aggregate';
import {Axis} from './axis';
Expand Down Expand Up @@ -220,7 +220,7 @@ export type FieldName = string;
export type Field = FieldName | RepeatRef;

export function isRepeatRef(field: Field | any): field is RepeatRef {
return field && !isString(field) && 'repeat' in field;
return field && !isString(field) && hasKey(field, 'repeat');
}

/** @@hidden */
Expand Down Expand Up @@ -357,7 +357,7 @@ export interface SortableFieldDef<
}

export function isSortableFieldDef<F extends Field>(fieldDef: FieldDef<F>): fieldDef is SortableFieldDef<F> {
return 'sort' in fieldDef;
return hasKey(fieldDef, 'sort');
}

export type ScaleFieldDef<
Expand Down Expand Up @@ -648,7 +648,7 @@ export interface OrderOnlyDef {
export function isOrderOnlyDef<F extends Field>(
orderDef: OrderFieldDef<F> | OrderFieldDef<F>[] | OrderValueDef | OrderOnlyDef
): orderDef is OrderOnlyDef {
return orderDef && !!(orderDef as OrderOnlyDef).sort && !orderDef['field'];
return hasKey(orderDef, 'sort') && !hasKey(orderDef, 'field');
}

export type OrderValueDef = ConditionValueDefMixins<number> & NumericValueDef;
Expand All @@ -661,7 +661,7 @@ export type ChannelDef<F extends Field = string> = Encoding<F>[keyof Encoding<F>
export function isConditionalDef<CD extends ChannelDef<any> | GuideEncodingConditionalValueDef | ExprRef | SignalRef>(
channelDef: CD
): channelDef is CD & {condition: Conditional<any>} {
return channelDef && 'condition' in channelDef;
return hasKey(channelDef, 'condition');
}

/**
Expand All @@ -670,39 +670,39 @@ export function isConditionalDef<CD extends ChannelDef<any> | GuideEncodingCondi
export function hasConditionalFieldDef<F extends Field>(
channelDef: Partial<ChannelDef<F>>
): channelDef is {condition: Conditional<TypedFieldDef<F>>} {
const condition = channelDef?.['condition'];
const condition = (channelDef as any)?.['condition'];
return !!condition && !isArray(condition) && isFieldDef(condition);
}

export function hasConditionalFieldOrDatumDef<F extends Field>(
channelDef: ChannelDef<F>
): channelDef is {condition: Conditional<TypedFieldDef<F>>} {
const condition = channelDef?.['condition'];
const condition = (channelDef as any)?.['condition'];
return !!condition && !isArray(condition) && isFieldOrDatumDef(condition);
}

export function hasConditionalValueDef<F extends Field>(
channelDef: ChannelDef<F>
): channelDef is ValueDef<any> & {condition: Conditional<ValueDef<any>> | Conditional<ValueDef<any>>[]} {
const condition = channelDef?.['condition'];
const condition = (channelDef as any)?.['condition'];
return !!condition && (isArray(condition) || isValueDef(condition));
}

export function isFieldDef<F extends Field>(
channelDef: Partial<ChannelDef<F>> | FieldDefBase<F> | DatumDef<F, any>
): channelDef is FieldDefBase<F> | TypedFieldDef<F> | SecondaryFieldDef<F> {
// TODO: we can't use field in channelDef here as it's somehow failing runtime test
return channelDef && (!!channelDef['field'] || channelDef['aggregate'] === 'count');
return hasKey(channelDef, 'field') || (channelDef as any)?.aggregate === 'count';
}

export function channelDefType<F extends Field>(channelDef: ChannelDef<F>): Type | undefined {
return channelDef?.['type'];
return (channelDef as any)?.['type'];
}

export function isDatumDef<F extends Field>(
channelDef: Partial<ChannelDef<F>> | FieldDefBase<F> | DatumDef<F, any>
): channelDef is DatumDef<F, any> {
return channelDef && 'datum' in channelDef;
return hasKey(channelDef, 'datum');
}

export function isContinuousFieldOrDatumDef<F extends Field>(
Expand All @@ -728,33 +728,37 @@ export function isFieldOrDatumDef<F extends Field>(
}

export function isTypedFieldDef<F extends Field>(channelDef: ChannelDef<F>): channelDef is TypedFieldDef<F> {
return channelDef && ('field' in channelDef || channelDef['aggregate'] === 'count') && 'type' in channelDef;
return (
channelDef &&
(hasKey(channelDef, 'field') || (channelDef as any)['aggregate'] === 'count') &&
hasKey(channelDef, 'type')
);
}

export function isValueDef<F extends Field>(channelDef: Partial<ChannelDef<F>>): channelDef is ValueDef<any> {
return channelDef && 'value' in channelDef && 'value' in channelDef;
return hasKey(channelDef, 'value');
}

export function isScaleFieldDef<F extends Field>(channelDef: ChannelDef<F>): channelDef is ScaleFieldDef<F> {
return channelDef && ('scale' in channelDef || 'sort' in channelDef);
return hasKey(channelDef, 'scale') || hasKey(channelDef, 'sort');
}

export function isPositionFieldOrDatumDef<F extends Field>(
channelDef: ChannelDef<F>
): channelDef is PositionFieldDef<F> | PositionDatumDef<F> {
return channelDef && ('axis' in channelDef || 'stack' in channelDef || 'impute' in channelDef);
return hasKey(channelDef, 'axis') || hasKey(channelDef, 'stack') || hasKey(channelDef, 'impute');
}

export function isMarkPropFieldOrDatumDef<F extends Field>(
channelDef: ChannelDef<F>
): channelDef is MarkPropFieldDef<F, any> | MarkPropDatumDef<F> {
return channelDef && 'legend' in channelDef;
return hasKey(channelDef, 'legend');
}

export function isStringFieldOrDatumDef<F extends Field>(
channelDef: ChannelDef<F>
): channelDef is StringFieldDef<F> | StringDatumDef<F> {
return channelDef && ('format' in channelDef || 'formatType' in channelDef);
return hasKey(channelDef, 'format') || hasKey(channelDef, 'formatType');
}

export function toStringFieldDef<F extends Field>(fieldDef: FieldDef<F>): StringFieldDef<F> {
Expand Down Expand Up @@ -783,7 +787,7 @@ export interface FieldRefOption {
function isOpFieldDef(
fieldDef: FieldDefBase<string> | WindowFieldDef | AggregatedFieldDef
): fieldDef is WindowFieldDef | AggregatedFieldDef {
return 'op' in fieldDef;
return hasKey(fieldDef, 'op');
}

/**
Expand Down Expand Up @@ -911,11 +915,7 @@ export function functionalTitleFormatter(fieldDef: FieldDefBase<string>) {
const timeUnitParams = timeUnit && !isBinnedTimeUnit(timeUnit) ? normalizeTimeUnit(timeUnit) : undefined;

const fn = aggregate || timeUnitParams?.unit || (timeUnitParams?.maxbins && 'timeunit') || (isBinning(bin) && 'bin');
if (fn) {
return `${fn.toUpperCase()}(${field})`;
} else {
return field;
}
return fn ? `${fn.toUpperCase()}(${field})` : field;
}

export const defaultTitleFormatter: FieldTitleFormatter = (fieldDef: FieldDefBase<string>, config: Config) => {
Expand Down Expand Up @@ -1102,8 +1102,8 @@ export function initFieldOrDatumDef(
: isFacetFieldDef(fd)
? 'header'
: null;
if (guideType && fd[guideType]) {
const {format, formatType, ...newGuide} = fd[guideType];
if (guideType && (fd as any)[guideType]) {
const {format, formatType, ...newGuide} = (fd as any)[guideType];
if (isCustomFormatType(formatType) && !config.customFormatTypes) {
log.warn(log.message.customFormatTypeNotAllowed(channel));
return initFieldOrDatumDef({...fd, [guideType]: newGuide}, channel, config, opt);
Expand Down Expand Up @@ -1177,7 +1177,7 @@ export function initFieldDef(
} else if (!isSecondaryRangeChannel(channel)) {
// If type is empty / invalid, then augment with default type
const newType = defaultType(fieldDef as TypedFieldDef<any>, channel);
fieldDef['type'] = newType;
(fieldDef as any)['type'] = newType;
}

if (isTypedFieldDef(fieldDef)) {
Expand All @@ -1195,7 +1195,7 @@ export function initFieldDef(
sort: {encoding: sort}
};
}
const sub = sort.substr(1);
const sub = sort.substring(1);
if (sort.charAt(0) === '-' && isSortByChannel(sub)) {
return {
...fieldDef,
Expand Down Expand Up @@ -1304,7 +1304,7 @@ export function channelCompatibility(
case RADIUS2:
case X2:
case Y2:
if (type === 'nominal' && !fieldDef['sort']) {
if (type === 'nominal' && !(fieldDef as any)['sort']) {
return {
compatible: false,
warning: `Channel ${channel} should not be used with an unsorted discrete field.`
Expand Down Expand Up @@ -1346,7 +1346,7 @@ export function isFieldOrDatumDefForTimeFormat(fieldOrDatumDef: FieldDef<string>
* Check if field def has type `temporal`. If you want to also cover field defs that use a time format, use `isTimeFormatFieldDef`.
*/
export function isTimeFieldDef(def: FieldDef<any> | DatumDef): boolean {
return def && (def['type'] === 'temporal' || (isFieldDef(def) && !!def.timeUnit));
return def && ((def as any)['type'] === 'temporal' || (isFieldDef(def) && !!def.timeUnit));
}

/**
Expand Down
22 changes: 15 additions & 7 deletions src/compile/axis/assemble.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import {Axis as VgAxis, AxisEncode, NewSignal, SignalRef, Text} from 'vega';
import {array, isArray} from 'vega-util';
import {AXIS_PARTS, AXIS_PROPERTY_TYPE, CONDITIONAL_AXIS_PROP_INDEX, isConditionalAxisValue} from '../../axis';
import {
AXIS_PARTS,
AXIS_PROPERTY_TYPE,
CONDITIONAL_AXIS_PROP_INDEX,
ConditionalAxisProp,
isConditionalAxisValue
} from '../../axis';
import {POSITION_SCALE_CHANNELS} from '../../channel';
import {defaultTitle, FieldDefBase} from '../../channeldef';
import {Config} from '../../config';
Expand Down Expand Up @@ -49,7 +55,8 @@ export function assembleAxis(
return undefined;
}

for (const prop in axis) {
for (const p in axis) {
const prop = p as keyof typeof axis;
const propType = AXIS_PROPERTY_TYPE[prop];
const propValue = axis[prop];

Expand All @@ -59,10 +66,10 @@ export function assembleAxis(
} else if (isConditionalAxisValue<any, SignalRef>(propValue)) {
// deal with conditional axis value

const {condition, ...valueOrSignalRef} = propValue;
const {condition, ...valueOrSignalRef} = propValue as any;
const conditions = array(condition);

const propIndex = CONDITIONAL_AXIS_PROP_INDEX[prop];
const propIndex = CONDITIONAL_AXIS_PROP_INDEX[prop as ConditionalAxisProp];
if (propIndex) {
const {vgProp, part} = propIndex;
// If there is a corresponding Vega property for the channel,
Expand Down Expand Up @@ -91,13 +98,14 @@ export function assembleAxis(
})
.join('') + exprFromValueRefOrSignalRef(valueOrSignalRef)
};
axis[prop] = signalRef;
(axis as any)[prop] = signalRef;
}
} else if (isSignalRef(propValue)) {
const propIndex = CONDITIONAL_AXIS_PROP_INDEX[prop];
const propIndex = CONDITIONAL_AXIS_PROP_INDEX[prop as ConditionalAxisProp];
if (propIndex) {
const {vgProp, part} = propIndex;
setAxisEncode(axis, part, vgProp, propValue);
// FIXME: remove as any
setAxisEncode(axis, part, vgProp, propValue as any);
delete axis[prop];
} // else do nothing since the property already supports signal
}
Expand Down
10 changes: 5 additions & 5 deletions src/compile/axis/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function getAxisConfigFromConfigTypes(

const conditionalOrientAxisConfig = {};
for (const prop of props.values()) {
conditionalOrientAxisConfig[prop] = {
(conditionalOrientAxisConfig as any)[prop] = {
// orient is surely signal in this case
signal: `${orient['signal']} === "${orient1}" ? ${signalOrStringValue(
signal: `${(orient as any)['signal']} === "${orient1}" ? ${signalOrStringValue(
orientConfig1[prop]
)} : ${signalOrStringValue(orientConfig2[prop])}`
};
Expand All @@ -38,7 +38,7 @@ function getAxisConfigFromConfigTypes(
return conditionalOrientAxisConfig;
}

return config[configType];
return (config as any)[configType];
})
]);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ export function getAxisConfigStyle(axisConfigTypes: string[], config: Config) {
const toMerge = [{}];
for (const configType of axisConfigTypes) {
// TODO: add special casing to add conditional value based on orient signal
let style = config[configType]?.style;
let style = (config as any)[configType]?.style;
if (style) {
style = array(style);
for (const s of style) {
Expand All @@ -110,7 +110,7 @@ export function getAxisConfig(
};
}

for (const configFrom of ['vlOnlyAxisConfig', 'vgAxisConfig', 'axisConfigStyle']) {
for (const configFrom of ['vlOnlyAxisConfig', 'vgAxisConfig', 'axisConfigStyle'] as const) {
if (axisConfigs[configFrom]?.[property] !== undefined) {
return {configFrom, configValue: axisConfigs[configFrom][property]};
}
Expand Down
2 changes: 1 addition & 1 deletion src/compile/axis/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function isExplicit<T extends string | number | boolean | unknown>(
}
}
// Otherwise, things are explicit if the returned value matches the specified property
return value === axis[property];
return value === (axis as any)[property];
}

/**
Expand Down
Loading

0 comments on commit 2ecb1e3

Please sign in to comment.