@@ -31,80 +31,53 @@ define([
3131
3232 getInitialDataParams : function ( ) {
3333 return ( {
34- outputMode : SplunkVisualizationBase . ROW_MAJOR_OUTPUT_MODE ,
34+ outputMode : SplunkVisualizationBase . COLUMN_MAJOR_OUTPUT_MODE ,
3535 count : 10000
3636 } ) ;
3737 } ,
3838
3939 // this for mat data method make sure that the data passed in
4040 formatData : function ( data , config ) {
41+ // Expects data
42+ // <basesearch> | table _time, open, close, low, high
4143
4244 //This returns nothing if there is no data passed in
43- if ( data . rows . length < 1 ) {
45+ if ( data . columns . length < 1 ) {
4446 return ;
4547 }
4648
4749 //This checks if all data being passed in are numbers and displays an error if not.
48- if ( _ . isNaN ( data ) ) {
49- throw new SplunkVisualizationBase . VisualizationError (
50- 'This chart only supports numbers'
51- ) ;
52- }
50+ // if (_.isNaN(data)) {
51+ // throw new SplunkVisualizationBase.VisualizationError(
52+ // 'This chart only supports numbers'
53+ // );
54+ // }
55+
56+ var columns = data . columns ,
57+ retData = { } ;
58+
59+ $ . each ( data . fields , function ( i , field ) {
60+ retData [ field . name . toLowerCase ( ) ] = columns [ i ] ;
61+ } ) ;
5362
54- return data ;
63+ return retData ;
5564 } ,
5665
5766 updateView : function ( data , config ) {
5867
59- // console.log("raw data?" + data);
6068 if ( ! data ) {
6169 return ;
6270 }
6371
64- var dataSet = data
65- // console.log("dataSet?" + dataSet);
66-
67- Plotly . purge ( 'candlestickContainer_' + this . __uniqueID ) ;
68-
69- $ ( '#' + this . id ) . empty ( ) ;
70-
71-
72- // this function extracts a column of an array
73- function arrayColumn ( arr , n ) {
74- return arr . map ( x => x [ n ] ) ;
75- }
76-
77- //Place arrays in variables
78- var time = arrayColumn ( data . rows , 0 ) ;
79- var close = arrayColumn ( data . rows , 1 ) ;
80- var high = arrayColumn ( data . rows , 2 ) ;
81- var low = arrayColumn ( data . rows , 3 ) ;
82- var open = arrayColumn ( data . rows , 4 ) ;
83-
84- // console.log(time);
85- // console.log(close);
86- // console.log(high);
87- // console.log(low);
88- // console.log(open);
89-
90- var trendHigh = high ;
91- var trendLow = low ;
92-
93- //converts the string array to a number array
94- trendHigh = trendHigh . map ( Number ) ;
95- trendLow = trendLow . map ( Number ) ;
96-
97- // console.log(trendHigh);
98- // console.log(trendLow);
99-
100- //these blocks of code calculate the simple moving average of the elements in and array and
101- //out put the avgs in an array also.
102- trendHigh = sma ( trendHigh , 4 ) ;
103- trendLow = sma ( trendLow , 4 ) ;
104-
105- // console.log(trendHigh);
106- // console.log(trendLow);
72+ var time = data . _time ,
73+ open = data . open ,
74+ close = data . close ,
75+ high = data . high ,
76+ low = data . low ,
77+ trendHigh = high ,
78+ trendLow = low ;
10779
80+ // Get info from config
10881 var modeBar = SplunkVisualizationUtils . normalizeBoolean ( this . _getEscapedProperty ( 'mbDisplay' , config ) ) ;
10982 var dispLegend = SplunkVisualizationUtils . normalizeBoolean ( this . _getEscapedProperty ( 'showLegend' , config ) ) ;
11083 var xTickAngle = this . _getEscapedProperty ( 'xAngle' , config ) || 0 ;
@@ -127,6 +100,24 @@ define([
127100 var incColor = this . _getEscapedProperty ( 'highColor' , config ) || '#008000' ;
128101 var decColor = this . _getEscapedProperty ( 'lowColor' , config ) || '#FF0000' ;
129102
103+ // Cleanup previous data
104+ Plotly . purge ( 'candlestickContainer_' + this . __uniqueID ) ;
105+ $ ( '#' + this . id ) . empty ( ) ;
106+
107+ //converts the string array to a number array
108+ trendHigh = trendHigh . map ( Number ) ;
109+ trendLow = trendLow . map ( Number ) ;
110+
111+ // console.log(trendHigh);
112+ // console.log(trendLow);
113+
114+ //these blocks of code calculate the simple moving average of the elements in and array and
115+ //out put the avgs in an array also.
116+ trendHigh = sma ( trendHigh , 4 ) ;
117+ trendLow = sma ( trendLow , 4 ) ;
118+
119+ // console.log(trendHigh);
120+ // console.log(trendLow);
130121
131122 //this block traces the chart variables and sets the asethetics
132123 var trace = {
@@ -225,11 +216,12 @@ define([
225216 }
226217 } ;
227218
219+ // Plotting the chart
228220 Plotly . plot ( 'candlestickContainer_' + this . __uniqueID , data1 , layout , {
229221 displayModeBar : modeBar
230222 } ) ;
231223
232- }
224+ } ,
233225
234226 _getEscapedProperty : function ( name , config ) {
235227 var propertyValue = config [ this . getPropertyNamespaceInfo ( ) . propertyNamespace + name ] ;
0 commit comments