1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Add grid background to visualization edit

This commit is contained in:
Markus Grigull 2017-07-27 23:32:09 +02:00
parent aaff21eb78
commit 32f2c719da
2 changed files with 56 additions and 8 deletions

42
src/components/grid.js Normal file
View file

@ -0,0 +1,42 @@
/**
* File: grid.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 27.07.2017
*
* This file is part of VILLASweb.
*
* VILLASweb is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VILLASweb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VILLASweb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import React from 'react';
class Grid extends React.Component {
render() {
if (this.props.disabled) return false;
return (
<svg width="100%" height="100%">
<defs>
<pattern id="grid" width={this.props.size} height={this.props.size} patternUnits="userSpaceOnUse">
<path d={"M " + this.props.size + " 0 L 0 0 0 " + this.props.size} fill="none" stroke="gray" strokeWidth="0.5" />
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#grid)" />
</svg>
);
}
}
export default Grid;

View file

@ -30,6 +30,7 @@ import ToolboxItem from '../components/toolbox-item';
import Dropzone from '../components/dropzone';
import Widget from './widget';
import EditWidget from '../components/dialog/edit-widget';
import Grid from '../components/grid';
import UserStore from '../stores/user-store';
import VisualizationStore from '../stores/visualization-store';
@ -61,7 +62,6 @@ class Visualization extends Component {
project: prevState.project || null,
simulation: prevState.simulation || null,
editing: prevState.editing || false,
grid: prevState.grid || [1, 1],
editModal: prevState.editModal || false,
modalData: prevState.modalData || null,
@ -339,7 +339,11 @@ class Visualization extends Component {
value = 1;
}
this.setState({ grid: [value, value] });
let visualization = Object.assign({}, this.state.visualization, {
grid: value
});
this.setState({ visualization });
}
render() {
@ -374,9 +378,9 @@ class Visualization extends Component {
{this.state.editing &&
<div className="section-grid-slider">
<span>Grid: {this.state.grid[0] > 1 ? this.state.grid[0] : 'Disabled'}</span>
<span>Grid: {this.state.visualization.grid > 1 ? this.state.visualization.grid : 'Disabled'}</span>
<Slider style={{ width: '80px' }} step={5} onChange={value => this.setGrid(value)} />
<Slider value={this.state.visualization.grid} style={{ width: '80px' }} step={5} onChange={value => this.setGrid(value)} />
</div>
}
</div>
@ -390,9 +394,9 @@ class Visualization extends Component {
<ToolboxItem name="Label" type="widget" />
<ToolboxItem name="Image" type="widget" />
<ToolboxItem name="PlotTable" type="widget" />
<ToolboxItem name="Button" type="widget" />
<ToolboxItem name="NumberInput" type="widget" />
<ToolboxItem name="Slider" type="widget" />
<ToolboxItem name="Button" type="widget" disabled />
<ToolboxItem name="NumberInput" type="widget" disabled />
<ToolboxItem name="Slider" type="widget" disabled />
<ToolboxItem name="Gauge" type="widget" />
<ToolboxItem name="Box" type="widget" />
</div>
@ -401,8 +405,10 @@ class Visualization extends Component {
<Dropzone height={this.state.dropZoneHeight} onDrop={(item, position) => this.handleDrop(item, position)} editing={this.state.editing}>
{current_widgets != null &&
Object.keys(current_widgets).map( (widget_key) => (
<Widget key={widget_key} data={current_widgets[widget_key]} simulation={this.state.simulation} onWidgetChange={(w, k) => this.widgetChange(w, k)} onWidgetStatusChange={(w, k) => this.widgetStatusChange(w, k)} editing={this.state.editing} index={widget_key} grid={this.state.grid} />
<Widget key={widget_key} data={current_widgets[widget_key]} simulation={this.state.simulation} onWidgetChange={(w, k) => this.widgetChange(w, k)} onWidgetStatusChange={(w, k) => this.widgetStatusChange(w, k)} editing={this.state.editing} index={widget_key} grid={[this.state.visualization.grid, this.state.visualization.grid]} />
))}
<Grid size={this.state.visualization.grid} disabled={this.state.visualization.grid === 1 || !this.state.editing} />
</Dropzone>
{current_widgets != null &&