11<script lang="ts">
2- import { defineComponent , nextTick , onMounted , onUnmounted , PropType , Ref , ref , watch } from " vue" ;
2+ import { defineComponent , nextTick , onMounted , onUnmounted , PropType , Ref , ref , watch , computed } from " vue" ;
33import * as d3 from " d3" ;
44import { SpectrogramAnnotation , SpectrogramSequenceAnnotation } from " ../../api/api" ;
55import {
@@ -72,6 +72,7 @@ export default defineComponent({
7272 drawingBoundingBox,
7373 boundingBoxError,
7474 fixedAxes,
75+ transparencyThreshold,
7576 } = useState ();
7677 const selectedAnnotationId: Ref <null | number > = ref (null );
7778 const hoveredAnnotationId: Ref <null | number > = ref (null );
@@ -726,6 +727,33 @@ export default defineComponent({
726727 const gValues = ref (' ' );
727728 const bValues = ref (' ' );
728729
730+
731+ function getTransparencyTableValues() {
732+ // transparencyThreshold is expected to be 0-100 (percentage)
733+ // Convert to normalized 0-1
734+ const t = (transparencyThreshold .value ?? 0 ) / 100 ;
735+
736+ // quick edge cases
737+ if (t <= 0 ) {
738+ // threshold 0% → everything visible (alpha=1)
739+ return " 1" ;
740+ }
741+ if (t >= 1 ) {
742+ // threshold 100% → everything transparent (alpha=0)
743+ return " 0" ;
744+ }
745+ // number of discrete steps (higher = sharper but costlier)
746+ const numSteps = 50 ;
747+ // which index is the last 'transparent' bucket
748+ const thresholdStep = Math .floor (t * (numSteps - 1 ));
749+
750+ const values: string [] = [];
751+ for (let i = 0 ; i < numSteps ; i ++ ) {
752+ // for i <= thresholdStep set transparent (0), else opaque (1)
753+ values .push (i <= thresholdStep ? " 0" : " 1" );
754+ }
755+ return values .join (" " );
756+ }
729757 function updateColorFilter() {
730758 if (! backgroundColor .value .includes (' ,' )) {
731759 // convert rgb(0 0 0) to rgb(0, 0, 0)
@@ -775,7 +803,6 @@ export default defineComponent({
775803
776804 watch ([backgroundColor , colorScheme ], updateColorFilter );
777805
778-
779806 watch (fixedAxes , setAxes );
780807
781808 return {
@@ -787,6 +814,7 @@ export default defineComponent({
787814 rValues ,
788815 gValues ,
789816 bValues ,
817+ getTransparencyTableValues ,
790818 };
791819 },
792820});
@@ -819,16 +847,43 @@ export default defineComponent({
819847 height =" 0"
820848 style =" position : absolute ; top : -1px ; left : -1px ;"
821849 >
822- <filter id =" apply-color-scheme" >
823- <!-- convert to grayscale -->
850+ <filter id =" svg-filters" >
824851 <feColorMatrix
825852 type =" saturate"
826853 values =" 0"
827854 result =" grayscale"
828855 />
829856
830- <!-- apply color scheme -->
831- <feComponentTransfer >
857+ <feColorMatrix
858+ in =" grayscale"
859+ type =" matrix"
860+ values =" 0.2126 0.7152 0.0722 0 0
861+ 0.2126 0.7152 0.0722 0 0
862+ 0.2126 0.7152 0.0722 0 0
863+ 0 0 0 1 0"
864+ result =" sourceGraphic"
865+ />
866+
867+ <feColorMatrix
868+ in =" SourceGraphic"
869+ type =" luminanceToAlpha"
870+ result =" luminance"
871+ />
872+ <feComponentTransfer in =" luminance" result =" transparency-mask" >
873+ <feFuncA
874+ type =" discrete"
875+ :tableValues =" getTransparencyTableValues()"
876+ />
877+ </feComponentTransfer >
878+
879+ <feComposite
880+ in =" grayscale"
881+ in2 =" transparency-mask"
882+ operator =" in"
883+ result =" grayscale-with-transparency"
884+ />
885+
886+ <feComponentTransfer in =" grayscale-with-transparency" >
832887 <feFuncR
833888 type =" table"
834889 :tableValues =" rValues"
0 commit comments