Skip to content

Commit

Permalink
Merge pull request #157 from devexperts/add-unique-dynamic-objects-me…
Browse files Browse the repository at this point in the history
…thod

Add unique dynamic objects method
  • Loading branch information
disyakidneyshot authored May 22, 2024
2 parents af0ed34 + 35216b0 commit d00787c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/chart/components/chart/chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export class ChartComponent extends ChartBaseElement {
this.dynamicObjects.model.addObject({
id: series.id,
paneId: series.extentComponent.paneUUID,
parentId: series.parentId,
model: series,
drawer: this.dataSeriesDrawer,
});
Expand Down
19 changes: 18 additions & 1 deletion src/chart/components/dynamic-objects/dynamic-objects.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ export interface DynamicObject<T = unknown> {
readonly drawer: DynamicModelDrawer<T>;
readonly paneId: PaneId;
readonly model?: T;
// this property shows if a dynamic object belongs to some higher entity, for example, data series is a part of a set of data series, which is a single object
readonly parentId?: DynamicObjectId;
}

export class DynamicObjectsModel extends ChartBaseElement {
private _objects: BehaviorSubject<Record<PaneId, LinkedList<DynamicObject>>>;
private modelIdToObjectMap: Map<DynamicObjectId, DynamicObject> = new Map();
private _uniqueObjects: Record<PaneId, Set<DynamicObjectId>> = {};

constructor(private canvasModel: CanvasModel) {
super();
Expand All @@ -27,7 +30,7 @@ export class DynamicObjectsModel extends ChartBaseElement {
* @returns the `DynamicObject` itself and pane `LinkedList` where the object is stored.
*
*/
private getObjectInfoById(id: DynamicObjectId): [DynamicObject, LinkedList<DynamicObject>] | undefined {
public getObjectInfoById(id: DynamicObjectId): [DynamicObject, LinkedList<DynamicObject>] | undefined {
const obj = this.modelIdToObjectMap.get(id);

if (!obj) {
Expand Down Expand Up @@ -76,6 +79,10 @@ export class DynamicObjectsModel extends ChartBaseElement {
}
paneList.insertAtEnd(obj);
this.modelIdToObjectMap.set(obj.id, obj);
if (!this.uniqueObjects[paneId]) {
this.uniqueObjects[paneId] = new Set();
}
this.uniqueObjects[paneId].add(obj.parentId ?? obj.id);
this.setDynamicObjects(objects);
}

Expand All @@ -95,6 +102,9 @@ export class DynamicObjectsModel extends ChartBaseElement {
const targetPos = paneList.getNodePosition(targetNode);
paneList.removeAt(targetPos);
this.modelIdToObjectMap.delete(id);
if (this.uniqueObjects[obj.paneId]) {
this.uniqueObjects[obj.paneId].delete(obj.parentId ?? obj.id);
}
if (paneList.size() === 0) {
delete this.objects[obj.paneId];
}
Expand Down Expand Up @@ -240,6 +250,13 @@ export class DynamicObjectsModel extends ChartBaseElement {
return this._objects.getValue();
}

/**
* Getter for the unique objects, unique object is an entity which is either dynamic object itself, or its parent
*/
get uniqueObjects() {
return this._uniqueObjects;
}

/**
* Sets the objects
* @param objects
Expand Down
1 change: 1 addition & 0 deletions src/chart/model/data-series.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class DataSeriesModel<
public extentComponent: YExtentComponent,
public id: string,
public htId: number,
public parentId?: number | string,
_config: AtLeastOne<DataSeriesConfig> = cloneUnsafe(DEFAULT_DATA_SERIES_CONFIG),
) {
super();
Expand Down

0 comments on commit d00787c

Please sign in to comment.