シェイプの境界線

SpreadJSでは、シェイプに境界線を追加し、色、透明度、幅など、さまざまな書式を適用できます。

Shape APIを使用して、autoShapesのプロパティをカスタマイズできます: text:シェイプのテキストを取得または設定します。 style:シェイプのスタイルを取得または設定します。 ConnectorShape APIを使用して、connectorShapesのプロパティをカスタマイズできます: style:コネクタシェイプのスタイルを取得または設定します。
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); initEvent(spread); }; var lineCapStyle = { flat: 2, square: 1, round: 0 }; var lineJoinStyle = { round: 0, miter: 1, bevel: 2 }; var lineDashStyle = { solid: 0, squareDot: 1, dash: 2, longDash: 3, dashDot: 4, longDashDot: 5, longDashDotDot: 6, sysDash: 7, sysDot: 8, sysDashDot: 9, dashDotDot: 10 }; var activeShape; function fillShapeTypeList(type, dom) { var names = []; for (var name in type) { if(name === "none" || (parseInt(name, 10)) == name) { continue; } names.push({name: name, value: type[name]}); } names.sort(function (a, b) { return a.name > b.name ? 1 : -1 }); var html = ""; names.forEach(function (item) { html += '<option value="' + item.value + '">' + item.name + '</option>'; }); dom.innerHTML= html; } function getActiveConnectorShape(sheet) { return sheet.shapes.all().filter(function(sp){ return sp.isSelected() && sp instanceof GC.Spread.Sheets.Shapes.ConnectorShape; }); } function initSpread(spread) { setBorderPropVisibility("none"); fillShapeTypeList(lineDashStyle, _getElementById("borderLineStyle")); fillShapeTypeList(lineCapStyle, _getElementById("borderCapLineStyle")); fillShapeTypeList(lineJoinStyle, _getElementById("borderJoinLineStyle")); let oval = spread.getActiveSheet().shapes.add("oval", GC.Spread.Sheets.Shapes.AutoShapeType.oval, 40, 20, 150, 150); let ovalStyle = oval.style(); ovalStyle.fill.color = "#FFFFFF"; oval.style(ovalStyle); var rectangle = spread.getActiveSheet().shapes.add("rectangle", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 40, 230, 150, 150); let rectangleStyle = rectangle.style(); rectangleStyle.fill.color = "#FFFFFF"; rectangle.style(rectangleStyle); spread.getActiveSheet().shapes.addConnector("line", GC.Spread.Sheets.Shapes.ConnectorType.straight, 250, 20, 400, 150); spread.getActiveSheet().shapes.addConnector("line", GC.Spread.Sheets.Shapes.ConnectorType.elbow, 250, 250, 400, 350); } function setBorderPropVisibility(display) { var borderProp = _getElementById("borderProp"); borderProp.style.display = display; } function initEvent(spread) { var spreadNS = GC.Spread.Sheets; var sheet = spread.getActiveSheet(); sheet.bind(spreadNS.Events.ShapeSelectionChanged, function () { var selectedShape = sheet.shapes.all().filter(function(sp){ return sp.isSelected(); }); var isShapeSelected = false, isConnectorSelected = false; if (selectedShape.length > 0) { selectedShape.forEach(function (shape) { if (!isShapeSelected && shape instanceof spreadNS.Shapes.Shape) { isShapeSelected = true; } else if (!isConnectorSelected && shape instanceof spreadNS.Shapes.ConnectorShape) { isConnectorSelected = true; } }); setBorderPropVisibility("block"); } else { setBorderPropVisibility("none"); } }); _getElementById("borderColorActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'color', _getElementById("borderColorStyle")); }); _getElementById("borderTransparencyActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'transparency', _getElementById("borderTransparencyStyle")); }); _getElementById("borderWidthActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'width', _getElementById("borderWidthStyle")); }); _getElementById("borderLineStyleActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'lineStyle', _getElementById("borderLineStyle")); }); _getElementById("borderCapLineActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'capType', _getElementById("borderCapLineStyle")); }); _getElementById("borderJoinLineActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'joinType', _getElementById("borderJoinLineStyle")); }); } function _handleShapeBorderAction(spread, action, valueDom) { var sheet = spread.getActiveSheet(); activeShape = sheet.shapes.all().filter(function (sp) { return sp.isSelected(); }); if (activeShape) { activeShape.forEach(function (shape) { var shapeStyle = shape.style(); shapeStyle.line[action] = valueDom.value; shape.style(shapeStyle); }); sheet.repaint(); } } function _getElementById(id){ return document.getElementById(id); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="spreadjs culture" content="ja-jp" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-shapes/dist/gc.spread.sheets.shapes.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <div class="options-container"> <div class="option-row"> シェイプを選択し、境界線のプロパティを変更して効果を確認してください: </div> <div id="divideLine" class="divide-line"></div> <div id="borderProp" class="option-row"> <label>境界線の色:</label> <input id="borderColorStyle" data-attr="color" type="color" value="#00A2E8"/> <input type="button" id='borderColorActionBtn' value="設定"/> <label>境界線の透過性:</label> <input id="borderTransparencyStyle" data-attr="transparency" type="text" value="0.5"/> <input type="button" id='borderTransparencyActionBtn' value="設定"/> <label>境界線の幅:</label> <input id="borderWidthStyle" data-attr="width" type="number" value="1"/> <input type="button" id='borderWidthActionBtn' value="設定"/> <label>境界線のスタイル:</label> <select id="borderLineStyle" data-attr="lineStyle"></select> <input type="button" id='borderLineStyleActionBtn' value="設定"/> <label>境界線の先端のスタイル:</label> <select id="borderCapLineStyle" data-attr="capType"></select> <input type="button" id='borderCapLineActionBtn' value="設定"/> <label>境界線の結合点のスタイル:</label> <select id="borderJoinLineStyle" data-attr="joinType"></select> <input type="button" id='borderJoinLineActionBtn' value="設定"/> </div> </div> </div></body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding-left: 5px; } .divide-line { width: 100%; height: 1px; background: #cbcbcb; margin-top: 10px; margin-bottom: 3px; } .title { text-align: center; font-weight: bold; } label { display: block; margin-top: 15px; margin-bottom: 5px; } p { padding: 2px 10px; background-color: #F4F8EB; } input { width: 160px; margin-left: 10px; display: inline; } input[type=button] { width: 50px; margin-left: 1px; } select { width: 160px; margin-left: 10px; display: inline; } textarea { width: 160px; margin-left: 10px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }