@@ -17,6 +17,7 @@ import { TFrame } from "../../timeseris/TFrame";
1717import type { KlineKind } from "../plot/PlotKline" ;
1818import type { Plot } from "../plot/Plot" ;
1919import { fetchData , Source } from "../../domain/DataFecther" ;
20+ import type { PineData } from "../../domain/PineData" ;
2021
2122import {
2223 ActionButton ,
@@ -72,7 +73,6 @@ import { style } from '@react-spectrum/s2/style' with {type: 'macro'};
7273import { Screenshot } from "../pane/Screenshot" ;
7374
7475import { Context , PineTS } from "pinets" ;
75- import type { PineData } from "../../domain/PineData" ;
7676//import { PineTS, } from '../../../../../PineTS/src/PineTS.class'
7777//import { Context } from '../../../../../PineTS/src/Context.class'
7878
@@ -117,11 +117,10 @@ type State = {
117117 screenshot : HTMLCanvasElement
118118}
119119
120-
121120const source : Source = dev ? Source . yfinance : Source . binance
122121
123122const allIndTags = dev
124- ? [ 'test' , 'bb' , 'rsi' , 'sma' , 'ema' , 'macd' ]
123+ ? [ 'test' , 'bb' ]
125124 : [ 'sma' , 'ema' , 'bb' , 'rsi' , 'macd' ]
126125
127126const TOOLTIP_DELAY = 500 ; // ms
@@ -732,49 +731,43 @@ class KlineViewContainer extends Component<Props, State> {
732731 }
733732
734733 setOverlayIndicatorLabels ( vs : string [ ] [ ] , refVs ?: string [ ] [ ] ) {
735- let overlayIndicatorLabels = this . state . overlayIndicatorLabels
736- let referOverlayIndicatorLabels = this . state . referOverlayIndicatorLabels
737-
738- const nOverlayInds = this . state . overlayIndicators . length
739-
740- overlayIndicatorLabels = overlayIndicatorLabels || new Array ( nOverlayInds )
741- referOverlayIndicatorLabels = referOverlayIndicatorLabels || new Array ( nOverlayInds )
742-
743- for ( let n = 0 ; n < nOverlayInds ; n ++ ) {
744- overlayIndicatorLabels [ n ] = vs [ n ] ;
745- referOverlayIndicatorLabels [ n ] = refVs [ n ] ;
746- }
747-
748- this . setState ( { overlayIndicatorLabels, referOverlayIndicatorLabels } )
749- }
734+ this . setState ( prevState => {
735+ const nOverlayInds = prevState . overlayIndicators . length
750736
737+ const overlayIndicatorLabels = prevState . overlayIndicatorLabels || new Array ( nOverlayInds )
738+ const referOverlayIndicatorLabels = prevState . referOverlayIndicatorLabels || new Array ( nOverlayInds )
751739
752- setStackedIndicatorLabels_old ( n : number ) {
753- return ( vs : string [ ] , refVs ?: string [ ] ) => {
754- let stackedIndicatorLabels = this . state . stackedIndicatorLabels
755- let referStackedIndicatorLabels = this . state . referStackedIndicatorLabels
756-
757- stackedIndicatorLabels = stackedIndicatorLabels || new Array ( this . state . stackedIndicators . length )
758- referStackedIndicatorLabels = referStackedIndicatorLabels || new Array ( this . state . stackedIndicators . length )
759-
760- stackedIndicatorLabels [ n ] = vs ;
761- referStackedIndicatorLabels [ n ] = refVs ;
740+ for ( let n = 0 ; n < nOverlayInds ; n ++ ) {
741+ overlayIndicatorLabels [ n ] = vs [ n ] ;
742+ referOverlayIndicatorLabels [ n ] = refVs [ n ] ;
743+ }
762744
763- this . setState ( { stackedIndicatorLabels , referStackedIndicatorLabels } )
764- }
745+ return { overlayIndicatorLabels , referOverlayIndicatorLabels }
746+ } )
765747 }
766748
767749 setStackedIndicatorLabels ( n : number , vs : string [ ] , refVs ?: string [ ] ) {
768- let stackedIndicatorLabels = this . state . stackedIndicatorLabels
769- let referStackedIndicatorLabels = this . state . referStackedIndicatorLabels
770-
771- stackedIndicatorLabels = stackedIndicatorLabels || new Array ( this . state . stackedIndicators . length )
772- referStackedIndicatorLabels = referStackedIndicatorLabels || new Array ( this . state . stackedIndicators . length )
773-
774- stackedIndicatorLabels [ n ] = vs ;
775- referStackedIndicatorLabels [ n ] = refVs ;
776-
777- this . setState ( { stackedIndicatorLabels, referStackedIndicatorLabels } )
750+ this . setState ( prevState => {
751+
752+ let stackedIndicatorLabels = prevState . stackedIndicatorLabels || new Array ( this . state . stackedIndicators . length )
753+ let referStackedIndicatorLabels = prevState . referStackedIndicatorLabels || new Array ( this . state . stackedIndicators . length )
754+
755+ //stackedIndicatorLabels[n] = vs;
756+ stackedIndicatorLabels = [
757+ ...stackedIndicatorLabels . slice ( 0 , n ) , // elements before the index
758+ vs , // the new value
759+ ...stackedIndicatorLabels . slice ( n + 1 ) // elements after the index
760+ ] ;
761+
762+ //referStackedIndicatorLabels[n] = refVs;
763+ referStackedIndicatorLabels = [
764+ ...referStackedIndicatorLabels . slice ( 0 , n ) , // elements before the index
765+ refVs , // the new value
766+ ...referStackedIndicatorLabels . slice ( n + 1 ) // elements after the index
767+ ] ;
768+
769+ return { stackedIndicatorLabels, referStackedIndicatorLabels }
770+ } )
778771 }
779772
780773 setSelectedIndicatorTags ( selectedIndicatorTags : Selection ) {
@@ -1281,7 +1274,7 @@ class KlineViewContainer extends Component<Props, State> {
12811274 tvar = { tvar }
12821275 mainIndicatorOutputs = { outputs }
12831276 updateEvent = { this . state . updateEvent }
1284- indexOfStackedIndicators = { n }
1277+ indexOfStackedIndicator = { n }
12851278 callbacksToContainer = { this . callbacks }
12861279 />
12871280 )
0 commit comments