ShapeBase API를 사용하여 모든 셰이프의 속성을 사용자 정의할 수 있습니다.
allowMove: 셰이프 이동을 비활성화할지 여부를 가져오거나 설정합니다.
allowResize: 셰이프의 크기 조정 모드를 가져오거나 설정합니다.
allowRotate: 셰이프 회전을 비활성화할지 여부를 가져오거나 설정합니다.
showHandle: 셰이프 핸들을 표시할지 여부를 가져오거나 설정합니다.
isSelected: 이 셰이프를 선택할지 여부를 가져오거나 설정합니다.
width/height: 셰이프의 너비 또는 높이를 가져오거나 설정합니다.
x/y: 셰이프의 가로 또는 세로 위치를 가져오거나 설정합니다.
Shape API를 사용하여 자동 셰이프의 속성을 사용자 정의할 수 있습니다.
rotate: 셰이프의 회전 각도를 가져오거나 설정합니다(도 단위).
style: 셰이프의 스타일을 가져오거나 설정합니다.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import './styles.css';
import { AppFunc } from './app-func';
// import { App } from './app-class';
// 1. Functional Component sample
ReactDOM.render(<AppFunc />, document.getElementById('app'));
// 2. Class Component sample
// ReactDOM.render(<App />, document.getElementById('app'));
import * as React from 'react';
import GC from '@mescius/spread-sheets';
import "@mescius/spread-sheets-shapes"
import { SpreadSheets } from "@mescius/spread-sheets-react";
import '@mescius/spread-sheets-resources-ko';
GC.Spread.Common.CultureManager.culture("ko-kr");
import Panel from './panel.jsx';
let spread = null;
export function AppFunc() {
const [showShapeFillPropPanel, setShowShapeFillPropPanel] = React.useState(false);
const updateShapeStyle = (action, value) => {
let sheet = spread.getActiveSheet();
let activeShape = sheet.shapes.all().filter(function (sp) {
return sp.isSelected();
});
if (activeShape.length > 0) {
activeShape.forEach((shape) => {
if (shape instanceof GC.Spread.Sheets.Shapes.Shape) {
_setShapeStyle(shape, action, value);
}
});
sheet.repaint();
}
}
const _setShapeStyle = (shape, action, value) => {
if (action === 'rotate') {
shape.rotate(value);
} else if (action === 'resizeMode') {
let resizeMode;
if (value === 'true') {
resizeMode = true;
} if (value === 'false') {
resizeMode = false;
} else {
resizeMode = Number(value);
}
shape.allowResize(resizeMode);
} else {
var shapeStyle = shape.style();
if (action === 'background') {
shapeStyle.fill.color = value;
} else if (action === 'transparency') {
shapeStyle.fill.transparency = value;
}
shape.style(shapeStyle);
}
}
const setShapePropVisibility = (isShow) => {
setShowShapeFillPropPanel(isShow);
}
const initSpread = (currSpread) => {
spread = currSpread;
spread.getActiveSheet().shapes.add("oval", GC.Spread.Sheets.Shapes.AutoShapeType.oval, 40, 20, 150, 150);
spread.getActiveSheet().shapes.add("curvedUpArrow", GC.Spread.Sheets.Shapes.AutoShapeType.curvedUpArrow, 250, 20, 150, 150);
spread.getActiveSheet().shapes.add("actionButtonSound", GC.Spread.Sheets.Shapes.AutoShapeType.actionButtonSound, 460, 20, 150, 150);
spread.getActiveSheet().shapes.add("flowchartDecision", GC.Spread.Sheets.Shapes.AutoShapeType.flowchartDecision, 40, 240, 150, 150);
spread.getActiveSheet().shapes.add("mathMinus", GC.Spread.Sheets.Shapes.AutoShapeType.mathMinus, 250, 240, 150, 150);
spread.getActiveSheet().shapes.add("donut", GC.Spread.Sheets.Shapes.AutoShapeType.donut, 460, 240, 150, 150);
bindSpreadEvent();
}
const bindSpreadEvent = () => {
spread.bind(GC.Spread.Sheets.Events.ShapeSelectionChanged, function () {
let sheet = spread.getActiveSheet();
var selectedShape = sheet.shapes.all().filter(function (sp) {
return sp.isSelected();
});
var isShapeSelected = false,
isConnectorSelected = false;
if (selectedShape.length > 0) {
selectedShape.forEach((shape) => {
if (!isShapeSelected && shape instanceof GC.Spread.Sheets.Shapes.Shape) {
isShapeSelected = true;
} else if (!isConnectorSelected && shape instanceof GC.Spread.Sheets.Shapes.ConnectorShape) {
isConnectorSelected = true;
}
});
setShapePropVisibility(isShapeSelected);
} else {
setShapePropVisibility(false);
}
})
}
return (<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)}>
</SpreadSheets>
</div>
<Panel
showShapeFillPropPanel={showShapeFillPropPanel}
updateShapeStyle={(action, value) => { updateShapeStyle(action, value) }}>
</Panel>
</div>);
}
import * as React from 'react';
import GC from '@mescius/spread-sheets';
import "@mescius/spread-sheets-shapes"
import { SpreadSheets } from "@mescius/spread-sheets-react";
import '@mescius/spread-sheets-resources-ko';
GC.Spread.Common.CultureManager.culture("ko-kr");
import Panel from './panel.jsx';
const Component = React.Component;
export class App extends Component {
constructor(props) {
super(props);
this.spread = null;
this.state = {
showShapeFillPropPanel: false
}
}
render() {
const {
showShapeFillPropPanel
} = this.state;
return (<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => this.initSpread(spread)}>
</SpreadSheets>
</div>
<Panel
showShapeFillPropPanel={showShapeFillPropPanel}
updateShapeStyle={(action, value) => { this.updateShapeStyle(action, value) }}>
</Panel>
</div>);
}
updateShapeStyle(action, value) {
let sheet = this.spread.getActiveSheet();
let activeShape = sheet.shapes.all().filter(function (sp) {
return sp.isSelected();
});
if (activeShape.length > 0) {
activeShape.forEach((shape) => {
if (shape instanceof GC.Spread.Sheets.Shapes.Shape) {
this._setShapeStyle(shape, action, value);
}
});
sheet.repaint();
}
}
_setShapeStyle(shape, action, value) {
if (action === 'rotate') {
shape.rotate(value);
} else if (action === 'resizeMode') {
let resizeMode;
if (value === 'true') {
resizeMode = true;
} if (value === 'false') {
resizeMode = false;
} else {
resizeMode = Number(value);
}
shape.allowResize(resizeMode);
} else {
var shapeStyle = shape.style();
if (action === 'background') {
shapeStyle.fill.color = value;
} else if (action === 'transparency') {
shapeStyle.fill.transparency = value;
}
shape.style(shapeStyle);
}
}
setShapePropVisibility(isShow) {
this.setState({ showShapeFillPropPanel: isShow })
}
initSpread(spread) {
this.spread = spread;
spread.getActiveSheet().shapes.add("oval", GC.Spread.Sheets.Shapes.AutoShapeType.oval, 40, 20, 150, 150);
spread.getActiveSheet().shapes.add("curvedUpArrow", GC.Spread.Sheets.Shapes.AutoShapeType.curvedUpArrow, 250, 20, 150, 150);
spread.getActiveSheet().shapes.add("actionButtonSound", GC.Spread.Sheets.Shapes.AutoShapeType.actionButtonSound, 460, 20, 150, 150);
spread.getActiveSheet().shapes.add("flowchartDecision", GC.Spread.Sheets.Shapes.AutoShapeType.flowchartDecision, 40, 240, 150, 150);
spread.getActiveSheet().shapes.add("mathMinus", GC.Spread.Sheets.Shapes.AutoShapeType.mathMinus, 250, 240, 150, 150);
spread.getActiveSheet().shapes.add("donut", GC.Spread.Sheets.Shapes.AutoShapeType.donut, 460, 240, 150, 150);
this.bindSpreadEvent();
}
bindSpreadEvent() {
let spread = this.spread,
self = this;
spread.bind(GC.Spread.Sheets.Events.ShapeSelectionChanged, function () {
let sheet = spread.getActiveSheet();
var selectedShape = sheet.shapes.all().filter(function (sp) {
return sp.isSelected();
});
var isShapeSelected = false,
isConnectorSelected = false;
if (selectedShape.length > 0) {
selectedShape.forEach((shape) => {
if (!isShapeSelected && shape instanceof GC.Spread.Sheets.Shapes.Shape) {
isShapeSelected = true;
} else if (!isConnectorSelected && shape instanceof GC.Spread.Sheets.Shapes.ConnectorShape) {
isConnectorSelected = true;
}
});
self.setShapePropVisibility(isShapeSelected);
} else {
self.setShapePropVisibility(false);
}
})
}
}
import * as React from 'react';
import "@mescius/spread-sheets-shapes"
export default function Panel(props) {
const [fillAndRotateOption, setFillAndRotateOption] = React.useState({
rotate: 30,
transparency: 0.5,
background: "#00A2E8",
resizeMode: 'true'
});
const {
updateShapeStyle,
showShapeFillPropPanel
} = props;
return (<div class="options-container">
<div class="option-row">
Select a shape then change fill color, fill transparency or rotate property to see the effect:
</div>
<div id="divideLine" class="divide-line"></div>
{
showShapeFillPropPanel &&
<div id="shapeFillProp" class="option-row">
<label>Fill Color: </label>
<input value={fillAndRotateOption.background} type="color" onChange={(event) => { setFillAndRotateOption({ ...fillAndRotateOption, background: event.target.value }); }} />
<input type="button" onClick={() => { updateShapeStyle('background', fillAndRotateOption.background) }} value="Set" />
<label>Fill Transparency: </label>
<input value={fillAndRotateOption.transparency} type="number" min="0" max="1" step={0.1} onChange={(event) => { setFillAndRotateOption({ ...fillAndRotateOption, transparency: parseFloat(event.target.value) }); }} />
<input type="button" onClick={() => { updateShapeStyle('transparency', fillAndRotateOption.transparency) }} value="Set" />
<label for='txtRotate'>Rotate: </label>
<input type="number" min="0" max="360" value={fillAndRotateOption.rotate} onChange={(event) => { setFillAndRotateOption({ ...fillAndRotateOption, rotate: parseInt(event.target.value) }); }} />
<input type="button" onClick={() => { updateShapeStyle('rotate', fillAndRotateOption.rotate) }} value="Set" />
<label for='txtResizeMode'>Resize Mode: </label>
<select id="txtResizeMode" value={fillAndRotateOption.resizeMode} onChange={(event) => { setFillAndRotateOption({ ...fillAndRotateOption, resizeMode: event.target.value }); }}>
<option value="true">All</option>
<option value="0">Aspect</option>
<option value="1">Horizontal</option>
<option value="2">Vertical</option>
<option value="false">None</option>
</select>
<input type="button" onClick={() => { updateShapeStyle('resizeMode', fillAndRotateOption.resizeMode) }} value="Set" />
</div>
}
</div>);
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- SystemJS -->
<script src="$DEMOROOT$/ko/react/node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('$DEMOROOT$/ko/lib/react/license.js').then(function () {
System.import('./src/app');
});
</script>
</head>
<body>
<div id="app"></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;
}
#app{
width: 100%;
height: 100%;
}
(function (global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true,
react: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js',
'@mescius/spread-sheets-shapes': 'npm:@mescius/spread-sheets-shapes/index.js',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js',
'@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js',
'react': 'npm:react/umd/react.production.min.js',
'react-dom': 'npm:react-dom/umd/react-dom.production.min.js',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'jsx'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);