небольшие корректировки в javascript
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
group = 'asys'
|
group = 'asys'
|
||||||
version = '0.8.5-SNAPSHOT'
|
version = '0.8.6-SNAPSHOT'
|
||||||
|
|
||||||
apply plugin: 'osgi'
|
apply plugin: 'osgi'
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* График.
|
||||||
|
* <code>this.props.datum</code> - данные в формате D3
|
||||||
|
*/
|
||||||
var NvLineChart = React.createClass({
|
var NvLineChart = React.createClass({
|
||||||
chart: null,
|
chart: null,
|
||||||
d3ChartData: null,
|
d3ChartData: null,
|
||||||
|
/*--------------------*/
|
||||||
render: function(){return(
|
render: function(){return(
|
||||||
ce('div', {id: 'chart'}, ce('svg', {style: {'height': '500px'}}))
|
ce('div', {id: 'chart'}, ce('svg', {style: {'height': '500px'}}))
|
||||||
)},
|
)},
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
console.debug('nvd3: componentDidMount');
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
nv.addGraph(function() {
|
nv.addGraph(function() {
|
||||||
_this.chart = nv.models.lineChart().useInteractiveGuideline(true);
|
_this.chart = nv.models.lineChart().useInteractiveGuideline(true);
|
||||||
_this.chart.xAxis.axisLabel('Time').tickFormat(function(d){ return d3.time.format('%X')(new Date(d)); });
|
_this.chart.xAxis.axisLabel('Time').tickFormat(function(d){ return d3.time.format('%X')(new Date(d)); });
|
||||||
_this.chart.yAxis.axisLabel('Players').tickFormat(d3.format('d'));
|
_this.chart.yAxis.axisLabel('Players').tickFormat(d3.format('d'));
|
||||||
|
|
||||||
_this.d3ChartData = d3.select('#chart svg').datum([{
|
_this.d3ChartData = d3.select('#chart svg').datum(_this.props.datum);
|
||||||
key: 'Online players',
|
|
||||||
color: '#37d668',
|
|
||||||
area: true,
|
|
||||||
values: _this.props.chartData
|
|
||||||
}]);
|
|
||||||
_this.d3ChartData.transition().duration(500).call(_this.chart);
|
_this.d3ChartData.transition().duration(500).call(_this.chart);
|
||||||
|
|
||||||
nv.utils.windowResize(_this.chart.update);
|
nv.utils.windowResize(_this.chart.update);
|
||||||
@@ -26,50 +24,44 @@ var NvLineChart = React.createClass({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
componentDidUpdate: function() {
|
componentDidUpdate: function() {
|
||||||
console.debug('nvd3: componentDidUpdate');
|
|
||||||
if (this.d3ChartData === null) return;
|
if (this.d3ChartData === null) return;
|
||||||
|
|
||||||
this.d3ChartData.datum([{
|
this.d3ChartData.datum(this.props.datum);
|
||||||
key: 'Online players',
|
|
||||||
color: '#37d668',
|
|
||||||
area: true,
|
|
||||||
values: this.props.chartData
|
|
||||||
}]);
|
|
||||||
this.d3ChartData.transition().duration(500).call(this.chart);
|
this.d3ChartData.transition().duration(500).call(this.chart);
|
||||||
nv.utils.windowResize(this.chart.update);
|
nv.utils.windowResize(this.chart.update);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var ServerInfo = React.createClass({
|
var ServerInfo = React.createClass({
|
||||||
sin2: function(){
|
|
||||||
var sin2 = [];
|
|
||||||
for (var i = 0; i < 100; i++) {
|
|
||||||
sin2.push({x: i, y: Math.sin(i/10) *0.25 + 0.5});
|
|
||||||
}
|
|
||||||
return sin2;
|
|
||||||
},
|
|
||||||
getInitialState: function(){return {
|
getInitialState: function(){return {
|
||||||
title: this.props.title,
|
title: null,
|
||||||
//Data is represented as an array of {x,y} pairs.
|
data: []
|
||||||
//example: chartData.push({x: i, y: Math.sin(i/10) *0.25 + 0.5})
|
|
||||||
chartData: []
|
|
||||||
}},
|
}},
|
||||||
render: function(){return(
|
render: function(){
|
||||||
ce('div', null,
|
if (this.state.title === null) {
|
||||||
ce('div', {className: 'pull-right'},
|
return ce('div', null, 'no data');
|
||||||
ce('div', {className: 'btn-group'},
|
} else {
|
||||||
ce(Button, {btnSize: 'xs'},
|
return(
|
||||||
ce('span', {className: 'glyphicon glyphicon-play'}), nbsp+'запуск'),
|
ce('div', null,
|
||||||
ce(Button, {btnSize: 'xs'},
|
ce('h2', {style: {'margin-top': '0px'}}, this.state.title),
|
||||||
ce('span', {className: 'glyphicon glyphicon-stop'}), nbsp+'остановка')
|
ce(NvLineChart, {datum: [{
|
||||||
|
key: 'Online players',
|
||||||
|
color: '#37d668',
|
||||||
|
area: true,
|
||||||
|
values: this.state.data
|
||||||
|
}]})
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
ce('h2', {style: {'margin-top': '0px'}}, this.state.title),
|
}
|
||||||
ce(NvLineChart, {chartData: this.state.chartData})
|
}
|
||||||
)
|
|
||||||
)}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Пункт списка серверов.
|
||||||
|
* <code>this.props.title</code> - заголовок / clientId
|
||||||
|
* <code>this.props.onClick</code> - callback события клика
|
||||||
|
* <code>this.props.active</code> - состояние активности (true/false)
|
||||||
|
*/
|
||||||
var ServerListItem = React.createClass({
|
var ServerListItem = React.createClass({
|
||||||
render: function(){
|
render: function(){
|
||||||
return(
|
return(
|
||||||
|
|||||||
@@ -1,19 +1,4 @@
|
|||||||
var ContentModule = React.createClass({
|
var ContentModule = React.createClass({
|
||||||
loadScript: function(url, fnLoad, fnError) {
|
|
||||||
const script = document.createElement("script");
|
|
||||||
script.src = url;
|
|
||||||
script.onload = fnLoad;
|
|
||||||
script.onerror = fnError;
|
|
||||||
document.body.appendChild(script);
|
|
||||||
},
|
|
||||||
loadStyle: function(url, fnLoad, fnError) {
|
|
||||||
const style = document.createElement("link");
|
|
||||||
style.rel = "stylesheet";
|
|
||||||
style.href = url;
|
|
||||||
style.onload = fnLoad;
|
|
||||||
style.onerror = fnError;
|
|
||||||
document.body.appendChild(style);
|
|
||||||
},
|
|
||||||
requestServerList: function() {
|
requestServerList: function() {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
fetch('/mcsmanager/servers.json')
|
fetch('/mcsmanager/servers.json')
|
||||||
@@ -50,6 +35,7 @@ var ContentModule = React.createClass({
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/*--------------------*/
|
||||||
getInitialState: function(){return{
|
getInitialState: function(){return{
|
||||||
nvScriptReady: 0,
|
nvScriptReady: 0,
|
||||||
serverList: []
|
serverList: []
|
||||||
@@ -57,12 +43,12 @@ var ContentModule = React.createClass({
|
|||||||
componentWillMount: function(){
|
componentWillMount: function(){
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
this.loadScript("/mcsmanager/components.js",
|
loadScript("/mcsmanager/components.js",
|
||||||
function(){ _this.setState({nvScriptReady: _this.state.nvScriptReady+1}); console.debug('components - ok'); },
|
function(){ _this.setState({nvScriptReady: _this.state.nvScriptReady+1}); console.debug('components - ok'); },
|
||||||
function(){ _this.setState({nvScriptReady: -5}); console.debug('components - error'); }
|
function(){ _this.setState({nvScriptReady: -5}); console.debug('components - error'); }
|
||||||
);
|
);
|
||||||
|
|
||||||
this.loadScript("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js",
|
loadScript("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js",
|
||||||
function(){
|
function(){
|
||||||
_this.setState({nvScriptReady: _this.state.nvScriptReady+1}); console.info('d3 - ok');
|
_this.setState({nvScriptReady: _this.state.nvScriptReady+1}); console.info('d3 - ok');
|
||||||
_this.loadStyle("https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.5/nv.d3.min.css");
|
_this.loadStyle("https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.5/nv.d3.min.css");
|
||||||
@@ -87,7 +73,7 @@ var ContentModule = React.createClass({
|
|||||||
|
|
||||||
element = ce('div', {className: 'row'},
|
element = ce('div', {className: 'row'},
|
||||||
ce('div', {className: 'col-md-4'}, ce(ServerList, null, serverListItems)),
|
ce('div', {className: 'col-md-4'}, ce(ServerList, null, serverListItems)),
|
||||||
ce('div', {className: 'col-md-8'}, ce(ServerInfo, {title: 'Server 2 [skywars-1]', ref: "serverInfo"}))
|
ce('div', {className: 'col-md-8'}, ce(ServerInfo, {ref: "serverInfo"}))
|
||||||
);
|
);
|
||||||
} else if (this.state.nvScriptReady < 0) {
|
} else if (this.state.nvScriptReady < 0) {
|
||||||
element = ce('span', null, 'error');
|
element = ce('span', null, 'error');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
group = 'asys'
|
group = 'asys'
|
||||||
version = '0.18.2-SNAPSHOT'
|
version = '0.18.3-SNAPSHOT'
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
@@ -1,6 +1,25 @@
|
|||||||
const ce = React.createElement;
|
const ce = React.createElement;
|
||||||
const nbsp = '\u00a0';
|
const nbsp = '\u00a0';
|
||||||
|
|
||||||
|
// -- Functions -- //
|
||||||
|
|
||||||
|
function loadScript(url, fnLoad, fnError) {
|
||||||
|
const script = document.createElement("script");
|
||||||
|
script.src = url;
|
||||||
|
script.onload = fnLoad;
|
||||||
|
script.onerror = fnError;
|
||||||
|
document.body.appendChild(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadStyle(url, fnLoad, fnError) {
|
||||||
|
const style = document.createElement("link");
|
||||||
|
style.rel = "stylesheet";
|
||||||
|
style.href = url;
|
||||||
|
style.onload = fnLoad;
|
||||||
|
style.onerror = fnError;
|
||||||
|
document.body.appendChild(style);
|
||||||
|
}
|
||||||
|
|
||||||
// -- Bootstrap -- //
|
// -- Bootstrap -- //
|
||||||
|
|
||||||
var MainMenuItem = React.createClass({
|
var MainMenuItem = React.createClass({
|
||||||
|
|||||||
Reference in New Issue
Block a user