-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-components): Generalize settings popup (#4684)
* Fix comment and small stuff * Fix commands * Moving files and made the code better * Add isToggle * Smaller fixes * Update SettingsButton.tsx * Update RevealButtons.tsx * Add mocked * Fix according to review and remove the mock * Update BaseOptionCommand.ts
- Loading branch information
1 parent
38c4c4a
commit 5630fa7
Showing
30 changed files
with
894 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
react-components/src/architecture/base/commands/BaseSliderCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*! | ||
* Copyright 2024 Cognite AS | ||
*/ | ||
|
||
import { RenderTargetCommand } from './RenderTargetCommand'; | ||
|
||
export abstract class BaseSliderCommand extends RenderTargetCommand { | ||
// ================================================== | ||
// INSTANCE FIELDS | ||
// ================================================= | ||
|
||
readonly min: number; | ||
readonly max: number; | ||
readonly step: number; | ||
|
||
// ================================================== | ||
// CONSTRUCTOR | ||
// ================================================== | ||
|
||
protected constructor(min: number, max: number, step: number) { | ||
super(); | ||
this.min = min; | ||
this.max = max; | ||
this.step = step; | ||
} | ||
|
||
// ================================================== | ||
// VIRTUAL METHODS (To be overridden) | ||
// ================================================= | ||
|
||
public abstract get value(): number; | ||
|
||
public abstract set value(value: number); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
react-components/src/architecture/base/concreteCommands/SetPointColorTypeCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/*! | ||
* Copyright 2024 Cognite AS | ||
*/ | ||
|
||
import { PointColorType } from '@cognite/reveal'; | ||
import { BaseOptionCommand } from '../commands/BaseOptionCommand'; | ||
import { RenderTargetCommand } from '../commands/RenderTargetCommand'; | ||
import { type TranslateKey } from '../utilities/TranslateKey'; | ||
|
||
const DEFAULT_OPTIONS: PointColorType[] = [ | ||
PointColorType.Rgb, | ||
PointColorType.Classification, | ||
PointColorType.Depth, | ||
PointColorType.Height, | ||
PointColorType.Intensity | ||
]; | ||
|
||
export class SetPointColorTypeCommand extends BaseOptionCommand { | ||
// ================================================== | ||
// CONSTRUCTOR | ||
// ================================================== | ||
|
||
constructor(supportedTypes = DEFAULT_OPTIONS) { | ||
super(); | ||
for (const value of supportedTypes) { | ||
this.add(new OptionCommand(value)); | ||
} | ||
} | ||
|
||
// ================================================== | ||
// OVERRIDES | ||
// ================================================== | ||
|
||
public override get tooltip(): TranslateKey { | ||
return { key: 'POINT_COLOR', fallback: 'Point color' }; | ||
} | ||
|
||
public override get isEnabled(): boolean { | ||
return this.renderTarget.getPointClouds().next().value !== undefined; | ||
} | ||
} | ||
|
||
// Note: This is not exported, as it is only used internally | ||
|
||
class OptionCommand extends RenderTargetCommand { | ||
private readonly _value: PointColorType; | ||
|
||
public constructor(value: PointColorType) { | ||
super(); | ||
this._value = value; | ||
} | ||
|
||
public override get tooltip(): TranslateKey { | ||
return getTranslateKey(this._value); | ||
} | ||
|
||
public override get isChecked(): boolean { | ||
// Let the first PointCloud decide the color type | ||
const pointCloud = this.renderTarget.getPointClouds().next().value; | ||
if (pointCloud === undefined) { | ||
return false; | ||
} | ||
return pointCloud.pointColorType === this._value; | ||
} | ||
|
||
public override invokeCore(): boolean { | ||
for (const pointCloud of this.renderTarget.getPointClouds()) { | ||
pointCloud.pointColorType = this._value; | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
// ================================================== | ||
// PRIVATE FUNCTIONS | ||
// ================================================== | ||
|
||
function getTranslateKey(type: PointColorType): TranslateKey { | ||
switch (type) { | ||
case PointColorType.Rgb: | ||
return { key: 'RGB', fallback: 'RGB' }; | ||
case PointColorType.Depth: | ||
return { key: 'DEPTH', fallback: 'Depth' }; | ||
case PointColorType.Height: | ||
return { key: 'HEIGHT', fallback: 'Height' }; | ||
case PointColorType.Classification: | ||
return { key: 'CLASSIFICATION', fallback: 'Classification' }; | ||
case PointColorType.Intensity: | ||
return { key: 'INTENSITY', fallback: 'Intensity' }; | ||
case PointColorType.LevelOfDetail: | ||
return { key: 'LEVEL_OF_DETAIL', fallback: 'LevelOfDetail' }; | ||
case PointColorType.PointIndex: | ||
return { key: 'POINT_INDEX', fallback: 'PointIndex' }; | ||
default: | ||
return { key: 'UNKNOWN', fallback: 'Unknown' }; | ||
} | ||
} |
Oops, something went wrong.