diff --git a/packages/perspective-viewer-d3fc/src/ts/axis/axisFactory.ts b/packages/perspective-viewer-d3fc/src/ts/axis/axisFactory.ts index e8a7484cae..a75d3cab2a 100644 --- a/packages/perspective-viewer-d3fc/src/ts/axis/axisFactory.ts +++ b/packages/perspective-viewer-d3fc/src/ts/axis/axisFactory.ts @@ -22,7 +22,6 @@ import { D3Scale, Domain, DomainTuple, - GetSetReturn, Orientation, SettingNameValues, Settings, @@ -50,30 +49,29 @@ export interface AxisFactoryContent { interface AxisFactory { (data: any[]): any; - memoValue: ( - ...args: T[] - ) => GetSetReturn; - excludeType: ( - ...args: T[] - ) => GetSetReturn; - orient: ( - ...args: T[] - ) => GetSetReturn; - settingName: ( - ...args: T[] - ) => GetSetReturn; - settingValue: ( - ...args: T[] - ) => GetSetReturn; - valueName: ( - ...args: T[] - ) => GetSetReturn; - valueNames: ( - ...args: T[] - ) => GetSetReturn; - modifyDomain: ( - ...args: T[] - ) => GetSetReturn; + memoValue(): Axis; + memoValue(a: Axis): AxisFactory; + + excludeType(): () => AxisTypeValues; + excludeType(nextExcludeType?: AxisTypeValues): this; + + orient(): () => Orientation; + orient(nextOrient?: Orientation): this; + + settingName(): () => SettingNameValues; + settingName(nextSettingName?: SettingNameValues): this; + + settingValue(): () => string | null; + settingValue(nextSettingValue?: string | null): this; + + valueName(): () => ValueName; + valueName(nextValueName?: ValueName): this; + + valueNames(): () => ValueName[]; + valueNames(nextValueNames?: ValueName[]): this; + + modifyDomain(): () => ModifyDomainFunc; + modifyDomain(nextModifyDomain?: ModifyDomainFunc): this; // optional params, no idea yet if these are right or not. include?: (nextInclude?: number[]) => any; @@ -102,7 +100,7 @@ export const axisFactory = (settings: Settings): AxisFactory => { const optionalParams = ["include", "paddingStrategy", "pad"]; const optional = {}; - const _factory: any = (data): AxisFactoryContent => { + const _factory: Partial = (data): AxisFactoryContent => { const useType = axisType(settings) .excludeType(excludeType) .settingName(settingName) @@ -167,95 +165,75 @@ export const axisFactory = (settings: Settings): AxisFactory => { decorate: () => {}, }); - _factory.memoValue = ( - ...args: T[] - ): GetSetReturn => { + _factory.memoValue = (...args: Axis[]): any => { if (!args.length) { - return memoValue as GetSetReturn; + return memoValue; } + memoValue = args[0]; return _factory; }; - _factory.excludeType = ( - ...args: T[] - ): GetSetReturn => { + _factory.excludeType = (...args: AxisTypeValues[]): any => { if (!args.length) { - return excludeType as GetSetReturn; + return excludeType; } + excludeType = args[0]; return _factory; }; - _factory.orient = ( - ...args: T[] - ): GetSetReturn => { + _factory.orient = (...args: Orientation[]): any => { if (!args.length) { - return orient as GetSetReturn; + return orient; } + orient = args[0]; return _factory; }; - _factory.settingName = < - T extends SettingNameValues | undefined = undefined - >( - ...args: T[] - ): GetSetReturn => { + _factory.settingName = (...args: SettingNameValues[]): any => { if (!args.length) { - return settingName as GetSetReturn< - T, - SettingNameValues, - AxisFactory - >; + return settingName; } + settingName = args[0]; return _factory; }; - _factory.settingValue = ( - ...args: T[] - ): GetSetReturn => { + _factory.settingValue = (...args: (string | null)[]): any => { if (!args.length) { - return settingValue as GetSetReturn; + return settingValue; } + settingValue = args[0]; return _factory; }; - _factory.valueName = ( - ...args: T[] - ): GetSetReturn => { + _factory.valueName = (...args: ValueName[]): any => { if (!args.length) { - return valueNames[0] as GetSetReturn; + return valueNames[0]; } + valueNames = [args[0]]; return _factory; }; - _factory.valueNames = ( - ...args: T[] - ): GetSetReturn => { + _factory.valueNames = (...args: ValueName[][]): any => { if (!args.length) { - return valueNames as GetSetReturn; + return valueNames; } + valueNames = args[0]; return _factory; }; - _factory.modifyDomain = < - T extends ModifyDomainFunc | undefined = undefined - >( - ...args: T[] - ): GetSetReturn => { - if (!args.length) { - return modifyDomain as GetSetReturn< - T, - ModifyDomainFunc, - AxisFactory - >; + _factory.modifyDomain = (nextModifyDomain?: ModifyDomainFunc) => { + if (!nextModifyDomain) { + return modifyDomain; } - modifyDomain = args[0]; + + modifyDomain = nextModifyDomain; return _factory; }; @@ -269,5 +247,5 @@ export const axisFactory = (settings: Settings): AxisFactory => { }; }); - return _factory; + return _factory as AxisFactory; }; diff --git a/packages/perspective-viewer-d3fc/src/ts/axis/axisLabel.ts b/packages/perspective-viewer-d3fc/src/ts/axis/axisLabel.ts index 7b0fa87afa..4c578429fa 100644 --- a/packages/perspective-viewer-d3fc/src/ts/axis/axisLabel.ts +++ b/packages/perspective-viewer-d3fc/src/ts/axis/axisLabel.ts @@ -16,7 +16,7 @@ import { labelFunction as noLabel } from "./noAxis"; import { labelFunction as timeLabel } from "./timeAxis"; import { labelFunction as linearLabel } from "./linearAxis"; import { labelFunction as ordinalLabel } from "./ordinalAxis"; -import { GetSetReturn, Settings } from "../types"; +import { Settings } from "../types"; const labelFunctions = { none: noLabel, @@ -28,30 +28,28 @@ const labelFunctions = { export interface LabelFunction { // NOTE: this "i" is not used... (d, i?: any): string; - valueName: ( - ...args: T[] - ) => GetSetReturn; + valueName(): string; + valueName(nextValueName: string): this; } export const labelFunction = (settings: Settings): LabelFunction => { const base = axisType(settings); let valueName = "__ROW_PATH__"; - const label: any = (d, _i) => { + const label: Partial = (d, _i) => { return labelFunctions[base()](valueName)(d); }; rebindAll(label, base); - label.valueName = ( - ...args: T[] - ): GetSetReturn => { + label.valueName = (...args: string[]): any => { if (!args.length) { - return valueName as GetSetReturn; + return valueName; } + valueName = args[0]; return label; }; - return label; + return label as LabelFunction; }; diff --git a/packages/perspective-viewer-d3fc/src/ts/axis/axisSplitter.ts b/packages/perspective-viewer-d3fc/src/ts/axis/axisSplitter.ts index 6259c320ad..fded479783 100644 --- a/packages/perspective-viewer-d3fc/src/ts/axis/axisSplitter.ts +++ b/packages/perspective-viewer-d3fc/src/ts/axis/axisSplitter.ts @@ -10,21 +10,22 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -import { GetSetReturn, Settings } from "../types"; +import { Settings } from "../types"; import { splitterLabels } from "./splitterLabels"; export interface AxisSplitter { (selection: any): void; - color: | undefined = undefined>( - ...args: T[] - ) => GetSetReturn, AxisSplitter>; + + color(): d3.ScaleOrdinal; + color(nextColor: d3.ScaleOrdinal): AxisSplitter; + haveSplit: () => boolean; - data: ( - ...args: T[] - ) => GetSetReturn; - altData: ( - ...args: T[] - ) => GetSetReturn; + + data(): any[]; + data(nextData: any[]): AxisSplitter; + + altData(): any[]; + altData(nextData: any[]): AxisSplitter; } export const axisSplitter = ( @@ -74,17 +75,9 @@ export const axisSplitter = ( .call(labeller().labels(altLabels).alt(true)); }; - splitter.color = < - T extends d3.ScaleOrdinal | undefined = undefined - >( - ...args: T[] - ): GetSetReturn, AxisSplitter> => { + splitter.color = (...args: d3.ScaleOrdinal[]): any => { if (!args.length) { - return color as GetSetReturn< - T, - d3.ScaleOrdinal, - AxisSplitter - >; + return color; } color = args[0]; return splitter; @@ -92,20 +85,17 @@ export const axisSplitter = ( splitter.haveSplit = (): boolean => haveSplit; - splitter.data = ( - ...args: T[] - ): GetSetReturn => { + splitter.data = (...args: any[][]): any => { if (!args.length) { - return data as GetSetReturn; + return data; } data = args[0]; return splitter; }; - splitter.altData = ( - ...args: T[] - ): GetSetReturn => { + + splitter.altData = (...args: any[][]): any => { if (!args.length) { - return altData as GetSetReturn; + return altData; } altData = args[0]; return splitter; diff --git a/packages/perspective-viewer-d3fc/src/ts/axis/axisType.ts b/packages/perspective-viewer-d3fc/src/ts/axis/axisType.ts index d6cd4bc2ec..957bca9dad 100644 --- a/packages/perspective-viewer-d3fc/src/ts/axis/axisType.ts +++ b/packages/perspective-viewer-d3fc/src/ts/axis/axisType.ts @@ -10,7 +10,7 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -import { GetSetReturn, Settings, SettingNameValues } from "../types"; +import { Settings, SettingNameValues } from "../types"; export const AXIS_TYPES = { none: "none", @@ -23,15 +23,15 @@ export type AxisTypeValues = typeof AXIS_TYPES[keyof typeof AXIS_TYPES]; export interface AxisType { (): AxisTypeValues; - settingName: ( - ...args: T[] - ) => GetSetReturn; - settingValue: ( - ...args: T[] - ) => GetSetReturn; - excludeType: ( - ...args: T[] - ) => GetSetReturn; + + settingName(): SettingNameValues; + settingName(nextSettingName: SettingNameValues): this; + + settingValue(): string; + settingValue(nextSettingValue: string): this; + + excludeType(): AxisTypeValues; + excludeType(nextExcludeType: AxisTypeValues): this; } export const axisType = (settings: Settings): AxisType => { @@ -39,7 +39,7 @@ export const axisType = (settings: Settings): AxisType => { let settingValue = null; let excludeType = null; - const getType: any = (): AxisTypeValues | boolean => { + const getType: Partial = (): AxisTypeValues | boolean => { const checkTypes = (types) => { const list = settingValue ? settings[settingName].filter((s) => settingValue == s.name) @@ -74,35 +74,30 @@ export const axisType = (settings: Settings): AxisType => { return AXIS_TYPES.ordinal; }; - getType.settingName = ( - ...args: T[] - ): GetSetReturn => { + getType.settingName = (...args: SettingNameValues[]): any => { if (!args.length) { - return settingName as GetSetReturn; + return settingName; } settingName = args[0]; return getType; }; - getType.settingValue = ( - ...args: T[] - ): GetSetReturn => { + getType.settingValue = (...args: (string | undefined)[]): any => { if (!args.length) { - return settingValue as GetSetReturn; + return settingValue; } + settingValue = args[0]; return getType; }; - getType.excludeType = ( - ...args: T[] - ): GetSetReturn => { + getType.excludeType = (...args: AxisTypeValues[]): any => { if (!args.length) { - return excludeType as GetSetReturn; + return excludeType; } excludeType = args[0]; return getType; }; - return getType; + return getType as AxisType; }; diff --git a/packages/perspective-viewer-d3fc/src/ts/axis/linearAxis.ts b/packages/perspective-viewer-d3fc/src/ts/axis/linearAxis.ts index 59e0b96166..92ace9fd93 100644 --- a/packages/perspective-viewer-d3fc/src/ts/axis/linearAxis.ts +++ b/packages/perspective-viewer-d3fc/src/ts/axis/linearAxis.ts @@ -20,7 +20,6 @@ import { Component, ComponentData, Domain, - GetSetReturn, PaddingStrategy, Settings, ValueName, @@ -66,20 +65,17 @@ export const domain = (): Domain => { } }; - _domain.valueName = ( - ...args: T[] - ): GetSetReturn => { + _domain.valueName = (...args: ValueName[]): any => { if (!args.length) { - return valueNames[0] as GetSetReturn; + return valueNames[0]; } valueNames = [args[0]]; return _domain; }; - _domain.valueNames = ( - ...args: T[] - ): GetSetReturn => { + + _domain.valueNames = (...args: ValueName[][]): any => { if (!args.length) { - return valueNames as GetSetReturn; + return valueNames; } valueNames = args[0]; return _domain; diff --git a/packages/perspective-viewer-d3fc/src/ts/axis/minBandwidth.ts b/packages/perspective-viewer-d3fc/src/ts/axis/minBandwidth.ts index 42df2c3ea1..169952842f 100644 --- a/packages/perspective-viewer-d3fc/src/ts/axis/minBandwidth.ts +++ b/packages/perspective-viewer-d3fc/src/ts/axis/minBandwidth.ts @@ -11,32 +11,27 @@ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ import { rebindAll } from "d3fc"; -import { GetSetReturn } from "../types"; const MIN_BANDWIDTH = 1; export interface MinBandwidth { (arg: any): any; + bandwidth(): number; + bandwidth(...args: any[]): any; } // NOTE: Can the minBandwidth in barSeries.ts be merged with this? export default (adaptee: d3.ScaleBand): MinBandwidth => { - const minBandwidth: any = (arg) => { + const minBandwidth: Partial = (arg) => { return adaptee(arg); }; rebindAll(minBandwidth, adaptee); - minBandwidth.bandwidth = ( - ...args: T[] - ): GetSetReturn => { + minBandwidth.bandwidth = (...args: any[]): any => { if (!args.length) { - return Math.max(adaptee.bandwidth(), MIN_BANDWIDTH) as GetSetReturn< - T, - number, - MinBandwidth - >; + return Math.max(adaptee.bandwidth(), MIN_BANDWIDTH); } // NOTE: d3.ScaleBand only has a getter for .bandwidth? (no args...); // I'm not sure this can be set. @@ -45,5 +40,5 @@ export default (adaptee: d3.ScaleBand): MinBandwidth => { return minBandwidth; }; - return minBandwidth; + return minBandwidth as MinBandwidth; }; diff --git a/packages/perspective-viewer-d3fc/src/ts/axis/noAxis.ts b/packages/perspective-viewer-d3fc/src/ts/axis/noAxis.ts index 53fcdd9782..738669cc74 100644 --- a/packages/perspective-viewer-d3fc/src/ts/axis/noAxis.ts +++ b/packages/perspective-viewer-d3fc/src/ts/axis/noAxis.ts @@ -14,7 +14,7 @@ import * as d3 from "d3"; import { flattenArray } from "./flatten"; import minBandwidth from "./minBandwidth"; import withoutTicks from "./withoutTicks"; -import { Domain, GetSetReturn, Orientation, ValueName } from "../types"; +import { Domain, Orientation, ValueName } from "../types"; export const scale = () => withoutTicks(minBandwidth(d3.scaleBand())); @@ -22,7 +22,7 @@ export const domain = (): Domain => { let valueNames = ["crossValue"]; let orient = "horizontal"; - const _domain: any = (data: any[]) => { + const _domain: Partial = (data: any[]) => { const flattenedData = flattenArray(data); return transformDomain([ ...new Set(flattenedData.map((d) => d[valueNames[0]])), @@ -31,36 +31,31 @@ export const domain = (): Domain => { const transformDomain = (d) => (orient == "vertical" ? d.reverse() : d); - _domain.valueName = ( - ...args: T[] - ): GetSetReturn => { + _domain.valueName = (...args: ValueName[]): any => { if (!args.length) { - return valueNames[0] as GetSetReturn; + return valueNames[0]; } valueNames = [args[0]]; return _domain; }; - _domain.valueNames = ( - ...args: T[] - ): GetSetReturn => { + + _domain.valueNames = (...args: ValueName[][]): any => { if (!args.length) { - return valueNames as GetSetReturn; + return valueNames; } valueNames = args[0]; return _domain; }; - _domain.orient = ( - ...args: T[] - ): GetSetReturn => { + _domain.orient = (...args: Orientation[]): any => { if (!args.length) { - return orient as GetSetReturn; + return orient; } orient = args[0]; return _domain; }; - return _domain; + return _domain as Domain; }; export const labelFunction = (valueName) => (d) => d[valueName].join("|"); diff --git a/packages/perspective-viewer-d3fc/src/ts/axis/ordinalAxis.ts b/packages/perspective-viewer-d3fc/src/ts/axis/ordinalAxis.ts index 78cdf959b3..e475d61b94 100644 --- a/packages/perspective-viewer-d3fc/src/ts/axis/ordinalAxis.ts +++ b/packages/perspective-viewer-d3fc/src/ts/axis/ordinalAxis.ts @@ -24,7 +24,7 @@ import { getChartContainer } from "../plugin/root"; import { Component, ComponentData, - GetSetReturn, + Domain, Orientation, SettingNameValues, Settings, @@ -38,22 +38,22 @@ export const scale = () => minBandwidth(d3.scaleBand()).padding(0.5); interface OrdinalAxisDomain { (data: any): any; - valueName: ( - ...args: T[] - ) => GetSetReturn; - valueNames: ( - ...args: T[] - ) => GetSetReturn; - orient: ( - ...args: T[] - ) => GetSetReturn; + + valueName(): ValueName; + valueName(nextValueName: ValueName): this; + + valueNames(): ValueName[]; + valueNames(nextValueNames: ValueName[]): this; + + orient(): Orientation; + orient(nextOrient: Orientation): this; } export const domain = (): OrdinalAxisDomain => { let valueNames = ["crossValue"]; let orient = "horizontal"; - const _domain: any = (data) => { + const _domain: Partial = (data) => { const flattenedData = flattenArray(data); return transformDomain([ ...Array.from(new Set(flattenedData.map((d) => d[valueNames[0]]))), @@ -62,44 +62,31 @@ export const domain = (): OrdinalAxisDomain => { const transformDomain = (d) => (orient == "vertical" ? d.reverse() : d); - _domain.valueName = ( - ...args: T[] - ): GetSetReturn => { + _domain.valueName = (...args: ValueName[]): any => { if (!args.length) { - return valueNames[0] as GetSetReturn< - T, - ValueName, - OrdinalAxisDomain - >; + return valueNames[0]; } valueNames = [args[0]]; return _domain; }; - _domain.valueNames = ( - ...args: T[] - ): GetSetReturn => { + + _domain.valueNames = (...args: ValueName[][]): any => { if (!args.length) { - return valueNames as GetSetReturn< - T, - ValueName[], - OrdinalAxisDomain - >; + return valueNames; } valueNames = args[0]; return _domain; }; - _domain.orient = ( - ...args: T[] - ): GetSetReturn => { + _domain.orient = (...args: Orientation[]): any => { if (!args.length) { - return orient as GetSetReturn; + return orient; } orient = args[0]; return _domain; }; - return _domain; + return _domain as Domain; }; export const labelFunction = @@ -331,33 +318,25 @@ export const component = (settings: Settings): Component => { }); }; - getComponent.orient = ( - ...args: T[] - ): GetSetReturn => { + getComponent.orient = (...args: Orientation[]): any => { if (!args.length) { - return orient as GetSetReturn; + return orient; } orient = args[0]; return getComponent; }; - getComponent.settingName = < - T extends SettingNameValues | undefined = undefined - >( - ...args: T[] - ): GetSetReturn => { + getComponent.settingName = (...args: SettingNameValues[]): any => { if (!args.length) { - return settingName as GetSetReturn; + return settingName; } settingName = args[0]; return getComponent; }; - getComponent.domain = ( - ...args: T[] - ): GetSetReturn => { + getComponent.domain = (...args: string[][]): any => { if (!args.length) { - return domain as GetSetReturn; + return domain; } domain = args[0]; return getComponent; diff --git a/packages/perspective-viewer-d3fc/src/ts/axis/splitterLabels.ts b/packages/perspective-viewer-d3fc/src/ts/axis/splitterLabels.ts index a940d06dc1..7712c82d91 100644 --- a/packages/perspective-viewer-d3fc/src/ts/axis/splitterLabels.ts +++ b/packages/perspective-viewer-d3fc/src/ts/axis/splitterLabels.ts @@ -13,7 +13,7 @@ import * as fc from "d3fc"; import { getChartElement } from "../plugin/root"; import { withoutOpacity } from "../series/seriesColors.js"; -import { GetSetReturn, HTMLSelection, Settings } from "../types"; +import { HTMLSelection, Settings } from "../types"; export type SplitterLabel = { index: number; @@ -22,15 +22,15 @@ export type SplitterLabel = { export interface SplitterLabels { (selection: any): void; - labels: ( - ...args: T[] - ) => GetSetReturn; - color: | undefined = undefined>( - ...args: T[] - ) => GetSetReturn, SplitterLabels>; - alt: ( - ...args: T[] - ) => GetSetReturn; + + labels(): SplitterLabel[]; + labels(labels: SplitterLabel[]): SplitterLabels; + + color(): d3.ScaleOrdinal; + color(nextColor: d3.ScaleOrdinal): SplitterLabels; + + alt(): boolean; + alt(nextAlt: boolean): SplitterLabels; } // Render a set of labels with the little left/right arrows for moving @@ -40,7 +40,7 @@ export const splitterLabels = (settings: Settings): SplitterLabels => { let alt = false; let color; - const _render: any = (selection: HTMLSelection) => { + const _render: Partial = (selection: HTMLSelection) => { selection.text(""); const labelDataJoin = fc @@ -83,20 +83,16 @@ export const splitterLabels = (settings: Settings): SplitterLabels => { chartElement._draw(); }; - _render.labels = ( - ...args: T[] - ): GetSetReturn => { + _render.labels = (...args: SplitterLabel[][]): any => { if (!args.length) { - return labels as GetSetReturn; + return labels; } labels = args[0]; return _render; }; - _render.alt = ( - ...args: T[] - ): GetSetReturn => { + _render.alt = (...args: boolean[]): any => { if (!args.length) { - return alt as GetSetReturn; + return alt; } alt = args[0]; return _render; @@ -109,5 +105,6 @@ export const splitterLabels = (settings: Settings): SplitterLabels => { color = args[0]; return _render; }; - return _render; + + return _render as SplitterLabels; }; diff --git a/packages/perspective-viewer-d3fc/src/ts/axis/timeAxis.ts b/packages/perspective-viewer-d3fc/src/ts/axis/timeAxis.ts index a6c2a8163b..ea20e70f0e 100644 --- a/packages/perspective-viewer-d3fc/src/ts/axis/timeAxis.ts +++ b/packages/perspective-viewer-d3fc/src/ts/axis/timeAxis.ts @@ -13,7 +13,7 @@ import * as d3 from "d3"; import * as fc from "d3fc"; import { flattenArray } from "./flatten"; -import { Domain, GetSetReturn, ValueName } from "../types"; +import { Domain, ValueName } from "../types"; export const scale = () => d3.scaleTime(); @@ -22,7 +22,7 @@ export const domain = (): Domain => { let valueNames = ["crossValue"]; - const _domain: any = (data) => { + const _domain: Partial = (data) => { base.accessors(valueNames.map((v) => (d) => new Date(d[v]))); return getDataExtent(flattenArray(data)); @@ -51,26 +51,23 @@ export const domain = (): Domain => { return base.padUnit("domain").pad([dataWidth / 2, dataWidth / 2])(data); }; - _domain.valueName = ( - ...args: T[] - ): GetSetReturn => { + _domain.valueName = (...args: ValueName[]): any => { if (!args.length) { - return valueNames[0] as GetSetReturn; + return valueNames[0]; } valueNames = [args[0]]; return _domain; }; - _domain.valueNames = ( - ...args: T[] - ): GetSetReturn => { + + _domain.valueNames = (...args: ValueName[][]): any => { if (!args.length) { - return valueNames as GetSetReturn; + return valueNames; } valueNames = args[0]; return _domain; }; - return _domain; + return _domain as Domain; }; export const labelFunction = (valueName) => (d) => new Date(d[valueName][0]); diff --git a/packages/perspective-viewer-d3fc/src/ts/charts/xy-scatter.ts b/packages/perspective-viewer-d3fc/src/ts/charts/xy-scatter.ts index 62d9d7ae15..4cbf419467 100644 --- a/packages/perspective-viewer-d3fc/src/ts/charts/xy-scatter.ts +++ b/packages/perspective-viewer-d3fc/src/ts/charts/xy-scatter.ts @@ -32,7 +32,7 @@ import { D3Scale, HTMLSelection, Settings } from "../types"; * @param {any} settings * @param {d3.ScaleOrdinal} symbols */ -function overrideSymbols(settings, symbols): D3Scale { +function overrideSymbols(settings: Settings, symbols): D3Scale { if (!symbols) { return; } diff --git a/packages/perspective-viewer-d3fc/src/ts/d3fc/axis/multi-axis.ts b/packages/perspective-viewer-d3fc/src/ts/d3fc/axis/multi-axis.ts index fd41838528..27a0bc4c0f 100644 --- a/packages/perspective-viewer-d3fc/src/ts/d3fc/axis/multi-axis.ts +++ b/packages/perspective-viewer-d3fc/src/ts/d3fc/axis/multi-axis.ts @@ -21,30 +21,30 @@ import { exclude, } from "d3fc"; import store from "./store"; -import { GetSetReturn, Orient } from "../../types"; +import { Orient } from "../../types"; export interface MultiAxis { (selection: any): void; - tickSize: ( - ...args: T[] - ) => GetSetReturn; - tickSizeInner: ( - ...args: T[] - ) => GetSetReturn; - tickSizeOuter: ( - ...args: T[] - ) => GetSetReturn; - decorate: ( - ...args: T[] - ) => GetSetReturn; - groups: ( - ...args: T[] - ) => GetSetReturn; + + tickSize(): number; + tickSize(nextTickSize: number): MultiAxis; + + tickSizeInner(): number | number[]; + tickSizeInner(nextTickSize: number | number[]): MultiAxis; + + tickSizeOuter(): number; + tickSizeOuter(nextTickSize: number): MultiAxis; + + decorate(): any; + decorate(nextDecorator: any): MultiAxis; + + groups(): any; + groups(nextGroups: any): MultiAxis; } const multiAxis = (orient: Orient, baseAxis, scale): MultiAxis => { let tickSizeOuter = 6; - let tickSizeInner = 6; + let tickSizeInner: number | number[] = 6; let axisStore = store( "tickFormat", "ticks", @@ -67,7 +67,7 @@ const multiAxis = (orient: Orient, baseAxis, scale): MultiAxis => { const isVertical = () => orient === "left" || orient === "right"; - const multiAxis: any = (selection) => { + const multiAxis: Partial = (selection) => { if (!groups) { axisStore(baseAxis(scale).decorate(decorate))(selection); return; @@ -153,7 +153,7 @@ const multiAxis = (orient: Orient, baseAxis, scale): MultiAxis => { return customScale; }; - multiAxis.tickSize = (...args) => { + multiAxis.tickSize = (...args): any => { if (!args.length) { return tickSizeInner; } @@ -161,27 +161,23 @@ const multiAxis = (orient: Orient, baseAxis, scale): MultiAxis => { return multiAxis; }; - multiAxis.tickSizeInner = ( - ...args: T[] - ): GetSetReturn => { + multiAxis.tickSizeInner = (...args: (number | number[])[]): any => { if (!args.length) { - return tickSizeInner as GetSetReturn; + return tickSizeInner; } tickSizeInner = Array.isArray(args[0]) ? args[0] : Number(args[0]); return multiAxis; }; - multiAxis.tickSizeOuter = ( - ...args: T[] - ): GetSetReturn => { + multiAxis.tickSizeOuter = (...args: number[]): any => { if (!args.length) { - return tickSizeOuter as GetSetReturn; + return tickSizeOuter; } tickSizeOuter = Number(args[0]); return multiAxis; }; - multiAxis.decorate = (...args) => { + multiAxis.decorate = (...args): any => { if (!args.length) { return decorate; } @@ -199,7 +195,7 @@ const multiAxis = (orient: Orient, baseAxis, scale): MultiAxis => { rebindAll(multiAxis, axisStore); - return multiAxis; + return multiAxis as MultiAxis; }; export const multiAxisTop = (scale) => multiAxis("top", axisOrdinalTop, scale); diff --git a/packages/perspective-viewer-d3fc/src/ts/d3fc/extent/extentLinear.ts b/packages/perspective-viewer-d3fc/src/ts/d3fc/extent/extentLinear.ts index 0f4932bfb9..05a50779d0 100644 --- a/packages/perspective-viewer-d3fc/src/ts/d3fc/extent/extentLinear.ts +++ b/packages/perspective-viewer-d3fc/src/ts/d3fc/extent/extentLinear.ts @@ -12,22 +12,28 @@ import * as d3Array from "d3-array"; import { defaultPadding } from "../padding/default"; -import { GetSetReturn, Pad, PadUnit, PaddingStrategy } from "../../types"; +import { Pad, PadUnit, PaddingStrategy } from "../../types"; export type SymmetricalAbout = number | null; export interface ExtentLinear { (data: any[]): PaddingStrategy; accessors: (nextAccessors?: any[]) => any; - pad: ( - ...args: T[] - ) => GetSetReturn; - padUnit: ( - ...args: T[] - ) => GetSetReturn; - include: (nextInclude?: number[]) => any; - symmetricalAbout: (nextSymmetricalAbout?: number | null) => any; - paddingStrategy: (nextPaddingStrategy?: any) => any; + + pad(): Pad; + pad(nextPad: Pad): ExtentLinear; + + padUnit(): PadUnit; + padUnit(nextPadUnit: PadUnit): ExtentLinear; + + include(): number[]; + include(nextInclude?: number[]): ExtentLinear; + + symmetricalAbout(): number | null; + symmetricalAbout(nextSymmetricalAbout?: number | null): ExtentLinear; + + paddingStrategy(): PaddingStrategy; + paddingStrategy(nextPaddingStrategy?: any): ExtentLinear; } export const extentLinear = function (): ExtentLinear { @@ -40,7 +46,9 @@ export const extentLinear = function (): ExtentLinear { let include: number[] = []; let paddingStrategy = defaultPadding(); - const instance: any = function instance(data): PaddingStrategy { + const instance: Partial = function instance( + data + ): PaddingStrategy { let values = new Array(data.length); let _iteratorNormalCompletion = true; let _didIteratorError = false; @@ -116,11 +124,9 @@ export const extentLinear = function (): ExtentLinear { //This function points directly at the paddingStrategy child object's //properties for backwards-compatibility. DEPRECATED. - instance.pad = function ( - ...args: T[] - ): GetSetReturn { - if (!arguments.length) { - return paddingStrategy.pad as GetSetReturn; + instance.pad = function (...args: Pad[]): any { + if (!args.length) { + return paddingStrategy.pad; } paddingStrategy.pad(args[0]); @@ -130,15 +136,9 @@ export const extentLinear = function (): ExtentLinear { //This function points directly at the paddingStrategy child object's //properties for backwards-compatibility. DEPRECATED. - instance.padUnit = function ( - ...args: T[] - ): GetSetReturn { - if (!arguments.length) { - return paddingStrategy.padUnit as GetSetReturn< - T, - PadUnit, - ExtentLinear - >; + instance.padUnit = function (...args: PadUnit[]): any { + if (!args.length) { + return paddingStrategy.padUnit; } paddingStrategy.padUnit(args[0]); @@ -146,53 +146,37 @@ export const extentLinear = function (): ExtentLinear { return instance; }; - instance.include = function ( - nextInclude?: T - ): GetSetReturn { - if (!arguments.length) { - return include as GetSetReturn; + instance.include = function (...args: number[][]): any { + if (!args.length) { + return include; } - include = nextInclude; + include = args[0]; return instance; }; - instance.symmetricalAbout = function < - T extends SymmetricalAbout | undefined = undefined - >( - nextSymmetricalAbout?: SymmetricalAbout - ): GetSetReturn { - if (!arguments.length) { - return symmetricalAbout as GetSetReturn< - T, - SymmetricalAbout, - ExtentLinear - >; + instance.symmetricalAbout = function (...args: SymmetricalAbout[]): any { + if (!args.length) { + return symmetricalAbout; } - symmetricalAbout = nextSymmetricalAbout; + symmetricalAbout = args[0]; return instance; }; - instance.paddingStrategy = function < - T extends PaddingStrategy | undefined = undefined - >(nextPaddingStrategy?: T): GetSetReturn { - if (!arguments.length) { - return paddingStrategy as GetSetReturn< - T, - PaddingStrategy, - ExtentLinear - >; + instance.paddingStrategy = function (...args: PaddingStrategy[]): any { + if (!args.length) { + return paddingStrategy; } - paddingStrategy = nextPaddingStrategy; + paddingStrategy = args[0]; return instance; }; - return instance; + return instance as ExtentLinear; }; let toConsumableArray = function (arr) { diff --git a/packages/perspective-viewer-d3fc/src/ts/d3fc/padding/default.ts b/packages/perspective-viewer-d3fc/src/ts/d3fc/padding/default.ts index 72658f264e..55a9f003b4 100644 --- a/packages/perspective-viewer-d3fc/src/ts/d3fc/padding/default.ts +++ b/packages/perspective-viewer-d3fc/src/ts/d3fc/padding/default.ts @@ -10,13 +10,13 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -import { GetSetReturn, Pad, PadUnit, PaddingStrategy } from "../../types"; +import { Pad, PadUnit, PaddingStrategy } from "../../types"; export const defaultPadding = (): PaddingStrategy => { let pad = [0, 0]; let padUnit: PadUnit = "percent" as const; - const padding: any = (extent) => { + const padding: Partial = (extent) => { switch (padUnit) { case "domain": { extent[0] -= pad[0]; @@ -35,11 +35,9 @@ export const defaultPadding = (): PaddingStrategy => { return extent; }; - padding.pad = function ( - ...args: T[] - ): GetSetReturn { - if (args.length === 0) { - return pad as GetSetReturn; + padding.pad = function (...args: Pad[]): any { + if (!args.length) { + return pad; } pad = args[0]; @@ -47,11 +45,9 @@ export const defaultPadding = (): PaddingStrategy => { return padding; }; - padding.padUnit = function ( - ...args: T[] - ): GetSetReturn { + padding.padUnit = function (...args: PadUnit[]): any { if (!args.length) { - return padUnit as GetSetReturn; + return padUnit; } padUnit = args[0]; @@ -59,5 +55,5 @@ export const defaultPadding = (): PaddingStrategy => { return padding; }; - return padding; + return padding as PaddingStrategy; }; diff --git a/packages/perspective-viewer-d3fc/src/ts/d3fc/padding/hardLimitZero.ts b/packages/perspective-viewer-d3fc/src/ts/d3fc/padding/hardLimitZero.ts index 998944a394..7bcde8b331 100644 --- a/packages/perspective-viewer-d3fc/src/ts/d3fc/padding/hardLimitZero.ts +++ b/packages/perspective-viewer-d3fc/src/ts/d3fc/padding/hardLimitZero.ts @@ -10,14 +10,14 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -import { GetSetReturn, Pad, PadUnit, PaddingStrategy } from "../../types"; +import { Pad, PadUnit, PaddingStrategy } from "../../types"; import { defaultPadding } from "./default"; import * as fc from "d3fc"; export const hardLimitZeroPadding = (): PaddingStrategy => { const _defaultPadding = defaultPadding(); - const padding: any = (extent) => { + const padding: Partial = (extent) => { let pad = _defaultPadding.pad(); let padUnit = _defaultPadding.padUnit(); @@ -46,19 +46,15 @@ export const hardLimitZeroPadding = (): PaddingStrategy => { return extent; }; - padding.pad = function ( - nextPad?: T - ): T extends undefined ? Pad : T extends Pad ? PaddingStrategy : never { - return padding; + padding.pad = function (..._args: Pad[]): any { + return _defaultPadding.pad(); }; - padding.padUnit = function ( - nextPadUnit?: T - ): GetSetReturn { - return padding; + padding.padUnit = function (..._args: PadUnit[]): any { + return _defaultPadding.padUnit(); }; fc.rebindAll(padding, _defaultPadding); - return padding; + return padding as PaddingStrategy; }; diff --git a/packages/perspective-viewer-d3fc/src/ts/gridlines/gridlines.ts b/packages/perspective-viewer-d3fc/src/ts/gridlines/gridlines.ts index f54cef6d4b..3924493943 100644 --- a/packages/perspective-viewer-d3fc/src/ts/gridlines/gridlines.ts +++ b/packages/perspective-viewer-d3fc/src/ts/gridlines/gridlines.ts @@ -11,7 +11,7 @@ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ import * as fc from "d3fc"; -import { GetSetReturn } from "../types"; +import { D3Scale, Orientation } from "../types"; const mainGridSvg = (settings) => (x) => x @@ -34,12 +34,21 @@ const crossGridCanvas = (settings) => (c) => { export interface WithGridLines { (...args): any; - orient: ( - ...args: T[] - ) => GetSetReturn; - canvas: ( - ...args: T[] - ) => GetSetReturn; + + orient(): Orientation; + orient(nextOrient: Orientation): WithGridLines; + + canvas(): boolean; + canvas(nextCanvas: boolean): WithGridLines; + + xScale(): D3Scale; + xScale(xScale: D3Scale): WithGridLines; + + yScale(): D3Scale; + yScale(yScale: D3Scale): WithGridLines; + + context(): any; + context(context: any): WithGridLines; } export default (series, settings): WithGridLines => { @@ -54,7 +63,7 @@ export default (series, settings): WithGridLines => { let mainGrid = mainGridSvg(settings); let crossGrid = crossGridSvg; - const _withGridLines: any = function (...args) { + const _withGridLines: Partial = function (...args) { if (canvas) { seriesMulti = fc.seriesCanvasMulti().context(context); annotationGridline = fc.annotationCanvasGridline(); @@ -74,7 +83,7 @@ export default (series, settings): WithGridLines => { return multi.series([gridlines, series])(...args); }; - _withGridLines.orient = (...args) => { + _withGridLines.orient = (...args: Orientation[]): any => { if (!args.length) { return orient; } @@ -82,17 +91,15 @@ export default (series, settings): WithGridLines => { return _withGridLines; }; - _withGridLines.canvas = ( - ...args: T[] - ): GetSetReturn => { + _withGridLines.canvas = (...args: boolean[]): any => { if (!args.length) { - return canvas as GetSetReturn; + return canvas; } canvas = args[0]; return _withGridLines; }; - _withGridLines.xScale = (...args) => { + _withGridLines.xScale = (...args): any => { if (!args.length) { return xScale; } @@ -100,7 +107,7 @@ export default (series, settings): WithGridLines => { return _withGridLines; }; - _withGridLines.yScale = (...args) => { + _withGridLines.yScale = (...args): any => { if (!args.length) { return yScale; } @@ -108,7 +115,7 @@ export default (series, settings): WithGridLines => { return _withGridLines; }; - _withGridLines.context = (...args) => { + _withGridLines.context = (...args): any => { if (!args.length) { return context; } @@ -116,5 +123,5 @@ export default (series, settings): WithGridLines => { return _withGridLines; }; - return _withGridLines; + return _withGridLines as WithGridLines; }; diff --git a/packages/perspective-viewer-d3fc/src/ts/layout/gridLayoutMultiChart.ts b/packages/perspective-viewer-d3fc/src/ts/layout/gridLayoutMultiChart.ts index 2cf5ed1ccd..d87bc482f6 100644 --- a/packages/perspective-viewer-d3fc/src/ts/layout/gridLayoutMultiChart.ts +++ b/packages/perspective-viewer-d3fc/src/ts/layout/gridLayoutMultiChart.ts @@ -10,23 +10,19 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -import { GetSetReturn } from "../types"; import { getOrCreateElement } from "../utils/utils"; export interface GridLayoutMultiChart { (container: any): any; - elementsPrefix: ( - ...args: T[] - ) => GetSetReturn; + elementsPrefix(): string; + elementsPrefix(nextPrefix: string): GridLayoutMultiChart; - padding: ( - ...args: T[] - ) => GetSetReturn; + padding(): string; + padding(nextPadding: string): GridLayoutMultiChart; - svg: ( - ...args: T[] - ) => GetSetReturn; + svg(): boolean; + svg(nextSvg: boolean): GridLayoutMultiChart; chartContainer: () => any; chartEnter: () => any; @@ -47,7 +43,9 @@ export function gridLayoutMultiChart(): GridLayoutMultiChart { let svg = true; let padding = null; - const _gridLayoutMultiChart: any = (container) => { + const _gridLayoutMultiChart: Partial = ( + container + ) => { const outerContainer = getOrCreateElement( container, "div.outer-container", @@ -139,36 +137,24 @@ export function gridLayoutMultiChart(): GridLayoutMultiChart { } }; - _gridLayoutMultiChart.padding = ( - ...args: T[] - ): GetSetReturn => { + _gridLayoutMultiChart.padding = (...args: string[]): any => { if (!args.length) { - return padding as GetSetReturn; + return padding; } padding = args[0]; return _gridLayoutMultiChart; }; - _gridLayoutMultiChart.svg = ( - ...args: T[] - ): GetSetReturn => { + _gridLayoutMultiChart.svg = (...args: boolean[]): any => { if (!args.length) { - return svg as GetSetReturn; + return svg; } svg = args[0]; return _gridLayoutMultiChart; }; - _gridLayoutMultiChart.elementsPrefix = < - T extends string | undefined = undefined - >( - ...args: T[] - ): GetSetReturn => { + _gridLayoutMultiChart.elementsPrefix = (...args: string[]): any => { if (!args.length) { - return elementsPrefix as GetSetReturn< - T, - string, - GridLayoutMultiChart - >; + return elementsPrefix; } elementsPrefix = args[0]; return _gridLayoutMultiChart; @@ -184,5 +170,5 @@ export function gridLayoutMultiChart(): GridLayoutMultiChart { _gridLayoutMultiChart.containerSize = () => containerSize; - return _gridLayoutMultiChart; + return _gridLayoutMultiChart as GridLayoutMultiChart; } diff --git a/packages/perspective-viewer-d3fc/src/ts/legend/legend.ts b/packages/perspective-viewer-d3fc/src/ts/legend/legend.ts index 62e2f891b9..a6dbc57557 100644 --- a/packages/perspective-viewer-d3fc/src/ts/legend/legend.ts +++ b/packages/perspective-viewer-d3fc/src/ts/legend/legend.ts @@ -16,7 +16,7 @@ import scrollableLegend from "./scrollableLegend"; import { withoutOpacity } from "../series/seriesColors"; import { getChartElement } from "../plugin/root"; import { getOrCreateElement } from "../utils/utils"; -import { D3Scale, GetSetReturn } from "../types"; +import { D3Scale } from "../types"; export type LegendComponentSettings = { hideKeys?: any[]; @@ -52,15 +52,15 @@ function symbolScale(fromScale) { interface LegendComponent { (container): void; - settings: ( - ...args: T[] - ) => GetSetReturn; - scale: ( - ...args: T[] - ) => GetSetReturn; - color: | undefined = undefined>( - ...args: T[] - ) => GetSetReturn, LegendComponent>; + + settings(): LegendComponentSettings; + settings(nextSettings: LegendComponentSettings): LegendComponent; + + scale(): D3Scale | null; + scale(nextScale: D3Scale | null): LegendComponent; + + color(): d3.ScaleOrdinal; + color(nextColor: d3.ScaleOrdinal): LegendComponent; } function legendComponent( @@ -71,7 +71,7 @@ function legendComponent( let scale = null; // type? let color: D3Scale | null = null; - const legend: any = (container) => { + const legend: Partial = (container) => { if (scale && scale.range().length > 1) { const scrollLegend = scrollLegendComponent(settings); scrollLegend @@ -136,42 +136,30 @@ function legendComponent( } }; - legend.settings = < - T extends LegendComponentSettings | undefined = undefined - >( - ...args: T[] - ): GetSetReturn => { + legend.settings = (...args: LegendComponentSettings[]): any => { if (args.length === 0) { - return settings as GetSetReturn< - T, - LegendComponentSettings, - LegendComponent - >; + return settings; } settings = args[0]; return legend; }; - legend.scale = ( - ...args - ): GetSetReturn => { + legend.scale = (...args: (D3Scale | null)[]): any => { if (!args.length) { - return scale as GetSetReturn; + return scale; } scale = scaleModifier ? scaleModifier(args[0]) : args[0]; return legend; }; - legend.color = ( - ...args: T[] - ): GetSetReturn => { + legend.color = (...args: D3Scale[]): any => { if (!args.length) { - return color as GetSetReturn; + return color; } color = args[0]; return legend; }; - return legend; + return legend as LegendComponent; } diff --git a/packages/perspective-viewer-d3fc/src/ts/series/seriesColors.ts b/packages/perspective-viewer-d3fc/src/ts/series/seriesColors.ts index 9f61061027..53540d0ae5 100644 --- a/packages/perspective-viewer-d3fc/src/ts/series/seriesColors.ts +++ b/packages/perspective-viewer-d3fc/src/ts/series/seriesColors.ts @@ -13,7 +13,7 @@ import * as d3 from "d3"; import { groupFromKey } from "./seriesKey"; import { getValuesByColumn } from "../data/utils"; -import { GetSetReturn, Settings } from "../types"; +import { Settings } from "../types"; export function seriesColors( settings: Settings @@ -60,18 +60,18 @@ type ColorScaleMapFunc = (d: any) => string; interface ColorScale { (): d3.ScaleOrdinal | null; - settings: ( - nextSettings?: T - ) => GetSetReturn; - domain: ( - nextDomain?: T - ) => GetSetReturn; - defaultColors: ( - nextDefaultColors?: T - ) => GetSetReturn; - mapFunction: ( - nextMapFunction?: T - ) => GetSetReturn; + + settings(): Settings; + settings(nextSettings: Settings): ColorScale; + + domain(): any[]; + domain(nextDomain: any[]): ColorScale; + + defaultColors(): string[]; + defaultColors(nextDefaultColors: string[]): ColorScale; + + mapFunction(): ColorScaleMapFunc; + mapFunction(nextMapFunction: ColorScaleMapFunc): ColorScale; } export function colorScale(): ColorScale { @@ -81,7 +81,7 @@ export function colorScale(): ColorScale { let mapFunction = (d) => withOpacity(d, settings.colorStyles && settings.colorStyles.opacity); - const colors: any = (): d3.ScaleOrdinal | null => { + const colors: ColorScale = (): d3.ScaleOrdinal | null => { const styles = settings.colorStyles; const defaults = defaultColors || [styles.series]; if (defaults || domain.length > 1) { @@ -91,52 +91,40 @@ export function colorScale(): ColorScale { return null; }; - colors.domain = ( - ...args: T[] - ): GetSetReturn => { + colors.domain = (...args: any[][]): any => { if (args.length === 0) { - return domain as GetSetReturn; + return domain; } domain = args[0]; return colors; }; - colors.defaultColors = ( - ...args: T[] - ): GetSetReturn => { + colors.defaultColors = (...args: string[][]): any => { if (!args.length) { - return defaultColors as GetSetReturn; + return defaultColors; } defaultColors = args[0]; return colors; }; - colors.mapFunction = ( - ...args: T[] - ): GetSetReturn => { + colors.mapFunction = (...args: ColorScaleMapFunc[]): any => { if (!args.length) { - return mapFunction as GetSetReturn< - T, - ColorScaleMapFunc, - ColorScale - >; + return mapFunction; } mapFunction = args[0]; return colors; }; - colors.settings = ( - ...args: T[] - ): GetSetReturn => { + colors.settings = (...args: Settings[]): any => { if (!args.length) { - return settings as GetSetReturn; + return settings; } settings = args[0]; return colors; }; - return colors; + return colors as ColorScale; } export function withoutOpacity(color) { diff --git a/packages/perspective-viewer-d3fc/src/ts/series/sunburst/sunburstSeries.ts b/packages/perspective-viewer-d3fc/src/ts/series/sunburst/sunburstSeries.ts index 2a6aa8408d..a85ab1880a 100644 --- a/packages/perspective-viewer-d3fc/src/ts/series/sunburst/sunburstSeries.ts +++ b/packages/perspective-viewer-d3fc/src/ts/series/sunburst/sunburstSeries.ts @@ -13,7 +13,7 @@ import { drawArc, arcVisible } from "./sunburstArc"; import { labelVisible, labelTransform, cropLabel } from "./sunburstLabel"; import { clickHandler } from "./sunburstClick"; -import { D3Scale, GetSetReturn, Settings } from "../../types"; +import { D3Scale, Settings } from "../../types"; export interface SunburstData extends d3.HierarchyNode { children: this[]; @@ -39,25 +39,20 @@ export interface SunburstData extends d3.HierarchyNode { export interface SunburstSeries { (sunburstElement: any): void; - settings: ( - ...args: T[] - ) => GetSetReturn; + settings(): Settings; + settings(settings: Settings): SunburstSeries; - split: ( - ...args: T[] - ) => GetSetReturn; + split(): string; + split(split: string): SunburstSeries; - data: ( - ...args: T[] - ) => GetSetReturn; + data(): SunburstData; + data(data: SunburstData): SunburstSeries; - color: ( - ...args: T[] - ) => GetSetReturn; + color(): D3Scale; + color(color: D3Scale): SunburstSeries; - radius: ( - ...args: T[] - ) => GetSetReturn; + radius(): number; + radius(radius: number): SunburstSeries; } export function sunburstSeries(): SunburstSeries { @@ -67,7 +62,7 @@ export function sunburstSeries(): SunburstSeries { let color: D3Scale | null = null; let radius = null; - const _sunburstSeries: any = (sunburstElement) => { + const _sunburstSeries: Partial = (sunburstElement) => { const segment = sunburstElement .selectAll("g.segment") .data(data.descendants().slice(1)); @@ -136,55 +131,45 @@ export function sunburstSeries(): SunburstSeries { .on("click", (d) => onClick(d, false)); }; - _sunburstSeries.settings = ( - ...args: T[] - ): GetSetReturn => { + _sunburstSeries.settings = (...args: Settings[]): any => { if (!args.length) { - return settings as GetSetReturn; + return settings; } settings = args[0]; return _sunburstSeries; }; - _sunburstSeries.split = ( - ...args: T[] - ): GetSetReturn => { + _sunburstSeries.split = (...args: string[]): any => { if (!args.length) { - return split as GetSetReturn; + return split; } split = args[0]; return _sunburstSeries; }; - _sunburstSeries.data = ( - ...args: T[] - ): GetSetReturn => { + _sunburstSeries.data = (...args: SunburstData[]): any => { if (!args.length) { - return data as GetSetReturn; + return data; } data = args[0]; return _sunburstSeries; }; - _sunburstSeries.color = ( - ...args: T[] - ): GetSetReturn => { + _sunburstSeries.color = (...args: D3Scale[]): any => { if (!args.length) { - return color as GetSetReturn; + return color; } color = args[0]; return _sunburstSeries; }; - _sunburstSeries.radius = ( - ...args: T[] - ): GetSetReturn => { + _sunburstSeries.radius = (...args: number[]): any => { if (!args.length) { - return radius as GetSetReturn; + return radius; } radius = args[0]; return _sunburstSeries; }; - return _sunburstSeries; + return _sunburstSeries as SunburstSeries; } diff --git a/packages/perspective-viewer-d3fc/src/ts/series/xy-scatter/xyScatterSeries.ts b/packages/perspective-viewer-d3fc/src/ts/series/xy-scatter/xyScatterSeries.ts index 0bad3da4d0..65e9b96489 100644 --- a/packages/perspective-viewer-d3fc/src/ts/series/xy-scatter/xyScatterSeries.ts +++ b/packages/perspective-viewer-d3fc/src/ts/series/xy-scatter/xyScatterSeries.ts @@ -20,7 +20,7 @@ import { hardLimitZeroPadding } from "../../d3fc/padding/hardLimitZero"; import zoomableChart from "../../zoom/zoomableChart"; import nearbyTip from "../../tooltip/nearbyTip"; import { symbolsObj } from "../seriesSymbols"; -import { D3Scale, GetSetReturn, Settings } from "../../types"; +import { D3Scale, Settings } from "../../types"; /** * Define a clamped scaling factor based on the container size for bubble plots. @@ -42,18 +42,18 @@ function interpolate_scale([x1, y1], [x2, y2]) { export interface XYScatterSeries { (container: any): void; - settings: ( - ...args: T[] - ) => GetSetReturn; - data: ( - ...args: T[] - ) => GetSetReturn; - color: ( - ...args: T[] - ) => GetSetReturn; - symbols: ( - ...args: T[] - ) => GetSetReturn; + + settings(): Settings; + settings(settings: Settings): XYScatterSeries; + + data(): Record[][]; + data(data: Record[][]): XYScatterSeries; + + color(): D3Scale; + color(color: D3Scale): XYScatterSeries; + + symbols(): D3Scale; + symbols(symbols: D3Scale): XYScatterSeries; } /** @@ -66,7 +66,7 @@ export default function xyScatterSeries(): XYScatterSeries { let color = null; let symbols = null; - const _xyScatterSeries: any = (container) => { + const _xyScatterSeries: Partial = (container) => { const colorBy = settings.realValues[2]; let hasColorBy = !!colorBy; const symbolCol = settings.realValues[4]; @@ -154,42 +154,34 @@ export default function xyScatterSeries(): XYScatterSeries { container.call(toolTip); }; - _xyScatterSeries.settings = ( - ...args: T[] - ): GetSetReturn => { + _xyScatterSeries.settings = (...args: Settings[]): any => { if (!args.length) { - return settings as GetSetReturn; + return settings; } settings = args[0]; return _xyScatterSeries; }; - _xyScatterSeries.data = ( - ...args: T[] - ): GetSetReturn => { + _xyScatterSeries.data = (...args: any[][]): any => { if (!args.length) { - return data as GetSetReturn; + return data; } data = args[0]; return _xyScatterSeries; }; - _xyScatterSeries.color = ( - ...args: T[] - ): GetSetReturn => { + _xyScatterSeries.color = (...args: D3Scale[]): any => { if (!args.length) { - return color as GetSetReturn; + return color; } color = args[0]; return _xyScatterSeries; }; - _xyScatterSeries.symbols = ( - ...args: T[] - ): GetSetReturn => { + _xyScatterSeries.symbols = (...args: D3Scale[]): any => { if (!args.length) { - return symbols as GetSetReturn; + return symbols; } symbols = args[0]; return _xyScatterSeries; }; - return _xyScatterSeries; + return _xyScatterSeries as XYScatterSeries; } diff --git a/packages/perspective-viewer-d3fc/src/ts/tooltip/nearbyTip.ts b/packages/perspective-viewer-d3fc/src/ts/tooltip/nearbyTip.ts index 53de40c503..39a2657137 100644 --- a/packages/perspective-viewer-d3fc/src/ts/tooltip/nearbyTip.ts +++ b/packages/perspective-viewer-d3fc/src/ts/tooltip/nearbyTip.ts @@ -16,7 +16,7 @@ import { withOpacity } from "../series/seriesColors.js"; import { findBestFromData } from "../data/findBest"; import { raiseEvent } from "./selectionEvent"; import { SplitData } from "../data/splitData"; -import { D3Scale, GetSetReturn, Settings } from "../types"; +import { D3Scale, Settings } from "../types"; export type AltDataWithScale = { data: SplitData[][]; @@ -30,39 +30,39 @@ export interface SizeArg { interface NearbyTip { (selection: any): void; - scaleFactor: ( - ...args: T[] - ) => GetSetReturn; - settings: ( - ...args: T[] - ) => GetSetReturn; - xScale: ( - ...args: T[] - ) => GetSetReturn; - yScale: ( - ...args: T[] - ) => GetSetReturn; - color: ( - ...args: T[] - ) => GetSetReturn; - size: ( - ...args: T[] - ) => GetSetReturn; - canvas: ( - ...args: T[] - ) => GetSetReturn; - data: ( - ...args: T[] - ) => GetSetReturn; - xValueName: ( - ...args: T[] - ) => GetSetReturn; - yValueName: ( - ...args: T[] - ) => GetSetReturn; - altDataWithScale: ( - ...args: T[] - ) => GetSetReturn; + + scaleFactor(): number; + scaleFactor(scaleFactor: number): NearbyTip; + + settings(): Settings; + settings(settings: Settings): NearbyTip; + + xScale(): D3Scale; + xScale(xScale: D3Scale): NearbyTip; + + yScale(): D3Scale; + yScale(yScale: D3Scale): NearbyTip; + + color(): D3Scale; + color(color: D3Scale): NearbyTip; + + size(): SizeArg; + size(size: SizeArg): NearbyTip; + + canvas(): boolean; + canvas(canvas: boolean): NearbyTip; + + data(): Record[][]; + data(data: Record[][]): NearbyTip; + + xValueName(): string; + xValueName(xValueName: string): NearbyTip; + + yValueName(): string; + yValueName(yValueName: string): NearbyTip; + + altDataWithScale(): AltDataWithScale; + altDataWithScale(altDataWithScale: AltDataWithScale): NearbyTip; } export default (): NearbyTip => { @@ -79,7 +79,7 @@ export default (): NearbyTip => { let altDataWithScale = null; let scale_factor = 1; - const nearbyTip: any = (selection) => { + const nearbyTip: Partial = (selection) => { const chartPlotArea = `d3fc-${canvas ? "canvas" : "svg"}.plot-area`; if (xScale || yScale) { let tooltipData = null; @@ -173,121 +173,93 @@ export default (): NearbyTip => { return { data: best1, scale: yScale }; }; - nearbyTip.scaleFactor = ( - ...args: T[] - ): GetSetReturn => { + nearbyTip.scaleFactor = (...args: number[]): any => { if (!args.length) { - return scale_factor as GetSetReturn; + return scale_factor; } scale_factor = args[0]; return nearbyTip; }; - nearbyTip.xScale = ( - ...args: T[] - ): GetSetReturn => { + nearbyTip.xScale = (...args: D3Scale[]): any => { if (!args.length) { - return xScale as GetSetReturn; + return xScale; } xScale = args[0]; return nearbyTip; }; - nearbyTip.yScale = ( - ...args: T[] - ): GetSetReturn => { + nearbyTip.yScale = (...args: D3Scale[]): any => { if (!args.length) { - return yScale as GetSetReturn; + return yScale; } yScale = args[0]; return nearbyTip; }; - nearbyTip.color = ( - ...args: T[] - ): GetSetReturn => { + nearbyTip.color = (...args: D3Scale[]): any => { if (!args.length) { - return color as GetSetReturn; + return color; } color = args[0]; return nearbyTip; }; - nearbyTip.size = ( - ...args: T[] - ): GetSetReturn => { + nearbyTip.size = (...args: SizeArg[]): any => { if (!args.length) { - return size as GetSetReturn; + return size; } size = args[0] ? args[0].copy().range([40, 4000]) : null; return nearbyTip; }; - nearbyTip.canvas = ( - ...args: T[] - ): GetSetReturn => { + nearbyTip.canvas = (...args: boolean[]): any => { if (!args.length) { - return canvas as GetSetReturn; + return canvas; } canvas = args[0]; return nearbyTip; }; - nearbyTip.data = < - T extends Record[][] | undefined = undefined - >( - ...args: T[] - ): GetSetReturn[][], NearbyTip> => { + nearbyTip.data = (...args: Record[][][]): any => { if (!args.length) { - return data as GetSetReturn[][], NearbyTip>; + return data; } data = args[0]; return nearbyTip; }; - nearbyTip.xValueName = ( - ...args: T[] - ): GetSetReturn => { + nearbyTip.xValueName = (...args: string[]): any => { if (!args.length) { - return xValueName as GetSetReturn; + return xValueName; } xValueName = args[0]; return nearbyTip; }; - nearbyTip.yValueName = ( - ...args: T[] - ): GetSetReturn => { + nearbyTip.yValueName = (...args: string[]): any => { if (!args.length) { - return yValueName as GetSetReturn; + return yValueName; } yValueName = args[0]; return nearbyTip; }; - nearbyTip.altDataWithScale = ( - ...args: T[] - ): GetSetReturn => { + nearbyTip.altDataWithScale = (...args: AltDataWithScale[]): any => { if (!args.length) { - return altDataWithScale as GetSetReturn; + return altDataWithScale; } altDataWithScale = args[0]; return nearbyTip; }; - nearbyTip.settings = ( - ...args: T[] - ): GetSetReturn => { + nearbyTip.settings = (...args: Settings[]): any => { if (!args.length) { - return base.settings() as unknown as GetSetReturn< - T, - Settings, - NearbyTip - >; + return base.settings(); } base.settings(args[0]); return nearbyTip; }; fc.rebindAll(nearbyTip, base); - return nearbyTip; + return nearbyTip as NearbyTip; }; diff --git a/packages/perspective-viewer-d3fc/src/ts/tooltip/tooltip.ts b/packages/perspective-viewer-d3fc/src/ts/tooltip/tooltip.ts index 10c493894a..bc7778b383 100644 --- a/packages/perspective-viewer-d3fc/src/ts/tooltip/tooltip.ts +++ b/packages/perspective-viewer-d3fc/src/ts/tooltip/tooltip.ts @@ -16,19 +16,19 @@ import { getOrCreateElement, isElementOverflowing } from "../utils/utils"; import tooltipTemplate from "../../html/tooltip.html"; import { generateHtml } from "./generateHTML"; import { selectionEvent } from "./selectionEvent"; -import { GetSetReturn, Settings } from "../types"; +import { Settings } from "../types"; export interface ToolTip { (selection: any): void; // double check the return value is void. - alwaysShow: ( - ...args: T[] - ) => GetSetReturn; - centered: ( - ...args: T[] - ) => GetSetReturn; - settings: ( - ...args: T[] - ) => GetSetReturn; + + alwaysShow(): boolean; + alwaysShow(alwaysShow: boolean): ToolTip; + + centered(): boolean; + centered(centered: boolean): ToolTip; + + settings(): Settings; + settings(settings: Settings): ToolTip; } export const tooltip = (): ToolTip => { @@ -73,31 +73,25 @@ export const tooltip = (): ToolTip => { } }; - _tooltip.alwaysShow = ( - ...args: T[] - ): GetSetReturn => { + _tooltip.alwaysShow = (...args: boolean[]): any => { if (!args.length) { - return alwaysShow as GetSetReturn; + return alwaysShow; } alwaysShow = args[0]; return _tooltip; }; - _tooltip.centered = ( - ...args: T[] - ): GetSetReturn => { + _tooltip.centered = (...args: boolean[]): any => { if (!args.length) { - return centered as GetSetReturn; + return centered; } centered = args[0]; return _tooltip; }; - _tooltip.settings = ( - ...args: T[] - ): GetSetReturn => { + _tooltip.settings = (...args: Settings[]): any => { if (!args.length) { - return settings as GetSetReturn; + return settings; } settings = args[0]; return _tooltip; diff --git a/packages/perspective-viewer-d3fc/src/ts/types.ts b/packages/perspective-viewer-d3fc/src/ts/types.ts index 87ffb78fad..6fe8aa96fd 100644 --- a/packages/perspective-viewer-d3fc/src/ts/types.ts +++ b/packages/perspective-viewer-d3fc/src/ts/types.ts @@ -37,20 +37,14 @@ export interface Chart { export type PadUnit = "percent" | "domain"; export type Pad = [number, number]; -export type GetSetReturn = T extends undefined - ? Arg - : T extends Arg - ? Func - : never; - export interface PaddingStrategy { (extent: any): any; - pad: ( - nextPad?: T - ) => GetSetReturn; - padUnit: ( - nextPadUnit?: T - ) => GetSetReturn; + + pad(): Pad; + pad(nextPad: Pad): this; + + padUnit(): PadUnit; + padUnit(nextPadUnit: PadUnit): this; } export type Axis = [number, number]; @@ -86,8 +80,6 @@ export type TreemapValue = { treemapRoute?: any[]; // string[]? }; -// Are these a particular type of settings? -// Question: Is there a better type def for this? export type Settings = { hideKeys?: any[]; agg_paths?: any; // any[]? @@ -103,6 +95,7 @@ export type Settings = { splitValues: any[]; textStyles: TextStyles; sunburstLevel?: any; + columns?: Record>; // Need to confirm this type. treemaps?: Record; }; @@ -119,21 +112,21 @@ export type ValueName = export interface Domain { (data: any[]): any; - valueName: ( - ...args: T[] - ) => GetSetReturn; - valueNames: ( - ...args: T[] - ) => GetSetReturn; - orient?: ( - ...args: T[] - ) => GetSetReturn; - pad: ( - ...args: T[] - ) => GetSetReturn; - padUnit: ( - ...args: T[] - ) => GetSetReturn; + + valueName(): ValueName; + valueName(nextValueName: ValueName): this; + + valueNames(): ValueName[]; + valueNames(nextValueNames: ValueName[]): this; + + orient(): Orientation; + orient(nextOrient: Orientation): this; + + pad(): Pad; + pad(nextPad: Pad): this; + + padUnit(): PadUnit; + padUnit(nextPadUnit: PadUnit): this; } export type DomainTuple = [number, number]; @@ -150,17 +143,14 @@ export interface ComponentData { export interface Component { (): ComponentData; - domain: ( - ...args: T[] - ) => GetSetReturn; + domain(): Domain; + domain(nextDomain: Domain): this; - orient: ( - ...args: T[] - ) => GetSetReturn; + orient(): Orientation; + orient(nextOrient: Orientation): this; - settingName: ( - ...args: T[] - ) => GetSetReturn; + settingName(): SettingNameValues; + settingName(nextSettingName: SettingNameValues): this; } export interface ScaleSequential extends d3.ScaleSequential {