Skip to content
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

feat(core): axisMeasure #259

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

razsultana
Copy link

@razsultana razsultana commented May 12, 2024

Implemented an axisMeasure lazy datasource which can be used to create a visual clue to the level of zoom, publishing the startPos, endPos, centerPos, measureDomainSize, measurePixelSize and measureLabel fields at each scale domain change.
Its behavior can be changed by several parameters: minMeasureSize, hideMeasureThreshold, multiplierValue and alignMeasure.
The parameters and fields usage is shown in two examples in packages/core/example/axes and they are also documented in the lazy.md part of the documentation.
The range of measureValues and measureLabels is determined by querying genome.totalSize, so this feature works only on genomeAxes (to make it more general, the scale #zoomExtent might need to be made available for simple Axes).

@razsultana razsultana marked this pull request as ready for review May 12, 2024 11:40
@razsultana razsultana changed the title Feature_axisMeasure feat: axisMeasure May 12, 2024
@razsultana razsultana changed the title feat: axisMeasure feat(core): axisMeasure May 12, 2024
break;
case "center":
// @ts-ignore
coordCenter = scale.invert(0.5);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for line 118

@tuner
Copy link
Member

tuner commented May 12, 2024

Awesome! Seems to work and looks pretty good! I added some comments.

The range of measureValues and measureLabels is determined by querying genome.totalSize, so this feature works only on genomeAxes (to make it more general, the scale #zoomExtent might need to be made available for simple Axes).

Instead of precalculating stuff, you could calculate the rule length on the fly. E.g., take Math.floor(Math.log10(domainSpan)) with some paddings, etc. or something like that. This way this.measureValues.find((value) => value > minValueSize); would become unnecessary. Not critical though, as it can be improved later on without breaking any interfaces or schemas.

*
* __Default value:__ `1`
*/
multiplierValue?: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I'm not sure about this. What if someone would like to have 1, 5, 10, 50, 100, 50, etc? No need to implement it now, but how would multiplierValue work with that?

I would be careful when adding nice-to-have options, as they may become a nuisance later on.

*/
export default class AxisMeasureSource extends SingleAxisLazySource {
/** @type {number} */
startPos = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be class-private variables (i.e., start with #).

On the other hand, you could have just a single variable that stores the object that you might publish when the domain changes. However, when propagating new data objects, it's best to always create a new object, not mutate an existing one.

/** @type {number} */
centerPos = 0;
/** @type {string} */
measureLabel = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local to onDomainChanged(). Shouldn't be here.

/** @type {string} */
measureLabel = "";
/** @type {number} */
measureDomainSize = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here and in the following few variables.

this.publishData([
[
{
startPos: startPos,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the property and variable names are the same, you can make it more succinct:

{
  startPos,
  endPos,
  centerPos,
  ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants