-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify MatrixVis
API
#1702
Simplify MatrixVis
API
#1702
Conversation
a1e4e8b
to
cb20c1b
Compare
dims.length === 1 | ||
? (row: number) => formatter(dataArray.get(row), 0) | ||
: (row: number, col: number) => formatter(dataArray.get(row, col), col); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic was not needed since dataArray.get(row, 0)
works fine with 1D arrays.
function assertPrimitiveValue<D extends Dataset>( | ||
dataset: D, | ||
function assertPrimitiveValue<T extends DType>( | ||
type: T, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated refactoring here: I'm just opening the door to asserting compound types more strictly in the future.
} else if (isCompoundType(type)) { | ||
assertArray(value); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this assertion to at least check that compound values are arrays.
if (hasScalarShape(dataset)) { | ||
assertPrimitiveValue(type, value); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swapping the logic because type
was narrowed down to never
in the else
branch due to the fact that ScalarShape
⊂ ArrayShape
([]
⊂ number[]
). I have a note somewhere to try to change ArrayShape
to [number, ...number[]]
, though I have to check if it's worth the effort.
8746fe1
to
cb20c1b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not too sure.
I find that it should not be the responsability of the MatrixVis
consumer to deal with the data access to the dataArray
. Notably, it would be easy for an unwary user to invert row
and col
.
About the formatter
type, I guess you tried something like
interface Props<T extends PrintableType> {
dataArray: NdArray<ArrayValue<T>>
formatter: (value: Primitive<T>, colIndex: number) => string;
...
}
and it didn't work ?
Yeah, doesn't work inside the I don't know, I feel like trying to hide away I know removing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, I feel like trying to hide away dataArray.get() is unnecessary. It also forces consumers to create the dataArray (or a view of it) in a certain way (cols, rows) ... but this restriction is artificial. With the new cellFormatter, the question for the consumer simply becomes: "what text do I want to display in cell (col, row)". You don't even need an ndarray to answer this..
Yeah good point. Let's try it.
I've been looking into making the types of
getFormatter
inMappedMatrixVis
more strict. I'd like to ensure that, for instance, when we have a numeric array:(val: number) => string
(instead of(val: number | string | ...) => string
);Unfortunately, I keep hitting roadblocks. While investigating, I found an interesting refactoring of
MatrixVis
that simplifies a bunch of things and may remove at least one of those roadblocks...The gist is that I remove the
dataArray
prop and let the consumer retrieve the value using the row and column index. This means we no longer have to worry about the formatterval
parameter matching the type of the values in the array, whether it be when usingMatrixVis
or typing its props. We still have to worry about it inMappedMatrixVis
, though, but hopefully I'll find a way to fix that next.Breaking changes: replace props
dataArray
andformatter
with propsdims
andcellFormatter
. Typical refactoring: