XR01 recJs Example: Example signals for charts
Outline
This recJs script creates some example signals that can be used for displaying Nebula and Birt charts.
Platforms |
|
|||
Requirements |
|
|||
Parameters: |
|
|||
Content of example record files |
|
Output
Usage
- Copy the script code onto a file resource with "recJs" ending or use the impulse record examples.
- Open the impulse viewer with the file resource (e.g. double-click the file in the eclipse explorer).
R003 recJs Reader 10 Signal Script Script Examples impulse JDK Open JavaDoc
Script
The script create a struct, an integer and a float array signal. Additionally a plot template is added.
//-recjs (keep this line) // generator : Record generator (de.toem.impulse.samples.ISingleDomainRecordGenerator) // file : File object of the executed recJs file (java.io.File) // p0..p9 : Parameters from the reader configuration (java.lang.String) // progress : Progress control (de.toem.impulse.cells.ports.IPortProgress) // console : Console output (de.toem.impulse.scripting.IScriptConsole) // Init the record generator.initRecord("Example Record",TimeBase.ns); // We forget the input and create a record with scopes and some signals var signals = generator.addScope(null, "External Signals"); var intsig = generator.addSignal(signals, "Sin", "", ProcessType.Discrete, SignalType.Integer, SignalDescriptor.DEFAULT); var struct = generator.addSignal(signals, "Birt", "", ProcessType.Discrete, SignalType.Struct, SignalDescriptor.DEFAULT); var floatArray = generator.addSignal(signals, "XY", "", ProcessType.Discrete, SignalType.FloatArray, new SignalDescriptor(SignalDescriptor.CONTENT_DEFAULT,2,ISample.FLOAT_WIDTH_64,ISample.FORMAT_DEFAULT)); // We start at 0 ns var t = 0; // 0 ns generator.open(t); // int signal var writer /*:IIntegerSamplesWriter:*/ = generator.getWriter(intsig); writer.writeInt(t, false, 0); t=14000; writer.writeInt(t, false, 0); for (; t < 94000; t ++) { // write time as integer writer.writeInt(t, false, (100 * Math.sin(t/1000.0))); } writer.writeInt(t, false, 0); writer.writeInt(100000, false, 0); // struct signal writer /*:IStructSamplesWriter:*/ = generator.getWriter(struct); var members/*:[Lde.toem.impulse.values.StructMember;:*/ = writer.createMembers(7); writer.createMember(members,0,"A", ISample.STRUCT_TYPE_INTEGER,null,-1); writer.createMember(members,1,"B", ISample.STRUCT_TYPE_INTEGER,null,-1); writer.createMember(members,2,"C", ISample.STRUCT_TYPE_INTEGER,null,-1); writer.createMember(members,3,"D", ISample.STRUCT_TYPE_INTEGER,null,-1); writer.createMember(members,4,"E", ISample.STRUCT_TYPE_INTEGER,null,-1); writer.createMember(members,5,"F", ISample.STRUCT_TYPE_INTEGER,null,-1); writer.createMember(members,6,"Label", ISample.STRUCT_TYPE_TEXT,"LABEL",-1); members[0].setIntValue(1); members[1].setIntValue(8); members[2].setIntValue(5); members[3].setIntValue(12); members[4].setIntValue(12); members[5].setIntValue(12); members[6].setStringValue("Series 1"); writer.write(0,false,members); members[0].setIntValue(14); members[1].setIntValue(15); members[2].setIntValue(16); members[3].setIntValue(17); members[4].setIntValue(18); members[5].setIntValue(19); members[6].setStringValue("Series 2"); writer.write(1,false,members); members[0].setIntValue(34); members[1].setIntValue(35); members[2].setIntValue(46); members[3].setIntValue(27); members[4].setIntValue(38); members[5].setIntValue(29); members[6].setStringValue("Series 3"); writer.write(1,false,members); // xy signal writer /*:IFloatSamplesWriter:*/ = generator.getWriter(floatArray); writer.setMember( 0, "x", null, ISample.FORMAT_DEFAULT); writer.setMember( 1, "y", null, ISample.FORMAT_DEFAULT); var DoubleArray = Java.type("double[]"); var array = new DoubleArray(2); for (t=0; t < 100000; t += 10) { array[0] = Math.sin((t + 100) / 3000.0) * 10.0; array[1] = Math.cos((t + 100) / 3000.0) * 10.0; writer.writeDoubleArray(t, false, array); } // And close finally generator.close(100000); // add a configuration var config /*:ViewConfiguration:*/ = generator.addViewConfiguration( "Demo", ""); var samples /*:PlotConfiguration:*/ = generator.addPlotConfiguration( config, intsig); samples.style = PlotConfiguration.STYLE_LINE; samples = generator.addPlotConfiguration( config, struct); samples.style = PlotConfiguration.STYLE_CHART; samples.preferedHeight = true; samples.preferedHeightValue = 100; samples.styleDescriptor = new Link("Pie Chart (Birt)"); samples.preferedHeight = true; samples.preferedHeightValue = 250; samples = generator.addPlotConfiguration( config, floatArray); samples.style = PlotConfiguration.STYLE_CHART; samples.styleDescriptor = new Link("Xy Chart (Nebula)"); samples.preferedHeight = true; samples.preferedHeightValue = 200;