-
Notifications
You must be signed in to change notification settings - Fork 185
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: enable or disable ruler #765
Changes from all commits
92397a8
37a6574
c3cc44a
8b717ab
80725c4
e9c5602
5627d39
65a83e0
f1d3f56
34adc72
9ee4f1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,28 @@ export class Ruler extends Component { | |
"y", | ||
"enabled" | ||
); | ||
// flag for checking whether ruler event listener is added or not | ||
isEventListenerAdded = false; | ||
|
||
render() { | ||
const isRulerEnabled = Tools.getProperty( | ||
this.model.getOptions(), | ||
"ruler", | ||
"enabled" | ||
); | ||
|
||
this.drawBackdrop(); | ||
this.addBackdropEventListeners(); | ||
|
||
if (isRulerEnabled && !this.isEventListenerAdded) { | ||
this.addBackdropEventListeners(); | ||
} else if (!isRulerEnabled && this.isEventListenerAdded) { | ||
this.removeBackdropEventListeners(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so we remove & add event listeners every time? This doesn't sound healthy, there should be a better way to only remove or add when we need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since d3 doesn't have an api for checking whether a specific eventListener is already existed or not. Removing and then adding event listeners when needed is what we can do for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again this is the same situation as the other PR, we just need a boolean here to keep track of event listeners There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A flag, |
||
} | ||
|
||
removeBackdropEventListeners() { | ||
this.isEventListenerAdded = false; | ||
this.backdrop.on("mousemove mouseover mouseout", null); | ||
} | ||
|
||
formatTooltipData(tooltipData) { | ||
|
@@ -203,6 +221,7 @@ export class Ruler extends Component { | |
* Adds the listener on the X grid to trigger multiple point tooltips along the x axis. | ||
*/ | ||
addBackdropEventListeners() { | ||
this.isEventListenerAdded = true; | ||
const self = this; | ||
const displayData = this.model.getDisplayData(); | ||
|
||
|
@@ -247,15 +266,5 @@ export class Ruler extends Component { | |
? "rect.chart-grid-backdrop.stroked" | ||
: "rect.chart-grid-backdrop" | ||
); | ||
|
||
this.backdrop | ||
.merge(backdropRect) | ||
.attr("x", xScaleStart) | ||
.attr("y", yScaleStart) | ||
.attr("width", xScaleEnd - xScaleStart) | ||
.attr("height", yScaleEnd - yScaleStart) | ||
.lower(); | ||
|
||
backdropRect.attr("width", "100%").attr("height", "100%"); | ||
} | ||
} |
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.
it seems like
drawBackdrop
is repeated in ruler & grid. Would ruler fully function without it?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.
ruler needs backdrop since the event listener is applied on backdrop.
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 get that ruler is dependant on backdrop, however I'm wondering if these lines are needed inside
ruler.ts
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.
Actually, I am not sure about it. These lines of code have existed even before I added the ruler option.
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.
Yes I'm just asking whether removing them on your end still makes everything work?
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.
As what I can see do far, removing code within line 253 to line 261 won't break any thing on my end.
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.
Codes within line 253 to line 261 have already been removed.