@@ -23,6 +23,11 @@ import {
2323 useGlobeControlStore ,
2424 type TUpdateMode ,
2525} from " @/store/store.ts" ;
26+ import {
27+ HISTOGRAM_SUMMARY_BINS ,
28+ buildHistogramSummary ,
29+ type THistogramSummary ,
30+ } from " @/utils/histogram.ts" ;
2631import { useLog } from " @/utils/logging.ts" ;
2732
2833const props = defineProps <{
@@ -58,6 +63,7 @@ const {
5863 fetchDimensionDetails,
5964 updateLandSeaMask,
6065 updateColormap,
66+ updateHistogram,
6167 projectionHelper,
6268 canvas,
6369 box,
@@ -327,8 +333,17 @@ async function getHealpixData(
327333 }
328334
329335 let { min, max, missingValue, fillValue } = getDataBounds (datavar , dataSlice );
336+ // Filter out missing and fill values before building histogram
330337 return {
331338 texture: data2texture (dataSlice , {}),
339+ histogramSummary: buildHistogramSummary (
340+ dataSlice ,
341+ min ,
342+ max ,
343+ fillValue ,
344+ missingValue ,
345+ HISTOGRAM_SUMMARY_BINS
346+ ),
332347 min ,
333348 max ,
334349 missingValue ,
@@ -561,19 +576,20 @@ async function getDimensionValues(
561576 return dimValues ;
562577}
563578
564- async function fetchAndRenderData (
579+ async function processHealpixChunks (
565580 datavar : zarr .Array <zarr .DataType , zarr .FetchStore >,
566- updateMode : TUpdateMode
567- ) {
568- const { dimensionRanges, indices } = await prepareDimensionData (
569- datavar ,
570- updateMode
571- );
572-
581+ cellCoord : number [] | undefined ,
582+ nside : number ,
583+ indices : (number | zarr .Slice | null )[]
584+ ): Promise <{
585+ dataMin: number ;
586+ dataMax: number ;
587+ histogramSummaries: THistogramSummary [];
588+ }> {
573589 let dataMin = Number .POSITIVE_INFINITY;
574590 let dataMax = Number .NEGATIVE_INFINITY;
575- const cellCoord = await getCells () ;
576- const nside = await getNside ();
591+ const histogramSummaries : THistogramSummary [] = [] ;
592+
577593 await Promise .all (
578594 [... Array (HEALPIX_NUMCHUNKS ).keys ()].map (async (ipix ) => {
579595 const texData = await getHealpixData (
@@ -590,7 +606,7 @@ async function fetchAndRenderData(
590606 return ;
591607 }
592608
593- // Update global data range
609+ histogramSummaries . push ( texData . histogramSummary );
594610 dataMin = dataMin > texData .min ? texData .min : dataMin ;
595611 dataMax = dataMax < texData .max ? texData .max : dataMax ;
596612
@@ -604,6 +620,29 @@ async function fetchAndRenderData(
604620 })
605621 );
606622
623+ return { dataMin , dataMax , histogramSummaries };
624+ }
625+
626+ async function fetchAndRenderData(
627+ datavar : zarr .Array <zarr .DataType , zarr .FetchStore >,
628+ updateMode : TUpdateMode
629+ ) {
630+ const { dimensionRanges, indices } = await prepareDimensionData (
631+ datavar ,
632+ updateMode
633+ );
634+
635+ const cellCoord = await getCells ();
636+ const nside = await getNside ();
637+ const { dataMin, dataMax, histogramSummaries } = await processHealpixChunks (
638+ datavar ,
639+ cellCoord ,
640+ nside ,
641+ indices
642+ );
643+
644+ updateHistogram (histogramSummaries , dataMin , dataMax );
645+
607646 const dimInfo = await getDimensionValues (dimensionRanges , indices );
608647
609648 store .updateVarInfo (
0 commit comments