All files / src index.ts

76.47% Statements 13/17
55.55% Branches 5/9
57.14% Functions 4/7
71.42% Lines 10/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166                          1x                       5x       5x 5x 1x         1x                                                                                                                                                                                                                   1x                           1x     2x     2x      
import type { OctopusHost } from '@ska-octopus-widget-sdk/widget-sdk';
import {
  COLOR_PALETTES,
  INPUT_FORMATED_SCHEMA_TYPE,
  INPUT_FORMATTED_PRESET_DESCRIPTIONS_TOKEN,
  INPUT_FORMATTED_PRESET_EXPRESSION,
  INPUT_TANGO_ATTRIBUTES,
  makeWidgetDef,
  type ColorPaletteId
} from '@ska-octopus-widget-sdk/widget-sdk';
import GeoMapWidget from './GeoMapWidget';
import pkg from '../package.json';
 
const { version } = pkg as { version: string };
 
function humanizePaletteId(id: string) {
  return id
    .replace(/([a-z])([A-Z])/g, '$1 $2')
    .replace(/(\d+)/g, ' $1')
    .replace(/[-_]/g, ' ')
    .replace(/\s+/g, ' ')
    .trim()
    .replace(/^./, (c) => c.toUpperCase());
}
 
const colorSchemeOptions = (Object.keys(COLOR_PALETTES) as ColorPaletteId[]).map((value) => ({
  value,
  label: COLOR_PALETTES[value]?.label || humanizePaletteId(value)
}));
const colorSchemeEnum = colorSchemeOptions.map((opt) => opt.value);
const colorSchemeEnumNames = colorSchemeOptions.map((opt) => opt.label);
const defaultColorScheme: ColorPaletteId =
  (colorSchemeOptions.find((opt) => opt.value === 'scientificActon10')?.value ??
    colorSchemeEnum[0]) ||
  'tableau10';
 
const schema = {
  type: 'object',
  properties: {
    title: {
      type: INPUT_FORMATED_SCHEMA_TYPE,
      title: 'Title',
      formatPreset: INPUT_FORMATTED_PRESET_EXPRESSION,
      propertyType: 'css',
      level: 2,
      description: `Optional map title. ${INPUT_FORMATTED_PRESET_DESCRIPTIONS_TOKEN}`,
      default: ''
    },
    endpoint: {
      type: INPUT_TANGO_ATTRIBUTES,
      title: 'Endpoint source',
      propertyType: 'functionality',
      level: 2,
      description: `Pick Tango DB endpoint and station source in Attribute (for example low-mccs/station/s8-1). ${INPUT_FORMATTED_PRESET_DESCRIPTIONS_TOKEN}`,
      items: {
        properties: {
          attribute: {
            description:
              'Station source template (for example low-mccs/station/s8-1 or s8-1). Used to derive station id.'
          }
        }
      },
      minItems: 1,
      default: [{ endpoint: '1', attribute: 'low-mccs/station/s8-1' }]
    },
    legendPosition: {
      type: 'string',
      title: 'Legend position',
      propertyType: 'css',
      level: 2,
      enum: ['left', 'right', 'top', 'bottom', 'none'],
      default: 'bottom',
      description: 'Controls where the legend is rendered on the map.'
    },
    showAntennas: {
      type: 'boolean',
      propertyType: 'css',
      level: 2,
      default: true,
      description: 'Show or hide antenna markers on the geomap.'
    },
    groupBy: {
      type: 'string',
      title: 'Aggregation',
      propertyType: 'functionality',
      level: 2,
      enum: ['smartbox', 'tpm'],
      enumNames: ['Per smartbox', 'Per TPM'],
      default: 'smartbox',
      description: 'Group map outlines by smartbox or by TPM.'
    },
    mccsBatchSize: {
      type: 'number',
      title: 'Batch size (attributes per request)',
      propertyType: 'functionality',
      level: 4,
      default: 5,
      minimum: 1,
      maximum: 50,
      description: 'Split attributes into batches to avoid heavy queries (spectra).'
    },
    radiusMinPx: {
      type: 'number',
      title: 'Min antenna radius (px)',
      propertyType: 'css',
      level: 4,
      default: 0.3,
      minimum: 0.1,
      description: 'Smallest antenna marker radius in pixels.'
    },
    radiusMaxPx: {
      type: 'number',
      title: 'Max antenna radius (px)',
      propertyType: 'css',
      level: 4,
      default: 1,
      minimum: 0.3,
      description: 'Largest antenna marker radius in pixels.'
    },
    colorScheme: {
      type: 'string',
      title: 'Color scheme',
      propertyType: 'css',
      level: 2,
      enum: colorSchemeEnum,
      enumNames: colorSchemeEnumNames,
      default: defaultColorScheme,
      description: 'Preset palette used for map coloring when no custom scale is provided.'
    },
    customColorScale: {
      type: 'string',
      title: 'Custom Color Scale (JSON)',
      propertyType: 'css',
      level: 4,
      description:
        'String with JSON array of RGB triplets, e.g. [[0,255,255],[255,0,0]]. If non-empty, it overrides colorScheme.',
      default: ''
    }
  },
  required: []
};
 
const widgetDef = makeWidgetDef({
  key: 'geoMap',
  component: GeoMapWidget as any,
  label: 'GeoMap',
  layout: { x: 0, y: 0, w: 40, h: 20 },
  requiredStreams: [],
  config: { schema },
  polls: true,
  version,
  docsUrl: 'https://developer.skao.int/projects/ska-octopus-geomap-widget/en/latest/'
});
 
function register(O: OctopusHost) {
  O.registerWidget(widgetDef as any);
}
 
(function wait(h: any) {
  Iif (typeof h.registerWidget === 'function') {
    register(h as OctopusHost);
  } else {
    setTimeout(wait, 50, h);
  }
})((globalThis as any).Octopus || ((globalThis as any).Octopus = {}));