From 20c34f17c8a49bc4a608631f4d1f7b4140b5270e Mon Sep 17 00:00:00 2001 From: Gordon Smith Date: Mon, 11 Nov 2024 07:48:42 +0000 Subject: [PATCH] fix: Revert arguments removal Signed-off-by: Gordon Smith --- packages/api/src/ITooltip.ts | 8 ++-- packages/chart/src/Axis.ts | 8 ++-- packages/chart/src/Bubble.ts | 4 +- packages/chart/src/D3Cloud.ts | 26 ++++++------ packages/chart/src/Pie.ts | 2 +- packages/chart/src/StatChart.ts | 2 +- packages/chart/src/Summary.ts | 4 +- packages/chart/src/SummaryC.ts | 4 +- packages/chart/src/WordCloud.ts | 57 --------------------------- packages/chart/src/XYAxis.ts | 4 +- packages/common/src/Class.ts | 2 +- packages/common/src/Database.ts | 38 +++++++++--------- packages/common/src/HTMLWidget.ts | 2 +- packages/common/src/List.ts | 2 - packages/common/src/Palette.ts | 14 +++---- packages/common/src/PropertyExt.ts | 12 +++--- packages/common/src/SVGWidget.ts | 10 ++--- packages/common/src/SVGZoomWidget.ts | 2 +- packages/common/src/Shape.ts | 2 +- packages/common/src/Surface.ts | 4 +- packages/common/src/TextBox.ts | 2 +- packages/common/src/TitleBar.ts | 6 +-- packages/common/src/Transition.ts | 6 +-- packages/common/src/Utility.ts | 25 ++++++------ packages/common/src/Widget.ts | 34 ++++++++-------- packages/comms/src/connection.ts | 2 +- packages/comms/src/ecl/scope.ts | 2 +- packages/dgrid/index.html | 1 + packages/dgrid/src/Common.ts | 33 +--------------- packages/dgrid/src/DatasourceTable.ts | 5 --- packages/dgrid/src/Table.ts | 26 +++++++----- 31 files changed, 131 insertions(+), 218 deletions(-) diff --git a/packages/api/src/ITooltip.ts b/packages/api/src/ITooltip.ts index 307136f7e3..880d2e07e1 100644 --- a/packages/api/src/ITooltip.ts +++ b/packages/api/src/ITooltip.ts @@ -208,8 +208,8 @@ ITooltip.prototype.publish("tooltipOffset", 8, "number", "Offset from the cursor const tooltipLabelFormat = ITooltip.prototype.tooltipLabelFormat; ITooltip.prototype.tooltipLabelFormat = function (_?): string | ITooltip { - const retVal = tooltipLabelFormat.call(this, _); - if (_ !== undefined) { + const retVal = tooltipLabelFormat.apply(this, arguments); + if (arguments.length) { this._labelFormatter = d3Format(_); } return retVal; @@ -217,8 +217,8 @@ ITooltip.prototype.tooltipLabelFormat = function (_?): string | ITooltip { const tooltipValueFormat = ITooltip.prototype.tooltipValueFormat; ITooltip.prototype.tooltipValueFormat = function (_?): string | ITooltip { - const retVal = tooltipValueFormat.call(this, _); - if (_ !== undefined) { + const retVal = tooltipValueFormat.apply(this, arguments); + if (arguments.length) { this._valueFormatter = d3Format(_); } return retVal; diff --git a/packages/chart/src/Axis.ts b/packages/chart/src/Axis.ts index a39d0cfafa..8ffd7f3753 100644 --- a/packages/chart/src/Axis.ts +++ b/packages/chart/src/Axis.ts @@ -114,13 +114,13 @@ export class Axis extends SVGWidget { } domain(_?) { - if (_ === undefined) return this.d3Scale.domain(); + if (!arguments.length) return this.d3Scale.domain(); this.d3Scale.domain(_); return this; } range(_?) { - if (_ === undefined) { + if (!arguments.length) { if (this.d3Scale.rangeRoundBands) { return this.d3Scale.rangeExtent(); } else if (this.d3Scale.rangeRound) { @@ -745,7 +745,7 @@ Axis.prototype.publish("padding", 0, "number", "Padding space at top of axis (pi Axis.prototype._origType = Axis.prototype.type; Axis.prototype.type = function (_?: string) { - const retVal = Axis.prototype._origType.call(this, _); + const retVal = Axis.prototype._origType.apply(this, arguments); if (_ !== undefined) { this._type = _; this.updateScale(); @@ -755,7 +755,7 @@ Axis.prototype.type = function (_?: string) { Axis.prototype._origTimePattern = Axis.prototype.timePattern; Axis.prototype.timePattern = function (_?: string) { - const retVal = Axis.prototype._origTimePattern.call(this, _); + const retVal = Axis.prototype._origTimePattern.apply(this, arguments); if (_ !== undefined) { this._timePattern = _; this.updateScale(); diff --git a/packages/chart/src/Bubble.ts b/packages/chart/src/Bubble.ts index 636e3eb7c6..2c2116fa15 100644 --- a/packages/chart/src/Bubble.ts +++ b/packages/chart/src/Bubble.ts @@ -36,8 +36,8 @@ export class Bubble extends SVGWidget { size(): ISize; size(_): this; size(_?): ISize | this { - const retVal = super.size(_); - if (_ !== undefined) { + const retVal = super.size.apply(this, arguments); + if (arguments.length) { this.d3Pack .size([this.width(), this.height()]) ; diff --git a/packages/chart/src/D3Cloud.ts b/packages/chart/src/D3Cloud.ts index 8f24c8b7cf..dd23227718 100644 --- a/packages/chart/src/D3Cloud.ts +++ b/packages/chart/src/D3Cloud.ts @@ -27,7 +27,7 @@ export function d3Cloud() { let canvas = cloudCanvas; cloud.canvas = function (_?) { - return _ !== undefined ? (canvas = functor(_), cloud) : canvas; + return arguments.length ? (canvas = functor(_), cloud) : canvas; }; cloud.start = function () { @@ -150,51 +150,51 @@ export function d3Cloud() { } cloud.timeInterval = function (_?) { - return _ !== undefined ? (timeInterval = _ == null ? Infinity : _, cloud) : timeInterval; + return arguments.length ? (timeInterval = _ == null ? Infinity : _, cloud) : timeInterval; }; cloud.words = function (_?) { - return _ !== undefined ? (words = _, cloud) : words; + return arguments.length ? (words = _, cloud) : words; }; cloud.size = function (_?) { - return _ !== undefined ? (size = [+_[0], +_[1]], cloud) : size; + return arguments.length ? (size = [+_[0], +_[1]], cloud) : size; }; cloud.font = function (_?) { - return _ !== undefined ? (font = functor(_), cloud) : font; + return arguments.length ? (font = functor(_), cloud) : font; }; cloud.fontStyle = function (_?) { - return _ !== undefined ? (fontStyle = functor(_), cloud) : fontStyle; + return arguments.length ? (fontStyle = functor(_), cloud) : fontStyle; }; cloud.fontWeight = function (_?) { - return _ !== undefined ? (fontWeight = functor(_), cloud) : fontWeight; + return arguments.length ? (fontWeight = functor(_), cloud) : fontWeight; }; cloud.rotate = function (_?) { - return _ !== undefined ? (rotate = functor(_), cloud) : rotate; + return arguments.length ? (rotate = functor(_), cloud) : rotate; }; cloud.text = function (_?) { - return _ !== undefined ? (text = functor(_), cloud) : text; + return arguments.length ? (text = functor(_), cloud) : text; }; cloud.spiral = function (_?) { - return _ !== undefined ? (spiral = spirals[_] || _, cloud) : spiral; + return arguments.length ? (spiral = spirals[_] || _, cloud) : spiral; }; cloud.fontSize = function (_?) { - return _ !== undefined ? (fontSize = functor(_), cloud) : fontSize; + return arguments.length ? (fontSize = functor(_), cloud) : fontSize; }; cloud.padding = function (_?) { - return _ !== undefined ? (padding = functor(_), cloud) : padding; + return arguments.length ? (padding = functor(_), cloud) : padding; }; cloud.random = function (_?) { - return _ !== undefined ? (random = _, cloud) : random; + return arguments.length ? (random = _, cloud) : random; }; cloud.on = function () { diff --git a/packages/chart/src/Pie.ts b/packages/chart/src/Pie.ts index 5188d9f6b2..65bb825613 100644 --- a/packages/chart/src/Pie.ts +++ b/packages/chart/src/Pie.ts @@ -119,7 +119,7 @@ export class Pie extends SVGWidget { selection(): any[]; // any[] === single row selection(_: any[]): this; selection(_?: any[]): any[] | this { - if (_ === undefined) { + if (!arguments.length) { try { return this._selection.selection2()[0]?.data; } catch (e) { diff --git a/packages/chart/src/StatChart.ts b/packages/chart/src/StatChart.ts index 067eae5f38..1627a8e085 100644 --- a/packages/chart/src/StatChart.ts +++ b/packages/chart/src/StatChart.ts @@ -106,7 +106,7 @@ export class StatChart extends HTMLWidget { data(): Data; data(_: Data): this; data(_?: Data): Data | this { - if (_ === undefined) return [[...this.quartiles(), this.mean(), this.standardDeviation()]]; + if (!arguments.length) return [[...this.quartiles(), this.mean(), this.standardDeviation()]]; const row = _[0]; this.quartiles([row[0], row[1], row[2], row[3], row[4]]); this.mean(row[5]); diff --git a/packages/chart/src/Summary.ts b/packages/chart/src/Summary.ts index 385fb2b39f..22208e0546 100644 --- a/packages/chart/src/Summary.ts +++ b/packages/chart/src/Summary.ts @@ -303,8 +303,8 @@ Summary.prototype.publish("playInterval", null, "number", "Play Interval", null, const playInterval = Summary.prototype.playInterval; Summary.prototype.playInterval = function (_?: number): number | any { - const retVal = playInterval.call(this, _); - if (_ === undefined) { + const retVal = playInterval.apply(this, arguments); + if (arguments.length) { if (this._playIntervalHandle) { clearInterval(this._playIntervalHandle); } diff --git a/packages/chart/src/SummaryC.ts b/packages/chart/src/SummaryC.ts index 4fbbfd2c4c..edcac02f26 100644 --- a/packages/chart/src/SummaryC.ts +++ b/packages/chart/src/SummaryC.ts @@ -221,8 +221,8 @@ SummaryC.prototype.publish("iconSizeRatio", 0.9, "number", "Ratio of the height const playInterval = SummaryC.prototype.playInterval; SummaryC.prototype.playInterval = function (_?: number): number | any { - const retVal = playInterval.call(this, _); - if (_ !== undefined) { + const retVal = playInterval.apply(this, arguments); + if (arguments.length) { if (this._playIntervalHandle) { clearInterval(this._playIntervalHandle); } diff --git a/packages/chart/src/WordCloud.ts b/packages/chart/src/WordCloud.ts index fc3e1bb6a3..7feebadbb5 100644 --- a/packages/chart/src/WordCloud.ts +++ b/packages/chart/src/WordCloud.ts @@ -191,63 +191,6 @@ WordCloud.prototype.implements(ITooltip.prototype); WordCloud.prototype.mixin(Utility.SimpleSelectionMixin); export interface WordCloud { - /* - paletteID: { (): string; (_: string): WordCloud }; - paletteID_exists: () => boolean; - useClonedPalette: { (): boolean; (_: boolean): WordCloud }; - useClonedPalette_exists: () => boolean; - fontFamily: { (): string; (_: string): WordCloud }; - fontFamily_exists: () => boolean; - fontSizeFrom: { (): number; (_: number): WordCloud }; - fontSizeFrom_exists: () => boolean; - fontSizeTo: { (): number; (_: number): WordCloud }; - fontSizeTo_exists: () => boolean; - angleFrom: { (): number; (_: number): WordCloud }; - angleFrom_exists: () => boolean; - angleTo: { (): number; (_: number): WordCloud }; - angleTo_exists: () => boolean; - angleCount: { (): number; (_: number): WordCloud }; - angleCount_exists: () => boolean; - padding: { (): number; (_: number): WordCloud }; - padding_exists: () => boolean; - scaleMode: { (): string; (_: string): WordCloud }; - scaleMode_exists: () => boolean; - spiral: { (): string; (_: string): WordCloud }; - spiral_exists: () => boolean; - offsetX: { (): number; (_: number): WordCloud }; - offsetX_exists: () => boolean; - offsetY: { (): number; (_: number): WordCloud }; - offsetY_exists: () => boolean; - zoom: { (): number; (_: number): WordCloud }; - zoom_exists: () => boolean; - - // I2DChart - _palette; - click: (row, column, selected) => void; - dblclick: (row, column, selected) => void; - - // ITooltip --- - tooltip; - tooltipHTML: (_?) => any; - tooltipFormat: (opts) => any; - tooltipStyle: { (): string; (_: string): WordCloud }; - tooltipStyle_exists: () => boolean; - tooltipValueFormat: { (): string; (_: string): WordCloud }; - tooltipValueFormat_exists: () => boolean; - tooltipSeriesColor: { (): string; (_: string): WordCloud }; - tooltipSeriesColor_exists: () => boolean; - tooltipLabelColor: { (): string; (_: string): WordCloud }; - tooltipLabelColor_exists: () => boolean; - tooltipValueColor: { (): string; (_: string): WordCloud }; - tooltipValueColor_exists: () => boolean; - tooltipTick: { (): boolean; (_: boolean): WordCloud }; - tooltipTick_exists: () => boolean; - tooltipOffset: { (): number; (_: number): WordCloud }; - tooltipOffset_exists: () => boolean; - - // SimpleSelectionMixin - _selection: Utility.SimpleSelection; - */ paletteID(): string; paletteID(_: string): this; diff --git a/packages/chart/src/XYAxis.ts b/packages/chart/src/XYAxis.ts index 52b74bab30..936daa6268 100644 --- a/packages/chart/src/XYAxis.ts +++ b/packages/chart/src/XYAxis.ts @@ -190,7 +190,7 @@ export class XYAxis extends SVGWidget { skipSelection(): boolean; skipSelection(_: boolean): this; skipSelection(_?: boolean): boolean | this { - if (_ === undefined) return this._skipSelection; + if (!arguments.length) return this._skipSelection; this._skipSelection = _; return this; } @@ -571,7 +571,7 @@ export class XYAxis extends SVGWidget { } layerData(host?: XYAxis): any[][] { - if (host !== undefined) { + if (arguments.length === 1) { const indices = this.layerColumnIndices(host); return host.data().map(row => { const retVal = indices.map(idx => row[idx]); diff --git a/packages/common/src/Class.ts b/packages/common/src/Class.ts index 60f29ac106..10b4138ef9 100644 --- a/packages/common/src/Class.ts +++ b/packages/common/src/Class.ts @@ -22,7 +22,7 @@ export class Class { class(): string; class(_: string): this; class(_?: string): string | this { - if (_ === undefined) return this._class; + if (!arguments.length) return this._class; this._class = _; return this; } diff --git a/packages/common/src/Database.ts b/packages/common/src/Database.ts index 8e62fd2f04..19c826f3b9 100644 --- a/packages/common/src/Database.ts +++ b/packages/common/src/Database.ts @@ -40,7 +40,7 @@ export class Field extends PropertyExt { owner(): Grid; owner(_: Grid): this; owner(_?: Grid): Grid | this { - if (_ === undefined) return this._owner; + if (!arguments.length) return this._owner; this._owner = _; return this; } @@ -228,7 +228,7 @@ export class Grid extends PropertyExt { } legacyColumns(_?, asDefault?): any | Grid { - if (_ === undefined) return this.row(0); + if (!arguments.length) return this.row(0); this.row(0, _, asDefault); return this; } @@ -253,7 +253,7 @@ export class Grid extends PropertyExt { } data(_?, clone?): any | Grid { - if (_ === undefined) return this._data; + if (!arguments.length) return this._data; this._data = clone ? _.map(function (d) { return d.map(function (d2) { return d2; }); }) : _; this._dataCalcChecksum(); return this; @@ -292,7 +292,7 @@ export class Grid extends PropertyExt { private _dataCalcChecksum(idx?) { ++this._dataVersion; if (this._dataChecksum) { - if (idx !== undefined) { + if (arguments.length) { this._dataChecksums[idx] = Utility.checksum(this._data[idx]); } else { this._dataChecksums = this._data.map(function (row) { return Utility.checksum(row); }); @@ -302,7 +302,7 @@ export class Grid extends PropertyExt { } row(row?, _?, asDefault?): any | Grid { - if (_ === undefined) return row === 0 ? this.fields().map(function (d) { return d.label(); }) : this._data[row - 1]; + if (arguments.length < 2) return row === 0 ? this.fields().map(function (d) { return d.label(); }) : this._data[row - 1]; if (row === 0) { const fieldsArr = this.fields(); this.fields(_.map(function (field: string | INestedColumn, idx) { @@ -334,7 +334,7 @@ export class Grid extends PropertyExt { } rows(_?): any | Grid { - if (_ === undefined) return [this.row(0)].concat(this._data); + if (!arguments.length) return [this.row(0)].concat(this._data); this.row(0, _[0]); this._data = _.filter(function (_row, idx) { return idx > 0; }); this._dataCalcChecksum(); @@ -343,7 +343,7 @@ export class Grid extends PropertyExt { // Column Access --- column(col, _?): any | Grid { - if (_ === undefined) return [this.fields()[col].label()].concat(this._data.map(function (row, _idx) { return row[col]; })); + if (arguments.length < 2) return [this.fields()[col].label()].concat(this._data.map(function (row, _idx) { return row[col]; })); _.forEach(function (d, idx) { if (idx === 0) { this.fields()[col] = new Field().label(_[0]); @@ -355,8 +355,8 @@ export class Grid extends PropertyExt { return this; } - columnData(col, _?): any | Grid { - if (_ === undefined) return this._data.map(function (row, _idx) { return row[col]; }); + columnData(col, _): any | Grid { + if (arguments.length < 2) return this._data.map(function (row, _idx) { return row[col]; }); _.forEach(function (d, idx) { this._data[idx][col] = d; this._dataCalcChecksum(idx); @@ -365,7 +365,7 @@ export class Grid extends PropertyExt { } columns(_?): any | Grid { - if (_ === undefined) return this.fields().map(function (_col, idx) { + if (!arguments.length) return this.fields().map(function (_col, idx) { return this.column(idx); }, this); _.forEach(function (_col, idx) { @@ -375,8 +375,8 @@ export class Grid extends PropertyExt { } // Cell Access --- - cell(row, col, _?) { - if (_ === undefined) return this.row(row)[col]; + cell(row, col, _) { + if (arguments.length < 3) return this.row(row)[col]; if (row === 0) { this.fields()[col] = new Field().label(_); } else { @@ -604,7 +604,7 @@ export class Grid extends PropertyExt { // Import/Export --- jsonObj(_?): any | Grid { - if (_ === undefined) return this._data.map(function (row) { + if (!arguments.length) return this._data.map(function (row) { const retVal = {}; this.row(0).forEach(function (col, idx) { retVal[col] = row[idx]; @@ -630,7 +630,7 @@ export class Grid extends PropertyExt { json(_: string | object): this; json(): string; json(_?: string | object): string | this { - if (_ === undefined) return JSON.stringify(this.jsonObj(), null, " "); + if (!arguments.length) return JSON.stringify(this.jsonObj(), null, " "); if (typeof (_) === "string") { _ = JSON.parse(_); } @@ -641,7 +641,7 @@ export class Grid extends PropertyExt { csv(_: string): this; csv(): string; csv(_?: string): string | this { - if (_ === undefined) { + if (!arguments.length) { const temp = document.createElement("div"); return d3CsvFormatRows(this.grid().map(row => { return row.map(cell => { @@ -656,7 +656,7 @@ export class Grid extends PropertyExt { tsv(_: string): this; tsv(): string; tsv(_?: string): string | this { - if (_ === undefined) return d3TsvFormatRows(this.grid()); + if (!arguments.length) return d3TsvFormatRows(this.grid()); this.jsonObj(d3TsvParse(_)); return this; } @@ -670,7 +670,7 @@ export interface Grid { Grid.prototype.publish("fields", [], "propertyArray", "Fields"); const fieldsOrig = Grid.prototype.fields; Grid.prototype.fields = function (_?, clone?) { - if (_ === undefined) return fieldsOrig.apply(this, arguments); + if (!arguments.length) return fieldsOrig.apply(this, arguments); return fieldsOrig.call(this, clone ? _.map(function (d) { return d.clone(); }) : _); }; @@ -700,12 +700,12 @@ export class LegacyView { return this._grid; } columns(_?) { - if (_ === undefined) return this._grid.legacyColumns(); + if (!arguments.length) return this._grid.legacyColumns(); this._grid.legacyColumns(_); return this; } rawData(_?) { - if (_ === undefined) return this._grid.legacyData(); + if (!arguments.length) return this._grid.legacyData(); this._grid.legacyData(_); return this; } diff --git a/packages/common/src/HTMLWidget.ts b/packages/common/src/HTMLWidget.ts index 4a586efcc1..d1c196d816 100644 --- a/packages/common/src/HTMLWidget.ts +++ b/packages/common/src/HTMLWidget.ts @@ -119,7 +119,7 @@ export class HTMLWidget extends Widget { target(_: null | string | HTMLElement | SVGElement): this; target(_?: null | string | HTMLElement | SVGElement): null | HTMLElement | SVGElement | this { const retVal = super.target.apply(this, arguments); - if (_ !== undefined) { + if (arguments.length) { if (this._target instanceof SVGElement) { // Target is a SVG Node, so create an item in the Overlay and force it "over" the overlay element (cough) --- this._isRootNode = false; diff --git a/packages/common/src/List.ts b/packages/common/src/List.ts index ab341a7c47..3232b174f9 100644 --- a/packages/common/src/List.ts +++ b/packages/common/src/List.ts @@ -91,8 +91,6 @@ export class List extends SVGWidget implements IList { dblclick(d) { // console.log("Double click: " + d); } - - // anchor: { (): string; (_: string): List; }; } List.prototype._class += " common_List"; diff --git a/packages/common/src/Palette.ts b/packages/common/src/Palette.ts index 56953f20f0..6250486528 100644 --- a/packages/common/src/Palette.ts +++ b/packages/common/src/Palette.ts @@ -125,12 +125,12 @@ function palette_ordinal(id?, colors?): any { return "ordinal"; }; ordinal.id = function (_?) { - if (_ === undefined) return id; + if (!arguments.length) return id; id = _; return ordinal; }; ordinal.colors = function (_?) { - if (_ === undefined) return colors; + if (!arguments.length) return colors; colors = _; return ordinal; }; @@ -149,7 +149,7 @@ function palette_ordinal(id?, colors?): any { if (id === _id) { return this; } - return _id !== undefined ? fetchOrdinalItem(_id, _colors) : fetchOrdinalItem(); + return arguments.length ? fetchOrdinalItem(_id, _colors) : fetchOrdinalItem(); }; return ordinal; @@ -173,7 +173,7 @@ export function fetchRainbowItem(id?: string, colors?: string[], steps?: number) } function palette_rainbow(id?, _colors?, _steps?) { - if (id === undefined) { + if (!arguments.length) { const retVal = ["default"]; for (const key in m_colorbrewer) { if (brewerOrdinal.indexOf(key) === -1) { @@ -240,12 +240,12 @@ function palette_rainbow(id?, _colors?, _steps?) { return "rainbow"; }; rainbow.id = function (_?) { - if (_ === undefined) return id; + if (!arguments.length) return id; id = _; return rainbow; }; rainbow.colors = function (_?) { - if (_ === undefined) return colors; + if (!arguments.length) return colors; colors = _; return rainbow; }; @@ -263,7 +263,7 @@ function palette_rainbow(id?, _colors?, _steps?) { if (id === _id) { return this; } - return _id !== undefined ? fetchRainbowItem(_id, _colors) : fetchRainbowItem(); + return arguments.length ? fetchRainbowItem(_id, _colors) : fetchRainbowItem(); }; return rainbow; diff --git a/packages/common/src/PropertyExt.ts b/packages/common/src/PropertyExt.ts index da93a659e5..38391b02d1 100644 --- a/packages/common/src/PropertyExt.ts +++ b/packages/common/src/PropertyExt.ts @@ -267,7 +267,7 @@ export class PropertyExt extends Class { id(): string; id(_: string): this; id(_?): string | this { - if (_ === undefined) return this._id; + if (!arguments.length) return this._id; this._id = _; return this; } @@ -494,7 +494,7 @@ export class PropertyExt extends Class { } else { if (type === "propertyArray") { this[id] = function (_?) { - if (_ === undefined) return this[__prop_ + id]; + if (!arguments.length) return this[__prop_ + id]; this[__prop_ + id] = _.map(item => { if (!meta.ext.noDeserialize && meta.ext.autoExpand && !(item instanceof meta.ext.autoExpand)) { item = new meta.ext.autoExpand().deserialize(item); @@ -506,7 +506,7 @@ export class PropertyExt extends Class { }; } else { this[id] = function (_?) { - if (_ === undefined) return this[__prop_ + id] ?? this[id + "_default"]() ?? null; + if (!arguments.length) return this[__prop_ + id] ?? this[id + "_default"](); this[__prop_ + id] = _; return this; }; @@ -533,7 +533,7 @@ export class PropertyExt extends Class { return false; }; this[id + "_default"] = function (_?) { - if (_ === undefined) return this[__default_ + id] !== undefined ? this[__default_ + id] : meta.defaultValue; + if (!arguments.length) return this[__default_ + id] !== undefined ? this[__default_ + id] : meta.defaultValue; if (_ === "") { _ = null; } @@ -595,7 +595,7 @@ export class PropertyExt extends Class { } this[__meta_ + id] = new MetaProxy(id, proxy, method, defaultValue); this[id] = function (_?) { - if (_ === undefined) return defaultValue === undefined || this[id + "_modified"]() ? this[proxy][method]() : defaultValue; + if (!arguments.length) return defaultValue === undefined || this[id + "_modified"]() ? this[proxy][method]() : defaultValue; if (defaultValue !== undefined && _ === defaultValue) { this[proxy][method + "_reset"](); } else { @@ -613,7 +613,7 @@ export class PropertyExt extends Class { return this[proxy][method + "_exists"](); }; this[id + "_default"] = function (_?) { - if (_ === undefined) return this[proxy][method + "_default"](); + if (!arguments.length) return this[proxy][method + "_default"](); this[proxy][method + "_default"](_); return this; }; diff --git a/packages/common/src/SVGWidget.ts b/packages/common/src/SVGWidget.ts index f8b5ae84d1..2c5fd7e29b 100644 --- a/packages/common/src/SVGWidget.ts +++ b/packages/common/src/SVGWidget.ts @@ -166,7 +166,7 @@ export class SVGWidget extends Widget { // Properties --- move(_?, transitionDuration?) { const retVal = this.pos(_); - if (_ !== undefined) { + if (arguments.length) { (transitionDuration ? this._element.transition().duration(transitionDuration) : this._element) .attr("transform", `translate(${_.x} ${_.y})scale(${this._widgetScale})`) ; @@ -178,7 +178,7 @@ export class SVGWidget extends Widget { enableOverflow(): boolean; enableOverflow(_: boolean): this; enableOverflow(_?: boolean): boolean | this { - if (_ === undefined) return this._enableOverflow; + if (!arguments.length) return this._enableOverflow; this._enableOverflow = _; return this; } @@ -187,7 +187,7 @@ export class SVGWidget extends Widget { enableOverflowScroll(): boolean; enableOverflowScroll(_: boolean): this; enableOverflowScroll(_?: boolean): boolean | this { - if (_ === undefined) return this._enableOverflowScroll; + if (!arguments.length) return this._enableOverflowScroll; this._enableOverflowScroll = _; return this; } @@ -196,7 +196,7 @@ export class SVGWidget extends Widget { size(_): this; size(_?): ISize | this { const retVal = super.size.apply(this, arguments); - if (_ !== undefined) { + if (arguments.length) { this._boundingBox = null; } return retVal; @@ -239,7 +239,7 @@ export class SVGWidget extends Widget { target(_: null | string | HTMLElement | SVGElement): this; target(_?: null | string | HTMLElement | SVGElement): null | HTMLElement | SVGElement | this { const retVal = super.target.apply(this, arguments); - if (_ !== undefined) { + if (arguments.length) { if (this._target instanceof SVGElement) { this._isRootNode = false; this._placeholderElement = d3Select(this._target); diff --git a/packages/common/src/SVGZoomWidget.ts b/packages/common/src/SVGZoomWidget.ts index d0089637cd..35f7c357b0 100644 --- a/packages/common/src/SVGZoomWidget.ts +++ b/packages/common/src/SVGZoomWidget.ts @@ -414,7 +414,7 @@ SVGZoomWidget.prototype.publish("mouseMode", "zoom", "set", "Mouse Mode (zoom | const _origMouseMode = SVGZoomWidget.prototype.mouseMode; SVGZoomWidget.prototype.mouseMode = function (_?, transitionDuration?) { const retVal = _origMouseMode.apply(this, arguments); - if (_ !== undefined) { + if (arguments.length) { if (_ === "zoom") { safeRaise(this._zoomRoot.node()); } else { diff --git a/packages/common/src/Shape.ts b/packages/common/src/Shape.ts index 3e9a4426f2..0dbb2808c4 100644 --- a/packages/common/src/Shape.ts +++ b/packages/common/src/Shape.ts @@ -177,7 +177,7 @@ Shape.prototype.publish("tooltip", "", "string", "Tooltip", null, { tags: ["Priv const _origRadius = Shape.prototype.radius; Shape.prototype.radius = function (_?) { const retVal = _origRadius.apply(this, arguments); - if (_ !== undefined) { + if (arguments.length) { this.width(_); this.height(_); return retVal; diff --git a/packages/common/src/Surface.ts b/packages/common/src/Surface.ts index f9a5e20010..f4e090b7f6 100644 --- a/packages/common/src/Surface.ts +++ b/packages/common/src/Surface.ts @@ -345,7 +345,7 @@ Surface.prototype.publish("menuPadding", 2, "number", "Menu Padding", null, { ta Surface.prototype._origMenuParam = Surface.prototype.menu; Surface.prototype.menu = function (this: Surface, _?) { Surface.prototype._origMenuParam.apply(this, arguments); - if (_ !== undefined) { + if (arguments.length) { this._menuWidget.data(_); return this; } @@ -355,7 +355,7 @@ Surface.prototype.menu = function (this: Surface, _?) { Surface.prototype._origShowContent = Surface.prototype.showContent; Surface.prototype.showContent = function (_?) { const retVal = Surface.prototype._origShowContent.apply(this, arguments); - if (_ !== undefined) { + if (arguments.length) { if (this.content()) { this.content().visible(this.showContent()); } diff --git a/packages/common/src/TextBox.ts b/packages/common/src/TextBox.ts index 9541104ab5..9e63bfa346 100644 --- a/packages/common/src/TextBox.ts +++ b/packages/common/src/TextBox.ts @@ -96,7 +96,7 @@ export class TextBox extends SVGWidget { this._text .x(this.getTextX(textBBox.width)) - .colorFill_default(this._shape.colorFill_exists() ? textColor(this._shape.colorFill()) : null) + .colorFill_default(this._shape.colorFill_exists() ? textColor(this._shape.colorFill()) : undefined) .render() ; diff --git a/packages/common/src/TitleBar.ts b/packages/common/src/TitleBar.ts index 416d3eac8f..79c8ad62c4 100644 --- a/packages/common/src/TitleBar.ts +++ b/packages/common/src/TitleBar.ts @@ -52,7 +52,7 @@ export class Button extends HTMLWidget { enabled(): boolean; enabled(_: boolean): this; enabled(_?: boolean): boolean | this { - if (_ === undefined) return this._enabled; + if (!arguments.length) return this._enabled; this._enabled = _; return this; } @@ -133,7 +133,7 @@ export class SelectDropDown extends HTMLWidget { enabled(): boolean; enabled(_: boolean): this; enabled(_?: boolean): boolean | this { - if (_ === undefined) return this._enabled; + if (!arguments.length) return this._enabled; this._enabled = _; return this; } @@ -295,7 +295,7 @@ export class SelectionBar extends IconBar { buttons(_: Array): this; buttons(_?: Array): Array | this { const retVal = super.buttons.apply(this, arguments); - if (_ !== undefined) { + if (arguments.length) { _.filter(b => b instanceof SelectionButton).forEach((sb: SelectionButton) => { sb._owner = this; }); diff --git a/packages/common/src/Transition.ts b/packages/common/src/Transition.ts index bb95f0ea50..59ac57e935 100644 --- a/packages/common/src/Transition.ts +++ b/packages/common/src/Transition.ts @@ -15,19 +15,19 @@ export class Transition { } duration(_?) { - if (_ === undefined) return this._duration; + if (!arguments.length) return this._duration; this._duration = _; return this._widget; } delay(_?) { - if (_ === undefined) return this._delay; + if (!arguments.length) return this._delay; this._delay = _; return this._widget; } ease(_?) { - if (_ === undefined) return this._ease; + if (!arguments.length) return this._ease; this._ease = _; return this._widget; } diff --git a/packages/common/src/Utility.ts b/packages/common/src/Utility.ts index 2f7386ee26..d888f10ffc 100644 --- a/packages/common/src/Utility.ts +++ b/packages/common/src/Utility.ts @@ -152,14 +152,14 @@ export class SimpleSelection extends SelectionBase { _widgetElement; widgetElement(_?) { - if (_ === undefined) return this._widgetElement; + if (!arguments.length) return this._widgetElement; this._widgetElement = _; return this; } _skipBringToTop; skipBringToTop(_?) { - if (_ === undefined) return this._skipBringToTop; + if (!arguments.length) return this._skipBringToTop; this._skipBringToTop = _; return this; } @@ -221,7 +221,7 @@ export class SimpleSelection extends SelectionBase { return d3Select(domNode).classed("selected"); } selection(_?) { - if (_ === undefined) { + if (!arguments.length) { return this.selection2().map(row => JSON.stringify(row)); } this.selection2(d => _.indexOf(JSON.stringify(d)) >= 0); @@ -230,7 +230,7 @@ export class SimpleSelection extends SelectionBase { selection2(): any[]; selection2(isSelected: (d) => boolean): this; selection2(isSelected?: (d) => boolean): any[] | this { - if (isSelected === undefined) { + if (!arguments.length) { const retVal: any[] = []; if (this._widgetElement) { this._widgetElement.selectAll(".selected") @@ -422,15 +422,12 @@ export function template(tpl?: string, _args?) { if (!tpl) return ""; let args; - if (_args !== undefined && typeof _args === "object") { + if (arguments.length === 2 && typeof arguments[1] === "object") { args = arguments[1]; } else { - args = []; - if (tpl !== undefined) { - args.push(tpl); - if (_args !== undefined) { - args.push(_args); - } + args = new Array(arguments.length - 1); + for (let i = 1; i < arguments.length; ++i) { + args[i - 1] = arguments[i]; } } @@ -653,10 +650,10 @@ export function checksum(s) { export function getTime() { return (now && now.call(perf)) || (new Date().getTime()); } -export function mixin(dest, ...args: any[]) { +export function mixin(dest, _sources) { dest = dest || {}; - for (let i = 0, l = args.length; i < l; i++) { - _mixin(dest, args[i]); + for (let i = 1, l = arguments.length; i < l; i++) { + _mixin(dest, arguments[i]); } return dest; } diff --git a/packages/common/src/Widget.ts b/packages/common/src/Widget.ts index 520eec4650..16a3daeb7c 100644 --- a/packages/common/src/Widget.ts +++ b/packages/common/src/Widget.ts @@ -7,6 +7,8 @@ import { debounce, textRect, TextRect, textSize, TextSize } from "./Utility.ts"; import "../src/Widget.css"; +export { Field }; + export type IPrimative = boolean | number | string | object; export type IFieldType = "boolean" | "number" | "string" | "dataset" | "object" | "any"; export interface InputField { @@ -166,7 +168,7 @@ export abstract class Widget extends PropertyExt { columns(): string[]; columns(_: string[], asDefault?: boolean): this; columns(_?: string[], asDefault?: boolean): string[] | this { - if (_ === undefined) return this._db.legacyColumns(); + if (!arguments.length) return this._db.legacyColumns(); this._db.legacyColumns(_, asDefault); return this; } @@ -194,7 +196,7 @@ export abstract class Widget extends PropertyExt { data(): any; data(_: any): this; data(_?: any): any | this { - if (_ === undefined) return this._db.legacyData(); + if (!arguments.length) return this._db.legacyData(); this._db.legacyData(_); return this; } @@ -237,7 +239,7 @@ export abstract class Widget extends PropertyExt { pos(): IPos; pos(_: IPos): this; pos(_?: IPos): IPos | this { - if (_ === undefined) return this._pos; + if (!arguments.length) return this._pos; this._pos = _; if (this._overlayElement) { this._overlayElement @@ -250,7 +252,7 @@ export abstract class Widget extends PropertyExt { x(): number; x(_): this; x(_?): number | this { - if (_ === undefined) return this._pos.x; + if (!arguments.length) return this._pos.x; this.pos({ x: _, y: this._pos.y }); return this; } @@ -258,7 +260,7 @@ export abstract class Widget extends PropertyExt { y(): number; y(_): this; y(_?): number | this { - if (_ === undefined) return this._pos.y; + if (!arguments.length) return this._pos.y; this.pos({ x: this._pos.x, y: _ }); return this; } @@ -266,7 +268,7 @@ export abstract class Widget extends PropertyExt { size(): ISize; size(_): this; size(_?): ISize | this { - if (_ === undefined) return this._size; + if (!arguments.length) return this._size; this._size = _; if (this._overlayElement) { this._overlayElement @@ -280,7 +282,7 @@ export abstract class Widget extends PropertyExt { width(): number; width(_): this; width(_?): number | this { - if (_ === undefined) return this._size.width; + if (!arguments.length) return this._size.width; this.size({ width: _, height: this._size.height }); return this; } @@ -288,7 +290,7 @@ export abstract class Widget extends PropertyExt { height(): number; height(_): this; height(_?): number | this { - if (_ === undefined) return this._size.height; + if (!arguments.length) return this._size.height; this.size({ width: this._size.width, height: _ }); return this; } @@ -314,7 +316,7 @@ export abstract class Widget extends PropertyExt { scale(): number; scale(_): this; scale(_?): number | this { - if (_ === undefined) return this._widgetScale; + if (!arguments.length) return this._widgetScale; this._widgetScale = _; if (this._overlayElement) { this._overlayElement @@ -327,7 +329,7 @@ export abstract class Widget extends PropertyExt { visible(): boolean; visible(_): this; visible(_?): boolean | this { - if (_ === undefined) return this._visible; + if (!arguments.length) return this._visible; this._visible = _; if (this._element) { this._element @@ -341,7 +343,7 @@ export abstract class Widget extends PropertyExt { display(): boolean; display(_): this; display(_?): boolean | this { - if (_ === undefined) return this._display; + if (!arguments.length) return this._display; this._display = _; if (this._element) { this._element.style("display", this._display ? null : "none"); @@ -352,7 +354,7 @@ export abstract class Widget extends PropertyExt { dataMeta(): DataMetaT; dataMeta(_): this; dataMeta(_?): DataMetaT | this { - if (_ === undefined) return this._dataMeta; + if (!arguments.length) return this._dataMeta; this._dataMeta = _; return this; } @@ -361,7 +363,7 @@ export abstract class Widget extends PropertyExt { appData(key: string): any; appData(key: string, value: any): this; appData(key: string, value?: any): any | this { - if (value === undefined) return this._appData[key]; + if (arguments.length < 2) return this._appData[key]; this._appData[key] = value; return this; } @@ -535,7 +537,7 @@ export abstract class Widget extends PropertyExt { target(): null | HTMLElement | SVGElement; target(_: null | string | HTMLElement | SVGElement): this; target(_?: null | string | HTMLElement | SVGElement): null | HTMLElement | SVGElement | this { - if (_ === undefined) return this._target; + if (!arguments.length) return this._target; if (this._target && _) { throw new Error("Target can only be assigned once."); } @@ -720,10 +722,10 @@ Widget.prototype.publish("classed", {}, "object", "HTML Classes", null, { tags: const origClassed = Widget.prototype.classed; Widget.prototype.classed = function (this: Widget, str_obj?: string | { [classID: string]: boolean }, _?: boolean) { if (typeof str_obj === "string") { - if (_ === undefined) return origClassed.call(this)[str_obj]; + if (arguments.length === 1) return origClassed.call(this)[str_obj]; const classed = origClassed.call(this); origClassed.call(this, { ...classed, [str_obj]: _ }); return this; } - return origClassed.call(this, str_obj, _); + return origClassed.apply(this, arguments); }; diff --git a/packages/comms/src/connection.ts b/packages/comms/src/connection.ts index 08b6cdae9e..4a94ac9b89 100644 --- a/packages/comms/src/connection.ts +++ b/packages/comms/src/connection.ts @@ -266,7 +266,7 @@ export class Connection implements IConnection { opts(_: Partial): this; opts(): IOptions; opts(_?: Partial): this | IOptions { - if (_ === undefined) return this._opts; + if (arguments.length === 0) return this._opts; this._opts = { ...DefaultOptions, ..._ }; return this; } diff --git a/packages/comms/src/ecl/scope.ts b/packages/comms/src/ecl/scope.ts index 11b952592a..87508aaa9f 100644 --- a/packages/comms/src/ecl/scope.ts +++ b/packages/comms/src/ecl/scope.ts @@ -105,7 +105,7 @@ export class BaseScope extends StateObject implements ScopeEx children(): BaseScope[]; children(_: BaseScope[]): BaseScope; children(_?: BaseScope[]): BaseScope[] | BaseScope { - if (_ === undefined) return this._children; + if (!arguments.length) return this._children; this._children = _!; return this; } diff --git a/packages/dgrid/index.html b/packages/dgrid/index.html index 762d198c0c..1807e680fd 100644 --- a/packages/dgrid/index.html +++ b/packages/dgrid/index.html @@ -71,6 +71,7 @@

ESM Quick Test

.target("placeholder") .columns(simple.ND.columns) .data(simple.ND.data) + .multiSelect(true) .render() ; diff --git a/packages/dgrid/src/Common.ts b/packages/dgrid/src/Common.ts index 6f6834820b..91abcc2e7b 100644 --- a/packages/dgrid/src/Common.ts +++ b/packages/dgrid/src/Common.ts @@ -19,16 +19,8 @@ export class Common extends HTMLWidget { this._tag = "div"; } - // Backward Compatibility - mulitSelect(): boolean; - mulitSelect(_?: boolean): this; - mulitSelect(_?: boolean): this | boolean { - return this.multiSelect(_); - } - protected formatSortBy(): [{ property: string, descending: boolean }] | undefined { - const cols = this.columns(); - const idx = cols.indexOf(this.sortBy()); + const idx = this.columns().indexOf(this.sortBy()); return idx >= 0 ? [{ property: idx.toString(), descending: this.sortByDescending() }] : undefined; } @@ -36,7 +28,7 @@ export class Common extends HTMLWidget { selection(): any[]; selection(_: any[]): this; selection(_?: any[]): any[] | this { - if (_ === undefined) { + if (!arguments.length) { const retVal = []; for (const id in this._dgrid.selection) { if (this._dgrid.selection[id]) { @@ -141,27 +133,6 @@ export class Common extends HTMLWidget { } Common.prototype._class += " dgrid_Common"; -/* - @publish("...empty...", "string", "No Data Message") - noDataMessage: publish; - @publish("loading...", "string", "Loading Message") - loadingMessage: publish; - @publish(false, "boolean", "Enable paging") - pagination: publish; - @publish(25, "number", "Page size") - pageSize: publish; - @publish(false, "boolean", "Enable sorting by column") - sortable: publish; - @publish(null, "set", "Default 'sort by' Column ID", function () { return this.columns(); }, { optional: true }) - sortBy: publish; - @publish(false, "boolean", "Default 'sort by' descending", null, { disable: self => !self.sortBy() }) - sortByDescending: publish; - @publish(false, "boolean", "Multiple Selection") - multiSelect: publish; - @publish(true, "boolean", "Render HTML") - renderHtml: publish; -*/ - export interface Common { noDataMessage(): string; noDataMessage(_: string): this; diff --git a/packages/dgrid/src/DatasourceTable.ts b/packages/dgrid/src/DatasourceTable.ts index 69bc3d5202..3cc35b348e 100644 --- a/packages/dgrid/src/DatasourceTable.ts +++ b/packages/dgrid/src/DatasourceTable.ts @@ -53,11 +53,6 @@ export class DatasourceTable extends Common { } DatasourceTable.prototype._class += " dgrid_DatasourceTable"; -/* - @publish(null, "object", "Datasource") - datasource: { (): IDatasource; (_: IDatasource): DatasourceTable }; - */ - export interface DatasourceTable { datasource(): IDatasource; datasource(_: IDatasource): this; diff --git a/packages/dgrid/src/Table.ts b/packages/dgrid/src/Table.ts index 0696460516..a00a076a2d 100644 --- a/packages/dgrid/src/Table.ts +++ b/packages/dgrid/src/Table.ts @@ -1,4 +1,4 @@ -import { Palette, PropertyExt } from "@hpcc-js/common"; +import { Palette, PropertyExt, Field } from "@hpcc-js/common"; import { hashSum } from "@hpcc-js/util"; import { format as d3Format } from "d3-format"; import { select as d3Select } from "d3-selection"; @@ -16,7 +16,7 @@ export class ColumnFormat extends PropertyExt { owner(): Table; owner(_: Table): this; owner(_?: Table): Table | this { - if (_ === undefined) return this._owner; + if (!arguments.length) return this._owner; this._owner = _; return this; } @@ -102,9 +102,11 @@ export class Table extends Common { super(); } - fields(_?: any): any | this { - const retVal = super.fields(_); - if (_ !== undefined) { + fields(): Field[]; + fields(_: Field[]): this; + fields(_?: Field[]): Field[] | this { + const retVal = super.fields.apply(this, arguments as any); + if (arguments.length) { const hash = hashSum({ _ }); if (this._prevFieldsHash !== hash) { this._prevFieldsHash = hash; @@ -114,9 +116,11 @@ export class Table extends Common { return retVal; } - columns(_?: any): any | this { - const retVal = super.columns(_); - if (_ !== undefined) { + columns(): string[]; + columns(_: string[], asDefault?: boolean): this; + columns(_?: string[], asDefault?: boolean): string[] | this { + const retVal = super.columns.apply(this, arguments as any); + if (arguments.length) { const hash = hashSum({ _ }); if (this._prevColsHash !== hash) { this._prevColsHash = hash; @@ -126,9 +130,11 @@ export class Table extends Common { return retVal; } + data(): any; + data(_: any): this; data(_?: any): any | this { - const retVal = super.data(_); - if (_ !== undefined) { + const retVal = super.data.apply(this, arguments as any); + if (arguments.length) { this._dataRefresh = true; } return retVal;