Skip to content

Commit

Permalink
stacked item
Browse files Browse the repository at this point in the history
  • Loading branch information
smariel committed Dec 25, 2022
1 parent 5bd3455 commit 385a8ba
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
5 changes: 5 additions & 0 deletions html/PTree.html
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ <h5 class="bottom_subtitle">Display</h5>
<input id="config_textsize" data-config="text_size" class="config_input config_range" type="range" min="1" max="30" value="14" step="1" />
</label>
<br />
<label for="config_textmargin">
Text margin: <span class="range_val">10</span>px
<input id="config_textmargin" data-config="text_margin" class="config_input config_range" type="range" min="0" max="50" value="10" step="1" />
</label>
<br />
<label for="config_zoom">
Zoom: <span class="range_val">100</span>%
<input id="config_zoom" data-config="zoom" class="config_input config_range" type="range" min="50" max="400" value="100" step="10" />
Expand Down
18 changes: 10 additions & 8 deletions html/itemEditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,18 @@ <h3>Description</h3>
<div class="col-xs-6"><label for="badge_out">Output badge</label><input id="input_badge_out" type="text" data-itemdata="badge_out" class="form-control item-control" placeholder="..." /></div>
</div>
<div class="form-group row">
<div class="col-xs-12">
<div class="col-xs-9">
<label for="source_shape">Shape</label>
</div>
<div class="col-xs-12">
<select id="source_shape" data-itemdata="shape" class="form-control item-control">
<option value="0">Rectangle</option>
<option value="1">Rounded rectangle</option>
<option value="2">Parallelogram</option>
</select>
</div>
<div class="col-xs-3">
<label for="input_quantity">Quantity</label>
<input id="input_quantity" type="text" data-itemdata="quantity" class="form-control input_num item-control" placeholder="1" data-toggle="tooltip" data-placement="bottom" title="Number of stacked item (only graphical)" />
</div>
</div>
<div class="form-group row">
<div class="col-xs-12">
Expand All @@ -77,8 +79,6 @@ <h3>Characteristics</h3>
<!-- REGULATOR TYPE -->
<div class="col-xs-12">
<label for="source_regtype">Regulator type</label>
</div>
<div class="col-xs-12">
<select id="source_regtype" data-itemdata="regtype" class="form-control item-control" data-toggle="tooltip">
<optgroup label="Fixed output">
<option value="0">DC/DC switching regulator</option>
Expand Down Expand Up @@ -258,16 +258,18 @@ <h3>Description</h3>
</div>
</div>
<div class="form-group row">
<div class="col-xs-12">
<div class="col-xs-9">
<label for="load_shape">Shape</label>
</div>
<div class="col-xs-12">
<select id="load_shape" data-itemdata="shape" class="form-control item-control">
<option value="0">Rectangle</option>
<option value="1">Rounded rectangle</option>
<option value="2">Parallelogram</option>
</select>
</div>
<div class="col-xs-3">
<label for="load_quantity">Quantity</label>
<input id="load_quantity" type="text" data-itemdata="quantity" class="form-control input_num item-control" placeholder="1" data-toggle="tooltip" data-placement="bottom" title="Number of stacked item (only graphical)" />
</div>
</div>
<div class="form-group row">
<div class="col-xs-12">
Expand Down
22 changes: 19 additions & 3 deletions js/class.Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Canvas {
width_coef : Canvas.app_template.item.width_coef,
height_coef : Canvas.app_template.item.height_coef,
text_size : 14,
text_margin : 10,
color_source : '#FF1744', // materialze red accent-3,
color_load : '#00bfa5', // materializ teal accent-4
display_typmax : 'max',
Expand Down Expand Up @@ -119,7 +120,7 @@ class Canvas {
itemGeometry.xvnet = itemGeometry.x1 + Math.round(this.config.cell_width * Canvas.app_template.verticalNet.left_coef);
itemGeometry.xhalf = itemGeometry.x1 + Math.round(itemGeometry.width /2 + itemGeometry.skew_error/2);
itemGeometry.yhalf = itemGeometry.y1 + Math.round(itemGeometry.height/2);

itemGeometry.textmargin = Math.max((item.characs.quantity-1)*Canvas.app_template.item.quantity_gap, this.config.text_margin);

// create a rectangle with the correct template
// and add it to the canvas
Expand Down Expand Up @@ -171,6 +172,20 @@ class Canvas {
this.fabricCanvas.fabric_obj[item.id] = itemGroup;
this.fabricCanvas.add(itemGroup);

// add stacked rectangles with darker color if quantity > 1
for(let i=1; i<item.characs.quantity; i++){
let itemRect2 = new fabric.Rect(itemTemplate);
itemRect2.set({
left : itemGeometry.x1+Canvas.app_template.item.quantity_gap*i,
top : itemGeometry.y1+Canvas.app_template.item.quantity_gap*i,
width : itemGeometry.width,
height: itemGeometry.height,
fill : Util.pickColorHex(item_color,'#000000',1-(i+1)*0.5/item.characs.quantity)
});
this.fabricCanvas.add(itemRect2);
itemRect2.sendToBack();
}

// Add some text around the item
this.addTexts(item, itemGeometry);

Expand Down Expand Up @@ -200,7 +215,7 @@ class Canvas {
originX : 'left',
originY : 'top',
top : itemGeometry.yhalf - Canvas.app_template.text.margin_y - this.config.text_size,
left : itemGeometry.x2 + Canvas.app_template.text.margin_x + itemGeometry.skew_error,
left : itemGeometry.x2 + itemGeometry.textmargin + itemGeometry.skew_error,
fontSize : this.config.text_size
});
this.fabricCanvas.add(itemText_vout);
Expand Down Expand Up @@ -229,7 +244,7 @@ class Canvas {
originX : 'left',
originY : 'top',
top : itemGeometry.yhalf + Canvas.app_template.text.margin_y - 2,
left : itemGeometry.x2 + Canvas.app_template.text.margin_x + itemGeometry.skew_error,
left : itemGeometry.x2 + itemGeometry.textmargin + itemGeometry.skew_error,
fontSize: this.config.text_size
});
this.fabricCanvas.add(itemText_ipout);
Expand Down Expand Up @@ -822,6 +837,7 @@ Canvas.app_template = {
item: {
width_coef : 45,
height_coef : 75,
quantity_gap: 5,
},
verticalNet: {
left_coef : 0.9
Expand Down
9 changes: 5 additions & 4 deletions js/class.Item.Load.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ class Load extends Item {
celltyp : 'A1',
cellmax : 'B1',
hidden : false,
shape : 1, // v1.7.0
badge_in : '', // v1.7.0
ptyp : 0, // v2.1.0
pmax : 0, // v2.1.0
shape : 1, // v1.7.0
badge_in : '', // v1.7.0
ptyp : 0, // v2.1.0
pmax : 0, // v2.1.0
quantity : '1', // v2.1.3
};
}

Expand Down
1 change: 1 addition & 0 deletions js/class.Item.Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Source extends Item {
badge_in : '', // v1.7.0
badge_out : '', // v1.7.0
resistor : '0', // v2.0.2
quantity : '1', // v2.1.3
sequence : { // v2.0.0
enable: {
exist: true,
Expand Down

0 comments on commit 385a8ba

Please sign in to comment.