validate returns error message if column indexes are invalid, else nil it also sets column indexes to 0 so nothing crashes.
()
| 73 | // validate returns error message if column indexes are invalid, else nil |
| 74 | // it also sets column indexes to 0 so nothing crashes. |
| 75 | func (txy *tableXY) validate() error { |
| 76 | if txy.table == nil { |
| 77 | return errors.New("eplot.TableXY table is nil") |
| 78 | } |
| 79 | nc := txy.table.Table.NumColumns() |
| 80 | if txy.xColumn >= nc || txy.xColumn < 0 { |
| 81 | txy.xColumn = 0 |
| 82 | return errors.New("eplot.TableXY XColumn index invalid -- reset to 0") |
| 83 | } |
| 84 | if txy.yColumn >= nc || txy.yColumn < 0 { |
| 85 | txy.yColumn = 0 |
| 86 | return errors.New("eplot.TableXY YColumn index invalid -- reset to 0") |
| 87 | } |
| 88 | xc := txy.table.Table.Columns[txy.xColumn] |
| 89 | yc := txy.table.Table.Columns[txy.yColumn] |
| 90 | if xc.NumDims() > 1 { |
| 91 | _, txy.xRowSize = xc.RowCellSize() |
| 92 | // note: index already validated |
| 93 | } |
| 94 | if yc.NumDims() > 1 { |
| 95 | _, txy.yRowSize = yc.RowCellSize() |
| 96 | if txy.yIndex >= txy.yRowSize || txy.yIndex < 0 { |
| 97 | txy.yIndex = 0 |
| 98 | return errors.New("eplot.TableXY Y TensorIndex invalid -- reset to 0") |
| 99 | } |
| 100 | } |
| 101 | txy.filterValues() |
| 102 | return nil |
| 103 | } |
| 104 | |
| 105 | // filterValues removes items with NaN values, and out of Y range |
| 106 | func (txy *tableXY) filterValues() { |
no test coverage detected