clone

a browser-first diagram editor with live svg previews, local drafts and encrypted, accountless sharing

main
diagramzip / renderers / browser-run / frames / diagramsnet / vendor / assets / shapes / pid2 / mxPidMisc.js
mxPidMisc.js 11.3K
1/**2 * Copyright (c) 2006-2013, JGraph Holdings Ltd3 */45//**********************************************************************************************************************************************************6//Fan7//**********************************************************************************************************************************************************8/**9 * Extends mxShape.10 */11function mxShapePidFan(bounds, fill, stroke, strokewidth)12{13 mxShape.call(this);14 this.bounds = bounds;15 this.fill = fill;16 this.stroke = stroke;17 this.strokewidth = (strokewidth != null) ? strokewidth : 1;18};1920/**21 * Extends mxShape.22 */23mxUtils.extend(mxShapePidFan, mxShape);2425mxShapePidFan.prototype.cst = {26 SHAPE_FAN : 'mxgraph.pid2misc.fan',27 FAN_TYPE : 'fanType',28 COMMON : 'common',29 AXIAL : 'axial',30 RADIAL : 'radial'31};3233mxShapePidFan.prototype.customProperties = [34 {name: 'fanType', dispName: 'Type', type: 'enum', defVal:'field',35 enumList: [36 {val:'common', dispName:'Common'},37 {val:'axial', dispName:'Axial'},38 {val:'radial', dispName:'Radial'}39 ]}40];4142/**43 * Function: paintVertexShape44 * 45 * Paints the vertex shape.46 */47mxShapePidFan.prototype.paintVertexShape = function(c, x, y, w, h)48{49 c.translate(x, y);50 this.background(c, x, y, w, h);51 c.setShadow(false);52 this.foreground(c, x, y, w, h);53};5455mxShapePidFan.prototype.background = function(c, x, y, w, h)56{57 c.ellipse(0, 0, w, h);58 c.fillAndStroke();59};6061mxShapePidFan.prototype.foreground = function(c, x, y, w, h)62{63 c.begin();64 c.moveTo(w * 0.3, h * 0.045);65 c.lineTo(w * 0.97, h * 0.33);66 c.moveTo(w * 0.3, h * 0.955);67 c.lineTo(w * 0.97, h * 0.67);6869 c.moveTo(w * 0.4228, h * 0.3655);70 c.arcTo(w * 0.15, h * 0.03, 50, 0, 1, w * 0.5, h * 0.5);71 c.arcTo(w * 0.15, h * 0.03, 50, 0, 1, w * 0.3772, h * 0.4045);72 c.arcTo(w * 0.15, h * 0.03, 50, 0, 1, w * 0.3025, h * 0.271);73 c.arcTo(w * 0.15, h * 0.03, 50, 0, 1, w * 0.4228, h * 0.3655);74 c.close();7576 c.moveTo(w * 0.377, h * 0.5973);77 c.arcTo(w * 0.15, h * 0.03, -50, 0, 1, w * 0.4966, h * 0.5019);78 c.arcTo(w * 0.15, h * 0.03, -50, 0, 1, w * 0.423, h * 0.636);79 c.arcTo(w * 0.15, h * 0.03, -50, 0, 1, w * 0.3034, h * 0.7314);80 c.arcTo(w * 0.15, h * 0.03, -50, 0, 1, w * 0.377, h * 0.5973);81 c.close();82 c.stroke();8384 c.ellipse(w * 0.5, h * 0.47, w * 0.3, h * 0.06);85 c.stroke();8687 var type = mxUtils.getValue(this.style, mxShapePidFan.prototype.cst.FAN_TYPE, 'common');8889 if (type === mxShapePidFan.prototype.cst.AXIAL)90 {91 c.begin();92 c.moveTo(w * 0.1, h * 0.5);93 c.lineTo(w * 0.3, h * 0.5);94 c.stroke();95 }96 else if (type === mxShapePidFan.prototype.cst.RADIAL)97 {98 c.begin();99 c.moveTo(w * 0.2, h * 0.4);100 c.lineTo(w * 0.2, h * 0.6);101 c.stroke();102 }103};104105mxCellRenderer.registerShape(mxShapePidFan.prototype.cst.SHAPE_FAN, mxShapePidFan);106107//**********************************************************************************************************************************************************108//Column109//**********************************************************************************************************************************************************110/**111 * Extends mxShape.112 */113function mxShapePidColumn(bounds, fill, stroke, strokewidth)114{115 mxShape.call(this);116 this.bounds = bounds;117 this.fill = fill;118 this.stroke = stroke;119 this.strokewidth = (strokewidth != null) ? strokewidth : 1;120};121122/**123 * Extends mxShape.124 */125mxUtils.extend(mxShapePidColumn, mxShape);126127mxShapePidColumn.prototype.cst = {128 SHAPE_COLUMN : 'mxgraph.pid2misc.column',129 COLUMN_TYPE : 'columnType',130 COMMON : 'common',131 FIXED : 'fixed',132 FLUIDIZED : 'fluid',133 BAFFLE : 'baffle',134 VALVE : 'valve',135 BUBBLE : 'bubble',136 NOZZLE : 'nozzle',137 TRAY : 'tray'138};139140mxShapePidColumn.prototype.customProperties = [141 {name: 'columnType', dispName: 'Type', type: 'enum', defVal:'field',142 enumList: [143 {val:'common', dispName:'Common'},144 {val:'fixed', dispName:'Fixed'},145 {val:'fluid', dispName:'Fluid'},146 {val:'baffle', dispName:'Baffle'},147 {val:'valve', dispName:'Valve'},148 {val:'bubble', dispName:'Bubble'},149 {val:'nozzle', dispName:'Nozzle'},150 {val:'tray', dispName:'Tray'}151 ]}152];153154/**155 * Function: paintVertexShape156 * 157 * Paints the vertex shape.158 */159mxShapePidColumn.prototype.paintVertexShape = function(c, x, y, w, h)160{161 c.translate(x, y);162 this.background(c, x, y, w, h);163 c.setShadow(false);164 this.foreground(c, x, y, w, h);165};166167mxShapePidColumn.prototype.background = function(c, x, y, w, h)168{169 h = Math.max(h, 30);170171 c.begin();172 c.moveTo(0, 15);173 c.arcTo(w * 0.5, 15, 0, 0, 1, w, 15);174 c.lineTo(w, h - 15);175 c.arcTo(w * 0.5, 15, 0, 0, 1, 0, h - 15);176 c.close();177 c.fillAndStroke();178};179180mxShapePidColumn.prototype.foreground = function(c, x, y, w, h)181{182 var type = mxUtils.getValue(this.style, mxShapePidColumn.prototype.cst.COLUMN_TYPE, 'common');183184 if (type === mxShapePidColumn.prototype.cst.FIXED)185 {186 var step = w * 1.2;187 var range = h - 50;188 var rem = range % step;189 var off = rem * 0.5 + 25;190191 c.begin();192193 for (var i = 0; i <= range - step; i += step)194 {195 c.moveTo(0, i + off + step * 0.1);196 c.lineTo(w, i + off + step * 0.1);197 c.moveTo(0, i + off + step * 0.9);198 c.lineTo(w, i + off + step * 0.9);199 c.moveTo(0, i + off + step * 0.1);200 c.lineTo(w, i + off + step * 0.9);201 c.moveTo(0, i + off + step * 0.9);202 c.lineTo(w, i + off + step * 0.1);203 }204205 c.stroke();206 }207 else if (type === mxShapePidColumn.prototype.cst.TRAY)208 {209 var step = w * 0.2;210 var range = h - 50;211 var rem = range % step;212 var off = rem * 0.5 + 25;213214 c.setDashed(true);215 c.begin();216217 for (var i = 0; i <= range; i += step)218 {219 c.moveTo(0, i + off);220 c.lineTo(w, i + off);221 }222223 c.stroke();224 }225 else if (type === mxShapePidColumn.prototype.cst.FLUIDIZED)226 {227 var stepY = w * 0.1;228 var stepX = w * 0.1;229 var range = h - 50;230 var rem = range % stepY;231 var off = 25;232 var dot = Math.min(w, h) * 0.02;233 var fillColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#ffffff');234 var dashed = mxUtils.getValue(this.style, mxConstants.STYLE_DASHED, '0');235 var strokeColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, '#000000');236 var odd = 0;237238 c.setFillColor(strokeColor);239 c.setDashed(true);240 c.begin();241 c.moveTo(0, 25);242 c.lineTo(w, 25);243 c.moveTo(0, h - 25);244 c.lineTo(w, h - 25);245 c.stroke();246247 if (dashed === '0')248 {249 c.setDashed(false);250 }251 else252 {253 c.setDashed(true);254 }255256 var counter = 0;257258 for (var i = off + stepY * 0.5; i < range + off - dot; i += stepY)259 {260 var startJ = stepX;261 odd = counter % 2;262263 if (odd === 0)264 {265 startJ = stepX * 0.5;266 }267268 for (var j = startJ; j < w; j += stepX )269 {270 c.ellipse(j, i, dot, dot);271 c.fillAndStroke();272 }273274 counter++;275 }276 }277 else if (type === mxShapePidColumn.prototype.cst.BAFFLE)278 {279 var stepY = w * 0.2;280 var range = h - 50 - stepY;281 var rem = range % stepY;282 var off = 25 + stepY * 0.5;283 var odd = 0;284285 c.setDashed(true);286 c.begin();287 c.moveTo(0, 25);288 c.lineTo(w, 25);289 c.moveTo(0, h - 25);290 c.lineTo(w, h - 25);291 c.stroke();292293 var counter = 0;294295 c.begin();296297 for (var i = off + stepY * 0.5; i < range + off; i += stepY)298 {299 odd = counter % 2;300301 if (odd === 0)302 {303 c.moveTo(0, i);304 c.lineTo(w * 0.9, i);305 c.lineTo(w * 0.9, i - stepY * 0.3);306 }307 else308 {309 c.moveTo(w * 0.1, i - stepY * 0.5);310 c.lineTo(w * 0.1, i);311 c.lineTo(w, i);312 }313314315 counter++;316 }317318 c.stroke();319 }320 else if (type === mxShapePidColumn.prototype.cst.VALVE || type === mxShapePidColumn.prototype.cst.BUBBLE)321 {322 var stepY = w * 0.2;323 var range = h - 50 - stepY;324 var rem = range % stepY;325 var off = 25 + stepY * 0.5;326 var dashed = mxUtils.getValue(this.style, mxConstants.STYLE_DASHED, '0');327 var odd = 0;328329 c.setFillColor(strokeColor);330 c.setDashed(true);331 c.begin();332 c.moveTo(0, 25);333 c.lineTo(w, 25);334 c.moveTo(0, h - 25);335 c.lineTo(w, h - 25);336 c.stroke();337338 if (dashed === '0')339 {340 c.setDashed(false);341 }342 else343 {344 c.setDashed(true);345 }346 347 c.begin();348349 for (var i = off + stepY * 0.5; i < range + off; i += stepY)350 {351 c.moveTo(0, i);352 c.lineTo(w * 0.4, i);353 354 if (type === mxShapePidColumn.prototype.cst.VALVE)355 {356 c.moveTo(w * 0.4, i - stepY * 0.2);357 c.lineTo(w * 0.6, i - stepY * 0.2);358 }359 else if (type === mxShapePidColumn.prototype.cst.BUBBLE)360 {361 c.moveTo(w * 0.25, i - stepY * 0.2);362 c.arcTo(stepY * 3, stepY * 3, 0, 0, 1, w * 0.75, i - stepY * 0.2);363 }364365 c.moveTo(w * 0.6, i);366 c.lineTo(w, i);367 }368369 c.stroke();370 }371 else if (type === mxShapePidColumn.prototype.cst.NOZZLE)372 {373 var step = w * 1.2;374 var range = h - 50;375 var rem = range % step;376 var off = rem * 0.5 + 25;377 var dashed = mxUtils.getValue(this.style, mxConstants.STYLE_DASHED, 0);378379380 for (var i = 0; i <= range - step; i += step)381 {382 c.setDashed(true);383 384 c.begin();385 c.moveTo(0, i + off + step * 0.2);386 c.lineTo(w, i + off + step * 0.2);387 c.moveTo(0, i + off + step * 0.8);388 c.lineTo(w, i + off + step * 0.8);389 c.stroke();390 391 if (dashed === 0)392 {393 c.setDashed(false);394 }395 else396 {397 c.setDashed(true);398 }399400 c.begin();401 c.moveTo(0, i + off + step * 0.2);402 c.lineTo(w, i + off + step * 0.8);403 c.moveTo(0, i + off + step * 0.8);404 c.lineTo(w, i + off + step * 0.2);405406 if (i !== 0)407 {408 c.moveTo(0, i + off);409 c.lineTo(w * 0.5, i + off);410 c.moveTo(w * 0.5 - step * 0.08, i + off + step * 0.08);411 c.lineTo(w * 0.5, i + off);412 c.lineTo(w * 0.5 + step * 0.08, i + off + step * 0.08);413 c.moveTo(w * 0.5, i + off);414 c.lineTo(w * 0.5, i + off + step * 0.08);415 }416 417 c.stroke();418 }419 420 c.stroke();421 }422};423424mxCellRenderer.registerShape(mxShapePidColumn.prototype.cst.SHAPE_COLUMN, mxShapePidColumn);425426//**********************************************************************************************************************************************************427//Conveyor428//**********************************************************************************************************************************************************429/**430 * Extends mxShape.431 */432function mxShapePidConveyor(bounds, fill, stroke, strokewidth)433{434 mxShape.call(this);435 this.bounds = bounds;436 this.fill = fill;437 this.stroke = stroke;438 this.strokewidth = (strokewidth != null) ? strokewidth : 1;439};440441/**442 * Extends mxShape.443 */444mxUtils.extend(mxShapePidConveyor, mxShape);445446mxShapePidConveyor.prototype.cst = {447 SHAPE_CONVEYOR : 'mxgraph.pid2misc.conveyor'448};449450/**451 * Function: paintVertexShape452 * 453 * Paints the vertex shape.454 */455mxShapePidConveyor.prototype.paintVertexShape = function(c, x, y, w, h)456{457 c.translate(x, y);458 this.background(c, x, y, w, h);459 c.setShadow(false);460};461462mxShapePidConveyor.prototype.background = function(c, x, y, w, h)463{464 var wheelSize = Math.min(h, w * 0.5);465466 c.begin();467 c.moveTo(wheelSize * 0.5, 0);468 c.lineTo(w - wheelSize * 0.5, 0);469 c.stroke();470471 c.ellipse(0, 0, wheelSize, wheelSize);472 c.fillAndStroke();473 c.ellipse(w - wheelSize, 0, wheelSize, wheelSize);474 c.fillAndStroke();475476 c.begin();477 c.moveTo(wheelSize * 0.5, wheelSize);478 c.lineTo(w - wheelSize * 0.5, wheelSize);479 c.stroke();480481 //holders482483 var dist = w - wheelSize * 1.8;484 var startX = wheelSize * 0.9;485 var step = wheelSize * 0.7;486487 for (var i = 0; i < dist; i = i + step)488 {489 c.rect(startX + i, 0, wheelSize * 0.2, wheelSize * 0.1);490 c.fillAndStroke();491 c.rect(startX + i, wheelSize * 0.9, wheelSize * 0.2, wheelSize * 0.1);492 c.fillAndStroke();493 }494495};496497mxCellRenderer.registerShape(mxShapePidConveyor.prototype.cst.SHAPE_CONVEYOR, mxShapePidConveyor);