@@ -6,115 +6,152 @@ import createPlotlyComponent from 'react-plotly.js/factory';
66import createPlotlyRenderers from '../src/PlotlyRenderers' ;
77import PivotTableUI from '../src/PivotTableUI' ;
88import '../src/pivottable.css' ;
9- import Dropzone from 'react-dropzone'
10- import Papa from 'papaparse'
9+ import Dropzone from 'react-dropzone' ;
10+ import Papa from 'papaparse' ;
1111
1212const Plot = createPlotlyComponent ( window . Plotly ) ;
1313
1414class PivotTableUISmartWrapper extends React . PureComponent {
1515 constructor ( props ) {
16- super ( props )
17- this . state = { pivotState : props } ;
16+ super ( props ) ;
17+ this . state = { pivotState : props } ;
1818 }
1919
20-
2120 componentWillReceiveProps ( nextProps ) {
2221 this . setState ( { pivotState : nextProps } ) ;
2322 }
2423
2524 render ( ) {
26- return < PivotTableUI
27- renderers = { Object . assign ( { } , TableRenderers , createPlotlyRenderers ( Plot ) ) }
28- rendererOptions = { {
29- table : {
30- clickCallback : function ( e , value , filters , pivotData ) {
31- var names = [ ] ;
32- pivotData . forEachMatchingRecord ( filters ,
33- function ( record ) { names . push ( record . Meal ) ; } ) ;
34- alert ( names . join ( "\n" ) ) ;
35- }
36- }
37- } }
38- { ...this . state . pivotState } onChange = { s => this . setState ( { pivotState : s } ) }
39- unusedOrientationCutoff = { Infinity }
40- /> ;
25+ return (
26+ < PivotTableUI
27+ renderers = { Object . assign (
28+ { } ,
29+ TableRenderers ,
30+ createPlotlyRenderers ( Plot )
31+ ) }
32+ { ...this . state . pivotState }
33+ onChange = { s => this . setState ( { pivotState : s } ) }
34+ unusedOrientationCutoff = { Infinity }
35+ />
36+ ) ;
4137 }
4238}
4339
4440export default class App extends React . Component {
4541 componentWillMount ( ) {
4642 this . setState ( {
47- mode : " demo" ,
48- filename : " Sample Dataset: Tips" ,
43+ mode : ' demo' ,
44+ filename : ' Sample Dataset: Tips' ,
4945 pivotState : {
5046 data : tips ,
51- rows : [ "Payer Gender" ] , cols : [ "Party Size" ] ,
52- aggregatorName : "Sum over Sum" , vals : [ "Tip" , "Total Bill" ] ,
53- rendererName : "Grouped Column Chart" ,
47+ rows : [ 'Payer Gender' ] ,
48+ cols : [ 'Party Size' ] ,
49+ aggregatorName : 'Sum over Sum' ,
50+ vals : [ 'Tip' , 'Total Bill' ] ,
51+ rendererName : 'Grouped Column Chart' ,
5452 sorters : {
55- "Meal" : sortAs ( [ "Lunch" , "Dinner" ] ) ,
56- "Day of Week" : sortAs ( [ "Thursday" , "Friday" , "Saturday" , "Sunday" ] ) } ,
57- plotlyOptions : { width : 900 , height : 500 }
58- }
53+ Meal : sortAs ( [ 'Lunch' , 'Dinner' ] ) ,
54+ 'Day of Week' : sortAs ( [
55+ 'Thursday' ,
56+ 'Friday' ,
57+ 'Saturday' ,
58+ 'Sunday' ,
59+ ] ) ,
60+ } ,
61+ plotlyOptions : { width : 900 , height : 500 } ,
62+ plotlyConfig : { } ,
63+ tableOptions : {
64+ clickCallback : function ( e , value , filters , pivotData ) {
65+ var names = [ ] ;
66+ pivotData . forEachMatchingRecord ( filters , function (
67+ record
68+ ) {
69+ names . push ( record . Meal ) ;
70+ } ) ;
71+ alert ( names . join ( '\n' ) ) ;
72+ } ,
73+ } ,
74+ } ,
5975 } ) ;
6076 }
6177
6278 onDrop ( files ) {
63- this . setState ( {
64- mode : "thinking" ,
65- filename : "(Parsing CSV...)" ,
66- textarea : "" ,
67- pivotState : { data : [ ] }
68- } , ( ) => Papa . parse ( files [ 0 ] , {
69- skipEmptyLines : true ,
70- error : ( e ) => alert ( e ) ,
71- complete : ( parsed ) => this . setState ( {
72- mode : "file" ,
73- filename : files [ 0 ] . name ,
74- pivotState : { data : parsed . data }
75- } ) } )
79+ this . setState (
80+ {
81+ mode : 'thinking' ,
82+ filename : '(Parsing CSV...)' ,
83+ textarea : '' ,
84+ pivotState : { data : [ ] } ,
85+ } ,
86+ ( ) =>
87+ Papa . parse ( files [ 0 ] , {
88+ skipEmptyLines : true ,
89+ error : e => alert ( e ) ,
90+ complete : parsed =>
91+ this . setState ( {
92+ mode : 'file' ,
93+ filename : files [ 0 ] . name ,
94+ pivotState : { data : parsed . data } ,
95+ } ) ,
96+ } )
7697 ) ;
7798 }
7899
79100 onType ( event ) {
80101 Papa . parse ( event . target . value , {
81102 skipEmptyLines : true ,
82- error : ( e ) => alert ( e ) ,
83- complete : ( parsed ) => this . setState ( {
84- mode : "text" ,
85- filename : "Data from <textarea>" ,
86- textarea : event . target . value ,
87- pivotState : { data : parsed . data }
88- } )
103+ error : e => alert ( e ) ,
104+ complete : parsed =>
105+ this . setState ( {
106+ mode : 'text' ,
107+ filename : 'Data from <textarea>' ,
108+ textarea : event . target . value ,
109+ pivotState : { data : parsed . data } ,
110+ } ) ,
89111 } ) ;
90112 }
91113
92114 render ( ) {
93- return ( < div >
94- < div className = "row text-center" >
95- < div className = "col-md-3 col-md-offset-3" >
96- < p > Try it right now on a file...</ p >
97- < Dropzone onDrop = { this . onDrop . bind ( this ) } accept = "text/csv" className = "dropzone"
98- activeClassName = "dropzoneActive" rejectClassName = "dropzoneReject" >
99- < p > Drop a CSV file here, or click to choose a file from your computer.</ p >
100- </ Dropzone >
115+ return (
116+ < div >
117+ < div className = "row text-center" >
118+ < div className = "col-md-3 col-md-offset-3" >
119+ < p > Try it right now on a file...</ p >
120+ < Dropzone
121+ onDrop = { this . onDrop . bind ( this ) }
122+ accept = "text/csv"
123+ className = "dropzone"
124+ activeClassName = "dropzoneActive"
125+ rejectClassName = "dropzoneReject"
126+ >
127+ < p >
128+ Drop a CSV file here, or click to choose a file
129+ from your computer.
130+ </ p >
131+ </ Dropzone >
132+ </ div >
133+ < div className = "col-md-3 text-center" >
134+ < p > ...or paste some data:</ p >
135+ < textarea
136+ value = { this . state . textarea }
137+ onChange = { this . onType . bind ( this ) }
138+ placeholder = "Paste from a spreadsheet or CSV-like file"
139+ />
140+ </ div >
101141 </ div >
102- < div className = "col-md-3 text-center" >
103- < p > ...or paste some data:</ p >
104- < textarea value = { this . state . textarea } onChange = { this . onType . bind ( this ) }
105- placeholder = "Paste from a spreadsheet or CSV-like file" />
142+ < div className = "row text-center" >
143+ < p >
144+ < em > Note: the data never leaves your browser!</ em >
145+ </ p >
146+ < br />
106147 </ div >
107- </ div >
108- < div className = "row text-center" >
109- < p > < em > Note: the data never leaves your browser!</ em > </ p >
110- < br />
111- </ div >
112- < div className = "row" >
113- < h2 className = "text-center" > { this . state . filename } </ h2 >
114- < br />
148+ < div className = "row" >
149+ < h2 className = "text-center" > { this . state . filename } </ h2 >
150+ < br />
115151
116- < PivotTableUISmartWrapper { ...this . state . pivotState } />
152+ < PivotTableUISmartWrapper { ...this . state . pivotState } />
153+ </ div >
117154 </ div >
118- </ div > ) ;
155+ ) ;
119156 }
120157}
0 commit comments