Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions src/components/plots/AxisLines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
const [xResolution, setXResolution] = useState<number>(AXIS_CONSTANTS.INITIAL_RESOLUTION)
const [yResolution, setYResolution] = useState<number>(AXIS_CONSTANTS.INITIAL_RESOLUTION)
const [zResolution, setZResolution] = useState<number>(AXIS_CONSTANTS.INITIAL_RESOLUTION)
const [timeResolution, setTimeResolution] = useState(0);
const isTimeCompatible = axisDimUnits[zIdx].toLowerCase().includes('since')

const isPC = useMemo(()=>plotType == 'point-cloud',[plotType])
const globalScale = isPC ? dataShape[2]/AXIS_CONSTANTS.PC_GLOBAL_SCALE_DIVISOR : 1
const [verboseTime, setVerboseTime] = useState(false)

const depthRatio = useMemo(()=>shape.z/shape.x*timeScale,[shape, timeScale]);
const shapeRatio = useMemo(()=>shape.y/shape.x, [shape])
Expand Down Expand Up @@ -102,6 +105,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
const length = dimLengths[isX ? 2 : 1]
return Math.floor(fac * (length - 1))
}

return (
<group visible={plotType != 'sphere' && plotType != 'flat' && !hideAxis}>
{/* Horizontal Group */}
Expand Down Expand Up @@ -188,10 +192,10 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
material-depthTest={false}
rotation={[-Math.PI/2, 0, flipY ? Math.PI/2 : -Math.PI/2]}
position={[flipY ? AXIS_CONSTANTS.TICK_LENGTH_FACTOR*globalScale :-AXIS_CONSTANTS.TICK_LENGTH_FACTOR*globalScale, 0, 0]}
>{parseLoc(dimSlices[0]?.[(Math.floor((dimLengths[0]-1)*idx*zValDelta)+Math.floor(dimLengths[0]*animProg))%dimLengths[0]] || 0,axisDimUnits[zIdx])}</Text>
>{parseLoc(dimSlices[0]?.[(Math.floor((dimLengths[0]-1)*idx*zValDelta)+Math.floor(dimLengths[0]*animProg))%dimLengths[0]] || 0,axisDimUnits[zIdx], verboseTime, timeResolution)}</Text>
</group>
))}
<group rotation={[-Math.PI/2, 0, flipY ? Math.PI/2 : -Math.PI/2]} position={[flipY ? AXIS_CONSTANTS.Z_TITLE_OFFSET_FACTOR*globalScale : -AXIS_CONSTANTS.Z_TITLE_OFFSET_FACTOR*globalScale, 0, isPC ? (zRange[0]+zRange[1])/2*depthRatio*(globalScale) : (zRange[0]+zRange[1])/2]}>
<group rotation={[-Math.PI/2, 0, flipY ? Math.PI/2 : -Math.PI/2]} position={[flipY ? AXIS_CONSTANTS.Z_TITLE_OFFSET_FACTOR*globalScale : -AXIS_CONSTANTS.Z_TITLE_OFFSET_FACTOR*globalScale, 0, isPC ? (zRange[0]+zRange[1])/2*depthRatio*(globalScale) : (zRange[0]+zRange[1])/2*depthRatio]}>
<Text
key={'zTitle'}
anchorX={'center'}
Expand Down Expand Up @@ -232,6 +236,47 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
>
-
</Text>}
{isTimeCompatible &&
<>
<Text
visible={timeResolution < 3}
key={'zUpRes'}
anchorX={'center'}
anchorY={'top'}
fontSize={AXIS_CONSTANTS.TITLE_FONT_SIZE_FACTOR*globalScale}
position={[zTitleOffset*0.5, -AXIS_CONSTANTS.TITLE_FONT_SIZE_FACTOR * globalScale *2, 0]}
color={colorHex}
material-depthTest={false}
onClick={e=>setTimeResolution(x=> Math.min(x+1,3))}
onPointerEnter={e=>document.body.style.cursor = 'pointer'}
onPointerLeave={e=>document.body.style.cursor = 'default'}
>⇒</Text>
<Text
key={'zVerbose'}
anchorX={'center'}
anchorY={'top'}
fontSize={AXIS_CONSTANTS.TITLE_FONT_SIZE_FACTOR*globalScale*0.66}
position={[0, -AXIS_CONSTANTS.TITLE_FONT_SIZE_FACTOR * globalScale*1.33 , 0]}
color={colorHex}
material-depthTest={false}
onClick={() => setVerboseTime(x => !x)}
onPointerEnter={e=>document.body.style.cursor = 'pointer'}
onPointerLeave={e=>document.body.style.cursor = 'default'}
>① ⮀ Ⓐ</Text>
<Text
visible={timeResolution > 0}
key={'zDownRes'}
anchorX={'center'}
anchorY={'top'}
fontSize={AXIS_CONSTANTS.TITLE_FONT_SIZE_FACTOR*globalScale}
position={[-zTitleOffset*0.5, -AXIS_CONSTANTS.TITLE_FONT_SIZE_FACTOR * globalScale*2, 0]}
color={colorHex}
material-depthTest={false}
onClick={e=>setTimeResolution(x=> Math.max(x-1,0))}
onPointerEnter={e=>document.body.style.cursor = 'pointer'}
onPointerLeave={e=>document.body.style.cursor = 'default'}
>⇐</Text>
</>}
</group>
</group>
</group>
Expand Down
31 changes: 12 additions & 19 deletions src/utils/HelperFuncs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const months = [
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
];

export function parseLoc(input: any, units: string | undefined, verbose: boolean = false) {
export function parseLoc(input: any, units: string | undefined, verbose: boolean = false, resolution: number = 0) {
if (!units){
if (typeof(input) == 'bigint'){
return input;
Expand All @@ -99,25 +99,18 @@ export function parseLoc(input: any, units: string | undefined, verbose: boolean
const hours = date.getUTCHours();
const mins = date.getUTCMinutes();
const secs = date.getUTCSeconds();

const lowerUnits = units.toLowerCase();
const showTime = lowerUnits.includes('hour') || lowerUnits.includes('min') || lowerUnits.includes('sec') || hours !== 0 || mins !== 0 || secs !== 0;

if (verbose) {
let dateStr = `${day} ${months[month - 1]} ${year}`;
if (showTime) {
dateStr += ` ${String(hours).padStart(2, '0')}:${String(mins).padStart(2, '0')}`;
if (secs !== 0 || lowerUnits.includes('sec')) dateStr += `:${String(secs).padStart(2, '0')}`;
}
return dateStr;
} else {
let dateStr = `${String(day).padStart(2, '0')}-${String(month).padStart(2, '0')}-${year}`;
if (showTime) {
dateStr += ` ${String(hours).padStart(2, '0')}:${String(mins).padStart(2, '0')}`;
if (secs !== 0 || lowerUnits.includes('sec')) dateStr += `:${String(secs).padStart(2, '0')}`;
}
return dateStr;

let dateStr;
if (verbose) dateStr = `${day} ${months[month - 1]} ${year}`
else dateStr = `${String(day).padStart(2, '0')}-${String(month).padStart(2, '0')}-${year}`;
if (resolution > 0){
const thisRes = Math.min(resolution, 3);
dateStr += [
` ${String(hours).padStart(2, '0')}`,
`${String(mins).padStart(2, '0')}`,
`${String(secs).padStart(2, '0')}`].slice(0,thisRes).join(':')
}
return dateStr;
}
catch{
return input;
Expand Down
Loading