Shape API를 사용하여 자동 셰이프의 속성을 사용자 정의할 수 있습니다.
text: 셰이프의 텍스트를 가져오거나 설정합니다.
style: 셰이프의 스타일을 가져오거나 설정합니다.
ConnectorShape API를 사용하여 연결선 셰이프의 속성을 사용자 정의할 수 있습니다.
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 [showBorderPanel, setShowBorderPanel] = React.useState(false);
const updateShapeBorderStyle = (action, value) => {
let sheet = spread.getActiveSheet();
let activeShape = sheet.shapes.all().filter(function (sp) {
return sp.isSelected();
});
if (activeShape.length > 0) {
activeShape.forEach(function (shape) {
let shapeStyle = shape.style();
shapeStyle.line[action] = value;
shape.style(shapeStyle);
});
sheet.repaint();
}
}
const setBorderPropVisibility = (isShow) => {
setShowBorderPanel(isShow);
}
const initSpread = (currSpread) => {
spread = currSpread;
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);
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;
}
});
setBorderPropVisibility(true);
} else {
setBorderPropVisibility(false);
}
})
}
return (<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)}>
</SpreadSheets>
</div>
<Panel
showBorderPanel={showBorderPanel}
updateShapeBorderStyle={(action, value) => { updateShapeBorderStyle(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.autoGenerateColumns = false;
this.state = {
showBorderPanel: false
}
}
render() {
const {
showBorderPanel
} = this.state;
return (<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => this.initSpread(spread)}>
</SpreadSheets>
</div>
<Panel
showBorderPanel={showBorderPanel}
updateShapeBorderStyle={(action, value) => { this.updateShapeBorderStyle(action, value) }}>
</Panel>
</div>);
}
updateShapeBorderStyle(action, value) {
let sheet = this.spread.getActiveSheet();
let activeShape = sheet.shapes.all().filter(function (sp) {
return sp.isSelected();
});
if (activeShape.length > 0) {
activeShape.forEach(function (shape) {
let shapeStyle = shape.style();
shapeStyle.line[action] = value;
shape.style(shapeStyle);
});
sheet.repaint();
}
}
setBorderPropVisibility(isShow) {
this.setState({ showBorderPanel: isShow });
}
initSpread(spread) {
this.spread = spread;
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);
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.setBorderPropVisibility(true);
} else {
self.setBorderPropVisibility(false);
}
})
}
}
import * as React from 'react';
import "@mescius/spread-sheets-shapes"
export default function Panel(props) {
const lineCapStyle = {
flat: 2,
square: 1,
round: 0
};
const lineJoinStyle = {
round: 0,
miter: 1,
bevel: 2
};
const lineDashStyle = {
solid: 0,
squareDot: 1,
dash: 2,
longDash: 3,
dashDot: 4,
longDashDot: 5,
longDashDotDot: 6,
sysDash: 7,
sysDot: 8,
sysDashDot: 9,
dashDotDot: 10
};
const {
updateShapeBorderStyle,
showBorderPanel
} = props;
const [borderOption, setBorderOption] = React.useState({
borderColor: "#00A2E8",
borderTransparency: 0.5,
borderWidth: 1,
borderLineStyle: 2,
borderCapType: 2,
borderJoinType: 2,
lineCapStyleList: getEnumList(lineCapStyle),
lineJoinStyleList: getEnumList(lineJoinStyle),
lineDashStyleList: getEnumList(lineDashStyle)
});
return (<div class="options-container">
<div class="option-row">
Try selecting a shape and change the border properties to see the effect:
</div>
<div id="divideLine" class="divide-line"></div>
{showBorderPanel &&
<div class="option-row">
<label>Border Color: </label>
<input value={borderOption.borderColor} type="color" onChange={(event) => { setBorderOption({ ...borderOption, borderColor: event.target.value }); }} />
<input type="button" onClick={() => { updateShapeBorderStyle('color', borderOption.borderColor) }} value="Set" />
<label>Border Transparency: </label>
<input value={borderOption.borderTransparency} type="text" onChange={(event) => { setBorderOption({ ...borderOption, borderTransparency: event.target.value }); }} />
<input type="button" onClick={() => { updateShapeBorderStyle('transparency', borderOption.borderTransparency) }} value="Set" />
<label>Border Width: </label>
<input value={borderOption.borderWidth} type="number" onChange={(event) => { setBorderOption({ ...borderOption, borderWidth: event.target.value }); }} />
<input type="button" onClick={() => { updateShapeBorderStyle('width', borderOption.borderWidth) }} value="Set" />
<label>Border Line Style: </label>
<select value={borderOption.borderLineStyle} onChange={(event) => { setBorderOption({ ...borderOption, borderLineStyle: event.target.value }); }}>
{borderOption.lineDashStyleList.map(({ name, value }) => {
return <option value={value} key={name}>{name}</option>
})}
</select>
<input type="button" onClick={() => { updateShapeBorderStyle('lineStyle', borderOption.borderLineStyle) }} value="Set" />
<label>Border Cap Line Style: </label>
<select value={borderOption.borderCapType} onChange={(event) => { setBorderOption({ ...borderOption, borderCapType: event.target.value }); }}>
{borderOption.lineCapStyleList.map(({ name, value }) => {
return <option value={value} key={name}>{name}</option>
})}
</select>
<input type="button" onClick={() => { updateShapeBorderStyle('capType', borderOption.borderCapType) }} value="Set" />
<label>Border Join Line Style: </label>
<select value={borderOption.borderJoinType} onChange={(event) => { setBorderOption({ ...borderOption, borderJoinType: event.target.value }); }}>
{borderOption.lineJoinStyleList.map(({ name, value }) => {
return <option value={value} key={name}>{name}</option>
})}
</select>
<input type="button" onClick={() => { updateShapeBorderStyle('joinType', borderOption.borderJoinType) }} value="Set" />
</div>
}
</div >);
}
function getEnumList(enumObject) {
let names = [];
for (var name in enumObject) {
if (name === "none" || (parseInt(name, 10)) == name) {
continue;
}
names.push({
name: name,
value: enumObject[name]
});
}
names.sort(function (a, b) {
return a.name > b.name ? 1 : -1
});
return names;
}
<!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);