1
+ /*
2
+ * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
3
+ */
4
+
5
+ import { get } from 'lodash' ;
6
+ import React from 'react' ;
7
+ import * as TblUtil from '../../tables/TableUtil.js' ;
8
+
9
+ import { LO_MODE , LO_VIEW , dispatchSetLayoutMode } from '../../core/LayoutCntlr.js' ;
10
+ import { HelpIcon } from '../../ui/HelpIcon.jsx' ;
11
+ import { ToolbarButton } from '../../ui/ToolbarButton.jsx' ;
12
+
13
+ import * as ChartsCntlr from '../ChartsCntlr.js' ;
14
+
15
+ import { HistogramOptions } from '../ui/HistogramOptions.jsx' ;
16
+ import { Histogram } from '../ui/Histogram.jsx' ;
17
+ import { getChartProperties , FilterEditorWrapper } from './TblView.jsx' ;
18
+
19
+ import DELETE from 'html/images/blue_delete_10x10.png' ;
20
+ import OUTLINE_EXPAND from 'html/images/icons-2014/24x24_ExpandArrowsWhiteOutline.png' ;
21
+ import SETTINGS from 'html/images/icons-2014/24x24_GearsNEW.png' ;
22
+ import CLEAR_FILTERS from 'html/images/icons-2014/24x24_FilterOff_Circle.png' ;
23
+ import FILTER from 'html/images/icons-2014/24x24_Filter.png' ;
24
+ import LOADING from 'html/images/gxt/loading.gif' ;
25
+
26
+ export const HISTOGRAM_TBLVIEW = {
27
+ id : 'histogram' ,
28
+ renderChart,
29
+ renderOptions,
30
+ renderToolbar,
31
+ getChartProperties,
32
+ updateOnStoreChange
33
+ } ;
34
+
35
+ function updateOnStoreChange ( chartProperties ) {
36
+ TblUtil . isFullyLoaded ( get ( chartProperties , 'tblId' ) ) ;
37
+ }
38
+
39
+ function renderChart ( props ) {
40
+ const { chartId, tblId, chartData, widthPx, heightPx} = props ;
41
+ if ( ! TblUtil . isFullyLoaded ( tblId ) || ! chartData || ! heightPx || ! widthPx ) {
42
+ return < div /> ;
43
+ }
44
+ const { isDataReady, data :histogramData , options :histogramParams } = ChartsCntlr . getChartDataElement ( chartId ) ;
45
+
46
+ if ( isDataReady ) {
47
+ var logs , reversed ;
48
+ if ( histogramParams ) {
49
+ var logvals = '' ;
50
+ if ( histogramParams . x . includes ( 'log' ) ) { logvals += 'x' ; }
51
+ if ( histogramParams . y . includes ( 'log' ) ) { logvals += 'y' ; }
52
+ if ( logvals . length > 0 ) { logs = logvals ; }
53
+
54
+ var rvals = '' ;
55
+ if ( histogramParams . x . includes ( 'flip' ) ) { rvals += 'x' ; }
56
+ if ( histogramParams . y . includes ( 'flip' ) ) { rvals += 'y' ; }
57
+ if ( rvals . length > 0 ) { reversed = rvals ; }
58
+
59
+ }
60
+
61
+ return (
62
+ < Histogram data = { histogramData }
63
+ desc = { histogramParams . columnOrExpr }
64
+ binColor = '#8c8c8c'
65
+ height = { heightPx }
66
+ width = { widthPx }
67
+ logs = { logs }
68
+ reversed = { reversed }
69
+ />
70
+ ) ;
71
+ } else {
72
+ if ( histogramParams ) {
73
+ return < div style = { { position : 'relative' , width : '100%' , height : '100%' } } > < div className = 'loading-mask' /> </ div > ;
74
+ } else {
75
+ return 'Select Histogram Parameters' ;
76
+ }
77
+ }
78
+ }
79
+
80
+ function renderOptions ( chartId , optionsKey ) {
81
+ if ( optionsKey === 'options' ) {
82
+ const { tblStatsData} = getChartProperties ( chartId ) ;
83
+ if ( get ( tblStatsData , 'isColStatsReady' ) ) {
84
+ const chartDataElement = ChartsCntlr . getChartDataElement ( chartId ) ;
85
+ const chartDataElementId = chartDataElement . id ;
86
+ const formName = `chartOpt-${ chartId } ` ;
87
+ return (
88
+ < HistogramOptions key = { formName }
89
+ groupKey = { formName }
90
+ colValStats = { tblStatsData . colStats }
91
+ histogramParams = { get ( chartDataElement , 'options' ) }
92
+ defaultParams = { get ( chartDataElement , 'defaultOptions' ) }
93
+ onOptionsSelected = { ( options ) => {
94
+ ChartsCntlr . dispatchChartOptionsReplace ( { chartId, chartDataElementId, newOptions : options } ) ;
95
+ } }
96
+ />
97
+ ) ;
98
+ } else {
99
+ return (
100
+ < img style = { { verticalAlign :'top' , height : 16 , padding : 10 , float : 'left' } }
101
+ title = 'Loading Options...'
102
+ src = { LOADING }
103
+ /> ) ;
104
+ }
105
+ } else if ( optionsKey === 'filters' ) {
106
+ const { tableModel} = getChartProperties ( chartId ) ;
107
+ return (
108
+ < FilterEditorWrapper tableModel = { tableModel } />
109
+ ) ;
110
+ }
111
+ }
112
+
113
+ function renderToolbar ( chartId , expandable , expandedMode , toggleOptions ) {
114
+ const { tableModel, deletable, help_id} = getChartProperties ( chartId ) ;
115
+ return (
116
+ < div className = 'PanelToolbar ChartPanel__toolbar' >
117
+ < div className = 'PanelToolbar_group' />
118
+ < div className = 'PanelToolbar_group' >
119
+ { TblUtil . getFilterCount ( tableModel ) > 0 &&
120
+ < img className = 'PanelToolbar__button'
121
+ title = 'Remove all filters'
122
+ src = { CLEAR_FILTERS }
123
+ onClick = { ( ) => TblUtil . clearFilters ( tableModel ) }
124
+ /> }
125
+ < ToolbarButton icon = { FILTER }
126
+ tip = 'Show/edit filters'
127
+ visible = { true }
128
+ badgeCount = { TblUtil . getFilterCount ( tableModel ) }
129
+ onClick = { ( ) => toggleOptions ( 'filters' ) } />
130
+ < img className = 'PanelToolbar__button'
131
+ title = 'Chart options and tools'
132
+ src = { SETTINGS }
133
+ onClick = { ( ) => toggleOptions ( 'options' ) }
134
+ />
135
+ { expandable && ! expandedMode &&
136
+ < img className = 'PanelToolbar__button'
137
+ title = 'Expand this panel to take up a larger area'
138
+ src = { OUTLINE_EXPAND }
139
+ onClick = { ( ) =>
140
+ {
141
+ ChartsCntlr . dispatchChartExpanded ( chartId ) ;
142
+ dispatchSetLayoutMode ( LO_MODE . expanded , LO_VIEW . xyPlots ) ;
143
+ } }
144
+ /> }
145
+
146
+ { help_id && < div style = { { display : 'inline-block' , position : 'relative' , top : - 9 } } > < HelpIcon helpId = { help_id } /> </ div > }
147
+
148
+ { expandable && ! expandedMode && deletable &&
149
+ < img style = { { display : 'inline-block' , position : 'relative' , top : - 9 , alignSelf : 'baseline' , padding : 2 , cursor : 'pointer' } }
150
+ title = 'Delete this chart'
151
+ src = { DELETE }
152
+ onClick = { ( ) => { ChartsCntlr . dispatchChartRemove ( chartId ) ; } }
153
+ /> }
154
+ </ div >
155
+ </ div >
156
+ ) ;
157
+ }
0 commit comments