@@ -3168,19 +3168,17 @@ Blockly.Blocks.graph_output = {
3168
3168
// this.setTooltip(Blockly.MSG_GRAPH_OUTPUT_TOOLTIP);
3169
3169
this . setColour ( colorPalette . getColor ( 'protocols' ) ) ;
3170
3170
this . appendDummyInput ( )
3171
- . appendField ( 'Graphing output ' ) ;
3171
+ . appendField ( 'Graph ' ) ;
3172
3172
this . appendValueInput ( 'PRINTa' )
3173
3173
. setAlign ( Blockly . ALIGN_RIGHT )
3174
3174
. setCheck ( 'Number' )
3175
- . appendField ( 'value' ) ;
3176
- this . appendValueInput ( 'PRINTb' )
3177
- . setAlign ( Blockly . ALIGN_RIGHT )
3178
- . setCheck ( 'Number' )
3175
+ . appendField ( new Blockly . FieldTextInput ( '' ) , 'GRAPH_LABELa' )
3179
3176
. appendField ( 'value' ) ;
3180
3177
this . setPreviousStatement ( true ) ;
3181
3178
this . setNextStatement ( true ) ;
3182
3179
this . setMutator ( new Blockly . Mutator ( [ 'graph_dec' ] ) ) ;
3183
- this . optionList_ = [ 'dec' , 'dec' ] ;
3180
+ this . optionList_ = [ 'dec' ] ;
3181
+ this . graph_labels_ = [ ] ;
3184
3182
} ,
3185
3183
mutationToDom : function ( workspace ) {
3186
3184
// Create XML to represent menu options.
@@ -3195,6 +3193,7 @@ Blockly.Blocks.graph_output = {
3195
3193
for ( var i = 0 ; i < this . optionList_ . length ; i ++ ) {
3196
3194
this . appendValueInput ( 'PRINT' + i )
3197
3195
. setAlign ( Blockly . ALIGN_RIGHT )
3196
+ . appendField ( new Blockly . FieldTextInput ( '' ) , 'GRAPH_LABEL' + i )
3198
3197
. appendField ( 'value' ) ;
3199
3198
}
3200
3199
} ,
@@ -3208,6 +3207,13 @@ Blockly.Blocks.graph_output = {
3208
3207
connection . connect ( optionBlock . previousConnection ) ;
3209
3208
connection = optionBlock . nextConnection ;
3210
3209
}
3210
+ var i = 0 ;
3211
+ this . graph_labels_ = null ;
3212
+ this . graph_labels_ = [ ] ;
3213
+ while ( this . getFieldValue ( 'GRAPH_LABEL' + i ) ) {
3214
+ this . graph_labels_ . push ( this . getFieldValue ( 'GRAPH_LABEL' + i ) ) ;
3215
+ i ++ ;
3216
+ }
3211
3217
return containerBlock ;
3212
3218
3213
3219
} ,
@@ -3218,7 +3224,6 @@ Blockly.Blocks.graph_output = {
3218
3224
this . removeInput ( 'PRINT' + i ) ;
3219
3225
i ++ ;
3220
3226
}
3221
-
3222
3227
i = 0 ;
3223
3228
this . optionList_ . length = 0 ;
3224
3229
// Rebuild the block's optional inputs.
@@ -3229,6 +3234,7 @@ Blockly.Blocks.graph_output = {
3229
3234
var printInput = this . appendValueInput ( 'PRINT' + i )
3230
3235
. setAlign ( Blockly . ALIGN_RIGHT )
3231
3236
. setCheck ( 'Number' )
3237
+ . appendField ( new Blockly . FieldTextInput ( 'label' ) , 'GRAPH_LABEL' + i )
3232
3238
. appendField ( 'value' ) ;
3233
3239
3234
3240
if ( clauseBlock . valueConnection_ ) {
@@ -3239,6 +3245,11 @@ Blockly.Blocks.graph_output = {
3239
3245
clauseBlock = clauseBlock . nextConnection &&
3240
3246
clauseBlock . nextConnection . targetBlock ( ) ;
3241
3247
}
3248
+ i = this . graph_labels_ . length ;
3249
+ for ( i = 0 ; i < this . graph_labels_ . length ; i ++ ) {
3250
+ if ( this . getFieldValue ( 'GRAPH_LABEL' + i ) )
3251
+ this . setFieldValue ( this . graph_labels_ [ i ] , 'GRAPH_LABEL' + i ) ;
3252
+ }
3242
3253
} ,
3243
3254
saveConnections : function ( containerBlock ) {
3244
3255
// Store a pointer to any connected child blocks.
@@ -3254,6 +3265,14 @@ Blockly.Blocks.graph_output = {
3254
3265
clauseBlock = clauseBlock . nextConnection &&
3255
3266
clauseBlock . nextConnection . targetBlock ( ) ;
3256
3267
}
3268
+ var i = 0 ;
3269
+ this . graph_labels_ = null ;
3270
+ this . graph_labels_ = [ ] ;
3271
+ while ( this . getFieldValue ( 'GRAPH_LABEL' + i ) ) {
3272
+ this . graph_labels_ . push ( this . getFieldValue ( 'GRAPH_LABEL' + i ) ) ;
3273
+ i ++ ;
3274
+ }
3275
+
3257
3276
} ,
3258
3277
onchange : function ( ) {
3259
3278
if ( this . workspace && this . optionList_ . length < 1 ) {
@@ -3266,7 +3285,7 @@ Blockly.Blocks.graph_output = {
3266
3285
}
3267
3286
if ( this . getInput ( 'PRINT0' ) && this . getInput ( 'PRINTa' ) ) {
3268
3287
this . removeInput ( 'PRINTa' ) ;
3269
- this . removeInput ( 'PRINTb' ) ;
3288
+ // this.removeInput('PRINTb');
3270
3289
}
3271
3290
}
3272
3291
} ;
@@ -3298,18 +3317,23 @@ Blockly.propc.graph_output = function () {
3298
3317
3299
3318
var code = 'print("%u' ;
3300
3319
var varList = '' ;
3320
+ var labelList = '' ;
3301
3321
var i = 0 ;
3302
3322
var orIt = '' ;
3303
3323
while ( Blockly . propc . valueToCode ( this , 'PRINT' + i , Blockly . propc . ORDER_NONE ) ) {
3304
3324
code += ',%d' ;
3305
3325
varList += ', ' + Blockly . propc . valueToCode ( this , 'PRINT' + i , Blockly . propc . NONE || '0' ) ;
3326
+ labelList += this . getFieldValue ( "GRAPH_LABEL" + i ) ;
3327
+ if ( Blockly . propc . valueToCode ( this , 'PRINT' + ( i + 1 ) , Blockly . propc . ORDER_NONE ) && i < 9 )
3328
+ labelList += ',' ;
3306
3329
i ++ ;
3307
3330
if ( i > 10 )
3308
3331
break ;
3309
3332
}
3310
3333
code += '\\r", (CNT >> 16)' + varList + ');\n' ;
3311
3334
3312
3335
Blockly . propc . serial_graphing_ = true ;
3336
+ Blockly . propc . definitions_ [ 'graphing_labels' ] = '// GRAPH_LABELS_START:' + labelList + ':GRAPH_LABELS_END //' ;
3313
3337
3314
3338
return code ;
3315
3339
} ;
@@ -3320,25 +3344,23 @@ Blockly.Blocks.graph_settings = {
3320
3344
// this.setTooltip(Blockly.MSG_GRAPH_SETTINGS_TOOLTIP);
3321
3345
this . setColour ( colorPalette . getColor ( 'protocols' ) ) ;
3322
3346
this . appendDummyInput ( )
3323
- . appendField ( "Graph settings" ) ;
3324
- this . appendDummyInput ( )
3325
- . appendField ( "x-axis" )
3347
+ . appendField ( "Graph initialize x-axis" )
3326
3348
. appendField ( new Blockly . FieldDropdown ( [
3327
- [ "keep 10 seconds of data " , "10,S" ] ,
3328
- [ "keep 20 seconds of data " , "20,S" ] ,
3329
- [ "keep 30 seconds of data " , "30,S" ] ,
3330
- [ "keep 40 seconds of data " , "40,S" ] ,
3331
- [ "keep 50 seconds of data " , "50,S" ] ,
3332
- [ "keep 60 seconds of data " , "60,S" ] ,
3333
- [ "keep 90 seconds of data " , "90,S" ] // Add comma back when resetting
3349
+ [ "10 seconds" , "10,S" ] ,
3350
+ [ "20 seconds" , "20,S" ] ,
3351
+ [ "30 seconds" , "30,S" ] ,
3352
+ [ "40 seconds" , "40,S" ] ,
3353
+ [ "50 seconds" , "50,S" ] ,
3354
+ [ "60 seconds" , "60,S" ] ,
3355
+ [ "90 seconds" , "90,S" ] // Add comma back when resetting
3334
3356
// ["trigger on value 1 rising edge", "1,TU"],
3335
3357
// ["trigger on value 1 falling edge", "1,TD"],
3336
3358
// ["trigger on value 1 zero crossing", "1,TZ"]
3337
- ] ) , "XAXIS" ) ;
3338
- this . appendDummyInput ( )
3359
+ ] ) , "XAXIS" )
3360
+ . appendField ( 'y-axis ' )
3339
3361
. appendField ( new Blockly . FieldDropdown ( [
3340
- [ "y-axis autoscale" , "AUTO" ] ,
3341
- [ "y-axis range" , "FIXED" ] ] ) , "YSETTING" )
3362
+ [ "autoscale" , "AUTO" ] ,
3363
+ [ "range" , "FIXED" ] ] ) , "YSETTING" )
3342
3364
. appendField ( "minimum" , 'LABELMIN' )
3343
3365
. appendField ( new Blockly . FieldTextInput ( '0' ,
3344
3366
Blockly . FieldTextInput . numberValidator ) , "YMIN" )
@@ -3361,6 +3383,7 @@ Blockly.Blocks.graph_settings = {
3361
3383
this . setInputsInline ( false ) ;
3362
3384
this . setPreviousStatement ( true , null ) ;
3363
3385
this . setNextStatement ( true , null ) ;
3386
+ this . render ( ) ;
3364
3387
} ,
3365
3388
onchange : function ( ) {
3366
3389
if ( this . getFieldValue ( 'YSETTING' ) === 'AUTO' ) {
0 commit comments