MCPcopy Create free account
hub / github.com/Kitware/VTK / WriteTable

Method WriteTable

IO/Core/vtkJavaScriptDataWriter.cxx:122–188  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

120
121//------------------------------------------------------------------------------
122void vtkJavaScriptDataWriter::WriteTable(vtkTable* table, ostream* stream_ptr)
123{
124 if (stream_ptr == nullptr)
125 {
126 if (this->FileName && this->OpenFile())
127 {
128 stream_ptr = this->OutputFile;
129 }
130 }
131
132 if (stream_ptr != nullptr)
133 {
134 vtkIdType numRows = table->GetNumberOfRows();
135 vtkIdType numCols = table->GetNumberOfColumns();
136 vtkDataSetAttributes* dsa = table->GetRowData();
137
138 std::string rowHeader = "[";
139 std::string rowFooter = "],";
140 if (this->IncludeFieldNames)
141 {
142 rowHeader = "{";
143 rowFooter = "},";
144 }
145
146 // Header stuff
147 if (this->VariableName)
148 {
149 (*stream_ptr) << "var " << this->VariableName << " = [\n";
150 }
151 else
152 {
153 (*stream_ptr) << "[";
154 }
155
156 for (vtkIdType r = 0; r < numRows; ++r)
157 {
158 // row header
159 (*stream_ptr) << rowHeader;
160
161 // Now for each column put out in the form
162 // colname1: data1, colname2: data2, etc
163 for (int c = 0; c < numCols; ++c)
164 {
165 if (this->IncludeFieldNames)
166 {
167 (*stream_ptr) << dsa->GetAbstractArray(c)->GetName() << ":";
168 }
169
170 // If the array is a string array put "" around it
171 if (vtkArrayDownCast<vtkStringArray>(dsa->GetAbstractArray(c)))
172 {
173 (*stream_ptr) << "\"" << table->GetValue(r, c).ToString() << "\",";
174 }
175 else
176 {
177 (*stream_ptr) << table->GetValue(r, c).ToString() << ",";
178 }
179 }

Callers 1

WriteDataMethod · 0.95

Calls 8

OpenFileMethod · 0.95
GetRowDataMethod · 0.80
GetAbstractArrayMethod · 0.80
GetNumberOfRowsMethod · 0.45
GetNumberOfColumnsMethod · 0.45
GetNameMethod · 0.45
ToStringMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected