From 01f8ee4cce3ed0355dda41179ad7b4f809cee396 Mon Sep 17 00:00:00 2001 From: Michele Ceriotti Date: Fri, 13 Sep 2024 11:40:03 +0200 Subject: [PATCH] Better error messages and target selection logic (#365) --- src/dataset.ts | 10 +++------- src/map/options.ts | 6 +++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/dataset.ts b/src/dataset.ts index 683e12076..9c889a1a6 100644 --- a/src/dataset.ts +++ b/src/dataset.ts @@ -302,17 +302,13 @@ export function getTarget(dataset: Dataset): DisplayTarget { // Target is specified in settings if (target !== undefined) { if (target === 'atom' && dataset.environments === undefined) { - throw new Error('To use "atom" target, "settings.properties" should be provided'); - } - if (getTargetProps(target).length < 2) { - throw new Error( - `The provided target (${target}) cannot be used. Make sure there are at least two corresponding properties ('settings.properties').` - ); + throw new Error('To use "atom" target, a list of environments should be provided'); } return target; } + // Default to atom properties if there are environments AND atomic properties const atomProperties = getTargetProps('atom'); - return dataset.environments !== undefined && atomProperties.length > 1 ? 'atom' : 'structure'; + return dataset.environments !== undefined && atomProperties.length > 0 ? 'atom' : 'structure'; } function checkMetadata(o: JsObject) { diff --git a/src/map/options.ts b/src/map/options.ts index 37956e3fb..eb5a262d8 100644 --- a/src/map/options.ts +++ b/src/map/options.ts @@ -99,7 +99,11 @@ export class MapOptions extends OptionsGroup { // Setup axes const propertiesName = Object.keys(properties); - assert(propertiesName.length >= 2); + if (propertiesName.length < 2) { + throw new Error( + 'Cannot show a map because the dataset contains fewer than two properties.' + ); + } this.x = new AxisOptions(propertiesName); this.y = new AxisOptions(propertiesName); // For z and color '' is a valid value