Skip to content

Commit

Permalink
AG-13501 Fix inconsistent use of visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobp100 committed Nov 27, 2024
1 parent b7cf353 commit 84a4a17
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class BubbleSeries extends CartesianSeries<Group, BubbleSeriesProperties,
}

override createNodeData() {
const { axes, dataModel, processedData, colorScale, sizeScale } = this;
const { axes, dataModel, processedData, colorScale, sizeScale, visible } = this;
const {
xKey,
yKey,
Expand All @@ -166,7 +166,6 @@ export class BubbleSeries extends CartesianSeries<Group, BubbleSeriesProperties,
label,
colorKey,
marker,
visible,
} = this.properties;
const markerShape = getMarker(marker.shape);
const { placement } = label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,9 @@ export class ScatterSeries extends CartesianSeries<Group, ScatterSeriesPropertie
}

override createNodeData() {
const { axes, dataModel, processedData, colorScale } = this;
const {
xKey,
yKey,
xFilterKey,
yFilterKey,
labelKey,
colorKey,
xName,
yName,
labelName,
marker,
label,
visible,
} = this.properties;
const { axes, dataModel, processedData, colorScale, visible } = this;
const { xKey, yKey, xFilterKey, yFilterKey, labelKey, colorKey, xName, yName, labelName, marker, label } =
this.properties;
const { placement } = label;
const markerShape = getMarker(marker.shape);

Expand Down
2 changes: 2 additions & 0 deletions packages/ag-charts-community/src/chart/series/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,15 @@ export abstract class Series<
}

set visible(value: boolean) {
// @ts-expect-error(2341) Ensure properties.visible is only accessed from here
this.properties.visible = value;
this.ctx.legendManager.toggleItem({ enabled: value, seriesId: this.id });
this.ctx.legendManager.update();
this.visibleMaybeChanged();
}

get visible() {
// @ts-expect-error(2341) Ensure properties.visible is only accessed from here
return this.properties.visible && this.ctx.legendManager.getSeriesEnabled(this.id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ export abstract class SeriesProperties<T extends object> extends BaseProperties<
@Validate(STRING, { optional: true })
id?: string;

// Private - use series.visible
@Validate(BOOLEAN)
visible: boolean = true;
protected readonly visible: boolean = true;

@Validate(REAL_NUMBER, { optional: true })
focusPriority?: number = Infinity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ export class CandlestickSeries extends OhlcSeriesBase<CandlestickNode, Candlesti
id,
data,
ctx: { legendManager },
visible,
} = this;
const {
xKey,
yName,
item: { up, down },
showInLegend,
legendItemName,
visible,
} = this.properties;

if (!data?.length || !xKey || legendType !== 'category') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export abstract class BaseFunnelSeries<
visible: this.visible,
};

const isVisible = this.visible && this.properties.visible;
const isVisible = this.visible;
if (!isVisible) return context;

const xValues = dataModel.resolveKeysById(this, 'xValue', processedData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ export class OhlcSeries extends OhlcSeriesBase<OhlcNode, OhlcSeriesProperties> {
id,
data,
ctx: { legendManager },
visible,
} = this;
const {
xKey,
yName,
item: { up, down },
showInLegend,
legendItemName,
visible,
} = this.properties;

if (!data?.length || !xKey || legendType !== 'category') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ export abstract class RadarSeries extends _ModuleSupport.PolarSeries<
selection: _ModuleSupport.Selection<_ModuleSupport.Marker, RadarNodeDatum>,
highlight: boolean
) {
const { angleKey, radiusKey, marker, visible } = this.properties;
const { visible } = this;
const { angleKey, radiusKey, marker } = this.properties;
const { itemStyler } = marker;

let selectionData: RadarNodeDatum[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ export class RadialBarSeries extends _ModuleSupport.PolarSeries<
return new Sector();
}

override addChartEventListeners(): void {
this.destroyFns.push(
this.ctx.chartEventManager?.addListener('legend-item-click', (event) => this.onLegendItemClick(event)),
this.ctx.chartEventManager?.addListener('legend-item-double-click', (event) =>
this.onLegendItemDoubleClick(event)
)
);
}

override getSeriesDomain(direction: _ModuleSupport.ChartAxisDirection): any[] {
const { dataModel, processedData } = this;
if (!processedData || !dataModel) return [];
Expand All @@ -116,10 +107,11 @@ export class RadialBarSeries extends _ModuleSupport.PolarSeries<
}

override async processData(dataController: _ModuleSupport.DataController) {
const { angleKey, radiusKey, normalizedTo, visible } = this.properties;
const { visible } = this;
const { angleKey, radiusKey, normalizedTo } = this.properties;
const animationEnabled = !this.ctx.animationManager.isSkipped();

if (!this.properties.isValid() || !(visible || animationEnabled)) return;
if (!this.properties.isValid()) return;

const stackGroupId = this.getStackId();
const stackGroupTrailingId = `${stackGroupId}-trailing`;
Expand All @@ -137,7 +129,7 @@ export class RadialBarSeries extends _ModuleSupport.PolarSeries<
extraProps.push(animationValidation());
}

const visibleProps = this.visible || !animationEnabled ? {} : { forceValue: 0 };
const visibleProps = visible || !animationEnabled ? {} : { forceValue: 0 };

const radiusScaleType = this.axes[ChartAxisDirection.Y]?.scale.type;
const angleScaleType = this.axes[ChartAxisDirection.X]?.scale.type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ export abstract class RadialColumnSeriesBase<
});
}

override addChartEventListeners(): void {
this.destroyFns.push(
this.ctx.chartEventManager?.addListener('legend-item-click', (event) => this.onLegendItemClick(event)),
this.ctx.chartEventManager?.addListener('legend-item-double-click', (event) =>
this.onLegendItemDoubleClick(event)
)
);
}

override getSeriesDomain(direction: _ModuleSupport.ChartAxisDirection): any[] {
const { dataModel, processedData } = this;
if (!processedData || !dataModel) return [];
Expand All @@ -122,10 +113,11 @@ export abstract class RadialColumnSeriesBase<
protected abstract getStackId(): string;

override async processData(dataController: _ModuleSupport.DataController) {
const { angleKey, radiusKey, normalizedTo, visible } = this.properties;
const { visible } = this;
const { angleKey, radiusKey, normalizedTo } = this.properties;
const animationEnabled = !this.ctx.animationManager.isSkipped();

if (!this.properties.isValid() || !(visible || animationEnabled)) return;
if (!this.properties.isValid()) return;

const stackGroupId = this.getStackId();
const stackGroupTrailingId = `${stackGroupId}-trailing`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,7 @@ export class RangeBarSeries extends _ModuleSupport.AbstractBarSeries<
}

override createNodeData() {
const {
data,
dataModel,
groupScale,
processedData,
properties: { visible },
} = this;
const { data, dataModel, groupScale, processedData, visible } = this;
const xAxis = this.getCategoryAxis();
const yAxis = this.getValueAxis();

Expand Down

0 comments on commit 84a4a17

Please sign in to comment.