* Determine the source definitions from data standalone dimensions definitions * are not specified.
(
data: OptionSourceData,
sourceFormat: SourceFormat,
seriesLayoutBy: SeriesLayoutBy,
sourceHeader: OptionSourceHeader,
// standalone raw dimensions definition, like:
// {
// dimensions: ['aa', 'bb', { name: 'cc', type: 'time' }]
// }
// in `dataset` or `series`
dimensionsDefine: DimensionDefinitionLoose[]
)
| 298 | * are not specified. |
| 299 | */ |
| 300 | function determineSourceDimensions( |
| 301 | data: OptionSourceData, |
| 302 | sourceFormat: SourceFormat, |
| 303 | seriesLayoutBy: SeriesLayoutBy, |
| 304 | sourceHeader: OptionSourceHeader, |
| 305 | // standalone raw dimensions definition, like: |
| 306 | // { |
| 307 | // dimensions: ['aa', 'bb', { name: 'cc', type: 'time' }] |
| 308 | // } |
| 309 | // in `dataset` or `series` |
| 310 | dimensionsDefine: DimensionDefinitionLoose[] |
| 311 | ): { |
| 312 | // If the input `dimensionsDefine` is specified, return it. |
| 313 | // Else determine dimensions from the input `data`. |
| 314 | // If not determined, `dimensionsDefine` will be null/undefined. |
| 315 | dimensionsDefine: Source['dimensionsDefine']; |
| 316 | startIndex: Source['startIndex']; |
| 317 | dimensionsDetectedCount: Source['dimensionsDetectedCount']; |
| 318 | } { |
| 319 | let dimensionsDetectedCount; |
| 320 | let startIndex: number; |
| 321 | |
| 322 | // PENDING: Could data be null/undefined here? |
| 323 | // currently, if `dataset.source` not specified, error thrown. |
| 324 | // if `series.data` not specified, nothing rendered without error thrown. |
| 325 | // Should test these cases. |
| 326 | if (!data) { |
| 327 | return { |
| 328 | dimensionsDefine: normalizeDimensionsOption(dimensionsDefine), |
| 329 | startIndex, |
| 330 | dimensionsDetectedCount |
| 331 | }; |
| 332 | } |
| 333 | |
| 334 | if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) { |
| 335 | const dataArrayRows = data as OptionSourceDataArrayRows; |
| 336 | // Rule: Most of the first line are string: it is header. |
| 337 | // Caution: consider a line with 5 string and 1 number, |
| 338 | // it still can not be sure it is a head, because the |
| 339 | // 5 string may be 5 values of category columns. |
| 340 | if (sourceHeader === 'auto' || sourceHeader == null) { |
| 341 | arrayRowsTravelFirst(function (val) { |
| 342 | // '-' is regarded as null/undefined. |
| 343 | if (val != null && val !== '-') { |
| 344 | if (isString(val)) { |
| 345 | startIndex == null && (startIndex = 1); |
| 346 | } |
| 347 | else { |
| 348 | startIndex = 0; |
| 349 | } |
| 350 | } |
| 351 | // 10 is an experience number, avoid long loop. |
| 352 | }, seriesLayoutBy, dataArrayRows, 10); |
| 353 | } |
| 354 | else { |
| 355 | startIndex = isNumber(sourceHeader) ? sourceHeader : sourceHeader ? 1 : 0; |
| 356 | } |
| 357 |
no test coverage detected
searching dependent graphs…