MCSM: перенос компонентов в отдельный файл
This commit is contained in:
@@ -1,58 +1,3 @@
|
||||
var NvLineChart = React.createClass({
|
||||
sinAndCos: function(){
|
||||
var sin = [],sin2 = [],cos = [];
|
||||
|
||||
//Data is represented as an array of {x,y} pairs.
|
||||
for (var i = 0; i < 100; i++) {
|
||||
sin.push({x: i, y: Math.sin(i/10)});
|
||||
sin2.push({x: i, y: Math.sin(i/10) *0.25 + 0.5});
|
||||
cos.push({x: i, y: .5 * Math.cos(i/10)});
|
||||
}
|
||||
|
||||
//Line chart data should be sent as an array of series objects.
|
||||
return [
|
||||
{
|
||||
values: sin, //values - represents the array of {x,y} data points
|
||||
key: 'Sine Wave', //key - the name of the series.
|
||||
color: '#ff7f0e' //color - optional: choose your own line color.
|
||||
},
|
||||
{
|
||||
values: cos,
|
||||
key: 'Cosine Wave',
|
||||
color: '#2ca02c'
|
||||
},
|
||||
{
|
||||
values: sin2,
|
||||
key: 'Another sine wave',
|
||||
color: '#7777ff',
|
||||
area: true //area - set to true if you want this line to turn into a filled area chart.
|
||||
}
|
||||
];
|
||||
},
|
||||
render: function(){return(
|
||||
ce('div', {id: 'chart'}, ce('svg', {style: {'height': '500px'}}))
|
||||
)},
|
||||
componentDidMount: function(){
|
||||
var _this = this;
|
||||
|
||||
nv.addGraph(function() {
|
||||
var chart = nv.models.lineChart().useInteractiveGuideline(true);
|
||||
|
||||
chart.xAxis.axisLabel('Time (ms)').tickFormat(d3.format(',r'));
|
||||
|
||||
chart.yAxis.axisLabel('Voltage (v)').tickFormat(d3.format('.02f'));
|
||||
|
||||
d3.select('#chart svg')
|
||||
.datum(_this.sinAndCos())
|
||||
.transition().duration(500)
|
||||
.call(chart);
|
||||
|
||||
nv.utils.windowResize(chart.update);
|
||||
return chart;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var ContentModule = React.createClass({
|
||||
loadScript: function(url, fnLoad, fnError) {
|
||||
const script = document.createElement("script");
|
||||
@@ -75,6 +20,7 @@ var ContentModule = React.createClass({
|
||||
componentWillMount: function(){
|
||||
var _this = this;
|
||||
|
||||
this.loadScript("/mcsmanager/components.js");
|
||||
this.loadScript(
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js",
|
||||
function(){
|
||||
@@ -104,4 +50,4 @@ var ContentModule = React.createClass({
|
||||
)
|
||||
)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user