feat(battery): configure observatory indicator geometry and space design controls
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
.battery-design-settings{display:grid;gap:var(--nodedc-space-4);min-width:0}
|
||||
.battery-indicator-previews{display:flex;flex-wrap:wrap;align-items:center;gap:var(--nodedc-space-3)}
|
||||
@@ -1,6 +1,8 @@
|
||||
import {BatteryIndicator} from './BatteryIndicator';
|
||||
import './BatteryDesignSettings.css';
|
||||
import {useState} from 'react';
|
||||
import {ColorField,ControlRow,Description,LevelButton,RangeControl,Select,SettingsCard} from '@nodedc/ui-react';
|
||||
import {batteryIndicatorColor,type BatteryAppearance} from '../../core/batteryScene/appearance';
|
||||
import {ColorField,ControlRow,Description,RangeControl,Select,SettingsCard} from '@nodedc/ui-react';
|
||||
import type {BatteryAppearance} from '../../core/batteryScene/appearance';
|
||||
export function BatteryDesignSettings({value,update}:{value:BatteryAppearance;update:(value:BatteryAppearance)=>void}){
|
||||
const [target,setTarget]=useState<'panels'|'indicator'>('panels');
|
||||
const p=value.panels,i=value.indicator;
|
||||
@@ -9,7 +11,7 @@ export function BatteryDesignSettings({value,update}:{value:BatteryAppearance;up
|
||||
const indicator=(patch:Partial<typeof i>)=>update({...value,indicator:{...i,...patch}});
|
||||
const range=(label:string,value:number,min:number,max:number,onChange:(v:number)=>void)=><RangeControl label={label} value={value} min={min} max={max} step={1} exactValueBounds={{min,max}} onChange={onChange}/>;
|
||||
const color=(label:string,value:string,onChange:(v:string)=>void)=><ControlRow label={label}><ColorField label={label} value={value} onChange={onChange}/></ControlRow>;
|
||||
return <><Select label="Элемент дизайна" value={target} onChange={setTarget} options={[{value:'panels',label:'Плашки показаний'},{value:'indicator',label:'Индикатор в обсерватории'}]}/>
|
||||
return <div className="battery-design-settings"><Select label="Элемент дизайна" value={target} onChange={setTarget} options={[{value:'panels',label:'Плашки показаний'},{value:'indicator',label:'Индикатор в обсерватории'}]}/>
|
||||
{target==='panels'?<SettingsCard title="Плашки показаний" description="Общий вид верхних и нижних плашек над моделью.">
|
||||
{range('Высота плашек, px',p.height,56,160,height=>panel({height}))}
|
||||
{range('Радиус углов, px',p.radius,0,48,radius=>panel({radius}))}
|
||||
@@ -19,7 +21,10 @@ export function BatteryDesignSettings({value,update}:{value:BatteryAppearance;up
|
||||
{color('Цвет стекла',p.glass.tintHex,tintHex=>glass({tintHex}))}
|
||||
{range('Прозрачность стекла, %',100-p.glass.tintOpacity,0,100,transparency=>glass({tintOpacity:100-transparency}))}
|
||||
{range('Размытие стекла, px',p.glass.blur,0,60,blur=>glass({blur}))}
|
||||
</SettingsCard>:<SettingsCard title="Индикатор в обсерватории" description="Цвет заливки и диапазоны уровня заряда для этой батареи.">
|
||||
</SettingsCard>:<SettingsCard title="Индикатор в обсерватории" description="Размеры, цвет заливки и диапазоны уровня заряда для этой батареи.">
|
||||
{range('Ширина индикатора, px',i.width,64,320,width=>indicator({width}))}
|
||||
{range('Высота индикатора, px',i.height,24,96,height=>indicator({height}))}
|
||||
{range('Радиус углов индикатора, px',i.radius,0,48,radius=>indicator({radius}))}
|
||||
<Select label="Режим цвета индикатора" value={i.mode} onChange={mode=>indicator({mode})} options={[{value:'ranges',label:'По уровню заряда'},{value:'mono',label:'Один цвет'}]}/>
|
||||
{i.mode==='mono'?color('Цвет индикатора',i.color,color=>indicator({color})):<>
|
||||
{range('Низкий заряд ниже, %',i.lowUntil,0,99,lowUntil=>indicator({lowUntil,middleUntil:Math.max(i.middleUntil,lowUntil+1)}))}
|
||||
@@ -29,6 +34,6 @@ export function BatteryDesignSettings({value,update}:{value:BatteryAppearance;up
|
||||
{color('Высокий заряд',i.highColor,highColor=>indicator({highColor}))}
|
||||
</>}
|
||||
<Description>Чёрный или белый текст выбирается автоматически по цвету заливки. Предпросмотр:</Description>
|
||||
<div className="observation-actions">{[10,25,80].map(soc=><LevelButton key={soc} label="Предпросмотр заряда" value={soc/100} valueText={`${soc}%`} fillColor={batteryIndicatorColor(i,soc)} disabled/>)}</div>
|
||||
</SettingsCard>}</>;
|
||||
<div className="battery-indicator-previews">{[10,25,80].map(soc=><BatteryIndicator key={soc} appearance={i} soc={soc} label="Предпросмотр заряда" valueText={`${soc}%`} disabled/>)}</div>
|
||||
</SettingsCard>}</div>;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import {LevelButton,type LevelButtonProps} from '@nodedc/ui-react';
|
||||
import {batteryIndicatorColor,type BatteryIndicatorAppearance} from '../../core/batteryScene/appearance';
|
||||
type Props=Omit<LevelButtonProps,'value'|'fillColor'>&{appearance:BatteryIndicatorAppearance;soc:number|null};
|
||||
export function BatteryIndicator({appearance,soc,style,...props}:Props){
|
||||
return <LevelButton {...props} value={soc===null?null:soc/100} fillColor={batteryIndicatorColor(appearance,soc)} style={{...style,width:appearance.width,minWidth:appearance.width,height:appearance.height,minHeight:appearance.height,borderRadius:appearance.radius,paddingInline:'var(--nodedc-space-2)',flexShrink:0}}/>;
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import {defaultGlassMaterial,type GlassMaterialSettings} from '@nodedc/ui-core';
|
||||
export type CellMarkingAppearance={color:string;size:number};
|
||||
export type BatteryPanelAppearance={height:number;radius:number;labelSize:number;valueSize:number;textColor:string;glass:GlassMaterialSettings};
|
||||
export type BatteryIndicatorAppearance={mode:'ranges'|'mono';color:string;lowColor:string;middleColor:string;highColor:string;lowUntil:number;middleUntil:number};
|
||||
export type BatteryIndicatorAppearance={width:number;height:number;radius:number;mode:'ranges'|'mono';color:string;lowColor:string;middleColor:string;highColor:string;lowUntil:number;middleUntil:number};
|
||||
export type BatteryAppearance={schema:'missioncore.battery-ui/v1';markings:CellMarkingAppearance;panels:BatteryPanelAppearance;indicator:BatteryIndicatorAppearance};
|
||||
export const batteryAppearanceKey=(id:string)=>`missioncore.battery-ui/v1:${id}`;
|
||||
export function defaultBatteryAppearance():BatteryAppearance{return {schema:'missioncore.battery-ui/v1',markings:{color:'#ffffff',size:100},indicator:{mode:'ranges',color:'#f1f1ef',lowColor:'#ff7474',middleColor:'#ffd166',highColor:'#b5ff5a',lowUntil:15,middleUntil:30},panels:{height:76,radius:24,labelSize:12,valueSize:18,textColor:'#f1f1ef',glass:{...defaultGlassMaterial,tintOpacity:52,blur:18}}};}
|
||||
export function defaultBatteryAppearance():BatteryAppearance{return {schema:'missioncore.battery-ui/v1',markings:{color:'#ffffff',size:100},indicator:{width:115,height:46,radius:23,mode:'ranges',color:'#f1f1ef',lowColor:'#ff7474',middleColor:'#ffd166',highColor:'#b5ff5a',lowUntil:15,middleUntil:30},panels:{height:76,radius:24,labelSize:12,valueSize:18,textColor:'#f1f1ef',glass:{...defaultGlassMaterial,tintOpacity:52,blur:18}}};}
|
||||
const object=(v:unknown):Record<string,unknown>=>v!==null&&typeof v==='object'?v as Record<string,unknown>:{};
|
||||
const number=(v:unknown,fallback:number,min:number,max:number)=>typeof v==='number'&&Number.isFinite(v)?Math.min(max,Math.max(min,v)):fallback;
|
||||
const color=(v:unknown,fallback:string)=>typeof v==='string'&&/^#[0-9a-f]{6}$/i.test(v)?v.toLowerCase():fallback;
|
||||
@@ -12,7 +12,7 @@ export function parseBatteryAppearance(raw:unknown):BatteryAppearance{
|
||||
const source=object(raw);if(source.schema!=='missioncore.battery-ui/v1')throw new Error('Это не профиль интерфейса батареи.');
|
||||
const d=defaultBatteryAppearance(),m=object(source.markings),p=object(source.panels),g=object(p.glass),i=object(source.indicator);
|
||||
const lowUntil=number(i.lowUntil,15,0,99),middleUntil=number(i.middleUntil,30,lowUntil+1,100);
|
||||
return {schema:d.schema,indicator:{mode:i.mode==='mono'?'mono':'ranges',color:color(i.color,d.indicator.color),lowColor:color(i.lowColor,d.indicator.lowColor),middleColor:color(i.middleColor,d.indicator.middleColor),highColor:color(i.highColor,d.indicator.highColor),lowUntil,middleUntil},markings:{color:color(m.color,d.markings.color),size:number(m.size,100,50,160)},panels:{height:number(p.height,76,56,160),radius:number(p.radius,24,0,48),labelSize:number(p.labelSize,12,10,20),valueSize:number(p.valueSize,18,12,30),textColor:color(p.textColor,d.panels.textColor),glass:{...d.panels.glass,tintHex:color(g.tintHex,d.panels.glass.tintHex),tintOpacity:number(g.tintOpacity,52,0,100),blur:number(g.blur,18,0,60)}}};
|
||||
return {schema:d.schema,indicator:{width:number(i.width,115,64,320),height:number(i.height,46,24,96),radius:number(i.radius,23,0,48),mode:i.mode==='mono'?'mono':'ranges',color:color(i.color,d.indicator.color),lowColor:color(i.lowColor,d.indicator.lowColor),middleColor:color(i.middleColor,d.indicator.middleColor),highColor:color(i.highColor,d.indicator.highColor),lowUntil,middleUntil},markings:{color:color(m.color,d.markings.color),size:number(m.size,100,50,160)},panels:{height:number(p.height,76,56,160),radius:number(p.radius,24,0,48),labelSize:number(p.labelSize,12,10,20),valueSize:number(p.valueSize,18,12,30),textColor:color(p.textColor,d.panels.textColor),glass:{...d.panels.glass,tintHex:color(g.tintHex,d.panels.glass.tintHex),tintOpacity:number(g.tintOpacity,52,0,100),blur:number(g.blur,18,0,60)}}};
|
||||
}
|
||||
|
||||
export function batteryIndicatorColor(value:BatteryIndicatorAppearance,soc:number|null):string|undefined{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {useBatteryAppearanceValue} from '../../../core/batteryScene/useBatteryAppearance';
|
||||
import {batteryIndicatorColor} from '../../../core/batteryScene/appearance';
|
||||
import {BatteryIndicator} from '../../../components/battery/BatteryIndicator';
|
||||
import {useEffect,useState} from 'react';
|
||||
import {Description,Icon,IconButton,LevelButton,ResourceRow,Window} from '@nodedc/ui-react';
|
||||
import {Description,Icon,IconButton,ResourceRow,Window} from '@nodedc/ui-react';
|
||||
import {batteryState,number} from '../../../../../../plugins/jk-bms/frontend/src/model';
|
||||
import type {Sensor,SensorTransport} from '../../../../../../packages/sensor-ui/src/contracts';
|
||||
import {sensorContribution,type SensorUiContribution} from '../../../../../../packages/sensor-ui/src/extensions';
|
||||
@@ -19,7 +19,7 @@ export function ObservationBattery({devices,transport,contributions,enabled,vehi
|
||||
const Detail=device?sensorContribution(contributions,device)?.Detail:null;
|
||||
const close=()=>{setOpen(false);setFullscreen(false);setError('');};
|
||||
const choose=()=>{if(batteries.length===1)setSelected(batteries[0].id);setOpen(true);};
|
||||
return <><LevelButton label={device?`Аккумулятор · ${device.name}`:'Аккумуляторы аппарата'} title={device?`${device.name} · ${state?.fresh?'Данные поступают':soc!==null?'Последние показания':'Нет свежих данных'}`:'Выбрать аккумулятор'} value={soc===null?null:soc/100} valueText={device?`${number(soc,0)} %`:`АКБ · ${batteries.length}`} fillColor={batteryIndicatorColor(appearance.indicator,soc)} freshness={state?.fresh?'live':soc!==null?'stale':'unknown'} levelTone={soc!==null&&soc<15?'danger':soc!==null&&soc<30?'warning':'success'} disabled={!batteries.length} onClick={choose}/>
|
||||
return <><BatteryIndicator appearance={appearance.indicator} soc={soc} label={device?`Аккумулятор · ${device.name}`:'Аккумуляторы аппарата'} title={device?`${device.name} · ${state?.fresh?'Данные поступают':soc!==null?'Последние показания':'Нет свежих данных'}`:'Выбрать аккумулятор'} valueText={device?`${number(soc,0)} %`:`АКБ · ${batteries.length}`} freshness={state?.fresh?'live':soc!==null?'stale':'unknown'} levelTone={soc!==null&&soc<15?'danger':soc!==null&&soc<30?'warning':'success'} disabled={!batteries.length} onClick={choose}/>
|
||||
<Window open={open} title={`${name} / ${device?.name??'Аккумуляторы'}`} subtitle="Аккумулятор" onClose={close} size="lg" allowFloating={false} closeOnBackdrop={false}
|
||||
className="observation-battery-window" style={{width:fullscreen?'calc(100vw - 2 * var(--nodedc-space-4))':'min(1440px, calc(100vw - 2 * var(--nodedc-space-6)))',maxWidth:'none',height:fullscreen?'calc(100dvh - 2 * var(--nodedc-space-4))':'calc(100dvh - 2 * var(--nodedc-space-6))',maxHeight:'none'}}
|
||||
headerActions={<><IconButton label="Вернуться в обсерваторию" onClick={close}><Icon name="chevron-left"/></IconButton><span ref={setActions} className="observation-actions"/></>}>
|
||||
|
||||
@@ -153,6 +153,15 @@ test('indicator design migrates old profiles and retains bounded independent col
|
||||
assert.equal(bounded.lowUntil,99);assert.equal(bounded.middleUntil,100);assert.equal(bounded.color,'#f1f1ef');
|
||||
});
|
||||
|
||||
test('indicator dimensions migrate without changing the old visual size and remain battery-local',()=>{
|
||||
const old=defaultBatteryAppearance();delete old.indicator.width;delete old.indicator.height;delete old.indicator.radius;
|
||||
const migrated=parseBatteryAppearance(old);assert.equal(migrated.indicator.width,115);assert.equal(migrated.indicator.height,46);assert.equal(migrated.indicator.radius,23);
|
||||
Object.assign(migrated.indicator,{width:184,height:64,radius:8});assert.deepEqual(parseBatteryAppearance(JSON.parse(JSON.stringify(migrated))),migrated);
|
||||
assert.equal(defaultBatteryAppearance().indicator.width,115);
|
||||
const bounded=parseBatteryAppearance({...migrated,indicator:{...migrated.indicator,width:-1,height:9999,radius:NaN}}).indicator;
|
||||
assert.equal(bounded.width,64);assert.equal(bounded.height,96);assert.equal(bounded.radius,23);
|
||||
});
|
||||
|
||||
test('legacy ignored white emission never bleaches the gradient after migration; new emission stays editable',()=>{
|
||||
const old=defaultBatteryScene(),m=old.materials['bms/cells'];delete m.chargeGradient.surfaceVersion;m.emissiveIntensity=.65;
|
||||
const migrated=parseScene(old,defaultBatteryScene);assert.equal(migrated.materials['bms/cells'].emissiveIntensity,0);
|
||||
|
||||
@@ -106,3 +106,11 @@ SOC is absent, and ends on leaving editing. Automatic mode retains valid stale
|
||||
SOC and uses the independent inactive surface only when no retained value exists.
|
||||
The renderer switches the complete surface and its texture bindings together;
|
||||
async texture completion cannot apply a hidden mode's texture over the live mode.
|
||||
|
||||
|
||||
The battery Design form separates its target selector from the settings card
|
||||
with the canonical 16 px gap. Observatory indicator geometry is per battery:
|
||||
width 64–320 px, height 24–96 px, radius 0–48 px. Existing documents migrate to
|
||||
115 × 46 px and radius 23 px, matching the previous pill. Live and preview use
|
||||
the same BatteryIndicator adapter over the canonical LevelButton; changes are
|
||||
immediate, persist in battery UI JSON and participate in its existing undo.
|
||||
|
||||
Reference in New Issue
Block a user