Skip to content

Commit eb28667

Browse files
author
minjk-bl
committed
small changes
1 parent 45cbd11 commit eb28667

File tree

3 files changed

+89
-3
lines changed

3 files changed

+89
-3
lines changed

css/root.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ hr.vp-extra-menu-line {
306306
.w30 {
307307
width: 30px !important;
308308
}
309+
.w10 {
310+
width: 10px !important;
311+
}
309312
/* temporary margin */
310313
.mb5 {
311314
margin-bottom: 5px;

data/m_library/numpyLibrary.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@ define([
4444
component: ['dtype']
4545
}
4646
]
47+
},
48+
'np_zeros': {
49+
name: 'zeros',
50+
library: 'numpy',
51+
description: '',
52+
code: '${o0} = np.zeros((${i0})${dtype})',
53+
options: [
54+
{
55+
name: 'i0',
56+
label: 'Input Parameter',
57+
component: ['1dlen', '2dlen', 'ndarr'],
58+
required: true
59+
},
60+
{
61+
name: 'o0',
62+
label: 'Allocate to',
63+
placeholder: 'New variable'
64+
},
65+
{
66+
name: 'dtype',
67+
label: 'Select Data Type',
68+
code: ', dtype=${dtype}',
69+
component: ['dtype']
70+
}
71+
]
4772
}
4873
};
4974

js/com/com_generatorV2.js

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ define([
1919
var _VP_SHOW_RESULT = true;
2020

2121
const _VP_COMP_TYPE_LABEL = {
22+
'1dlen': '1D Length',
23+
'2dlen': '2D Length',
2224
'1darr': '1D Array',
2325
'2darr': '2D Array',
2426
'ndarr': 'ND Array',
@@ -192,6 +194,12 @@ define([
192194
}
193195
// create as component type
194196
switch (componentType) {
197+
case '1dlen':
198+
content = render1dLen(pageThis, obj, state);
199+
break;
200+
case '2dlen':
201+
content = render2dLen(pageThis, obj, state);
202+
break;
195203
case '1darr':
196204
content = render1dArr(pageThis, obj, state);
197205
break;
@@ -576,6 +584,44 @@ define([
576584
//========================================================================
577585
// Render components
578586
//========================================================================
587+
var render1dLen = function(pageThis, obj, state) {
588+
state = {
589+
[obj.name]: '',
590+
...state
591+
};
592+
return $(`<div class="vp-numpy-style-flex-row">
593+
<div class="vp-numpy-style-flex-row" style="margin-right:10px;">
594+
<span class="vp-numpy-style-flex-column-center mr5">
595+
Length
596+
</span>
597+
<input type="text" id="${obj.name}" value="${state[obj.name]}" class="vp-input vp-state" style="width:200px;" placeholder="Input Number">
598+
</div>
599+
</div>`)
600+
}
601+
602+
var render2dLen = function(pageThis, obj, state) {
603+
state = {
604+
[obj.name + '_row']: '',
605+
[obj.name + '_col']: '',
606+
...state
607+
}
608+
return $(`<div class="vp-numpy-style-flex-row">
609+
<div class="vp-numpy-style-flex-row" style="margin-right:10px;">
610+
<span class="vp-numpy-style-flex-column-center" style="margin-right:5px;">
611+
Row
612+
</span>
613+
<input type="text" id="${obj.name}_row" data-id="${obj.name}" value="${state[obj.name+'_row']}" class="vp-input vp-state vp-numpy-2dlen-item" style="width:150px;" placeholder="Number">
614+
</div>
615+
<div class="vp-numpy-style-flex-row" style="margin-right:10px;">
616+
<span class="vp-numpy-style-flex-column-center" style="margin-right:5px;">
617+
Col
618+
</span>
619+
<input type="text" id="${obj.name}_col" data-id="${obj.name}" value="${state[obj.name+'_col']}" class="vp-input vp-state vp-numpy-2dlen-item" style="width:150px;" placeholder="Number">
620+
</div>
621+
<input type="hidden" class="vp-state" id="${obj.name}" value="${state[obj.name]}">
622+
</div>`);
623+
}
624+
579625
var render1dArr = function(pageThis, obj, state) {
580626
let arrKey = obj.name + '_1darr';
581627
let arrState = [ 0 ];
@@ -730,16 +776,16 @@ define([
730776
let arrItems = $(`<div class="vp-numpy-style-flex-row-between-wrap"></div>`);
731777
arrState.forEach((item, idx) => {
732778
arrItems.append($(`<div class="vp-numpy-style-flex-row">
733-
<div class="vp-numpy-style-flex-column-center vp-bold mr5">
779+
<div class="vp-numpy-style-flex-column-center vp-bold mr5 w10">
734780
${idx + 1}
735781
</div>
736782
<input class="vp-numpy-input vp-numpy-ndarr-item" data-idx="${idx}" value="${item}" type="text" placeholder="Value">
737-
<button class="vp-button vp-numpy-ndarr-del">x</button>
783+
<button class="vp-button vp-numpy-ndarr-del w30">x</button>
738784
</div>`));
739785
});
740786
contentTag.append(arrItems);
741787
// add button
742-
contentTag.append($(`<button class="vp-button vp-numpy-ndarr-add">+</button>`));
788+
contentTag.append($(`<button class="vp-button vp-numpy-ndarr-add w30">+</button>`));
743789
return contentTag;
744790
}
745791

@@ -790,9 +836,21 @@ define([
790836
let contentTag = $(this).parent().find('.vp-auto-component-content');
791837
let newType = $(this).val();
792838
let obj = $(this).data('obj');
839+
// reset state
840+
pageThis.setState({ [obj.name]: '' });
793841
$(contentTag).html(renderContent(pageThis, newType, obj, pageThis.getState()));
794842
});
795843

844+
//====================================================================
845+
// Event for 2dLen
846+
//====================================================================
847+
$(selector).on('change', '.vp-numpy-2dlen-item', function() {
848+
let id = $(this).data('id');
849+
let newValue = pageThis.getState(id+'_row') + ',' + pageThis.getState(id+'_col');
850+
$(pageThis.wrapSelector('#' + id)).val(newValue);
851+
$(pageThis.wrapSelector('#' + id)).trigger('change');
852+
});
853+
796854
//====================================================================
797855
// Event for 1dArr
798856
//====================================================================

0 commit comments

Comments
 (0)