Skip to content

Commit

Permalink
check mouseOver
Browse files Browse the repository at this point in the history
  • Loading branch information
katestange committed Apr 15, 2024
1 parent 12703e5 commit 395982c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/visualizers/Histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,25 @@ class FactorHistogramVisualizer extends VisualizerDefault {
let binTextSize = 0

// Checks to see whether the mouse is in the bin drawn on the screen
let inBin = false
const mouseX = this.sketch.mouseX
const mouseY = this.sketch.mouseY
const binIndex = Math.floor((mouseX - largeOffsetNumber) / binWidth)
const xAxisHeight = largeOffsetScalar * this.sketch.height
if (
mouseY
// hard to mouseover tiny bars, so minimum height to catch mouse
> Math.min(
largeOffsetScalar * this.sketch.height
- height * this.binFactorArray[binIndex],
xAxisHeight - 10
)
// and above axis
&& mouseY < largeOffsetScalar * this.sketch.height
) {
inBin = true
let inBin = false
if (this.mouseOver) {
if (
mouseY
// hard to mouseover tiny bars; min height to catch mouse
> Math.min(
largeOffsetScalar * this.sketch.height
- height * this.binFactorArray[binIndex],
xAxisHeight - 10
)
// and above axis
&& mouseY < largeOffsetScalar * this.sketch.height
) {
inBin = true
}
}

// Draw the axes
Expand All @@ -231,7 +233,7 @@ class FactorHistogramVisualizer extends VisualizerDefault {
)

for (let i = 0; i < 30; i++) {
if (inBin && i == binIndex) {
if (this.mouseOver && inBin && i == binIndex) {
this.sketch.fill(200, 200, 200)
} else {
this.sketch.fill('white')
Expand Down Expand Up @@ -325,7 +327,7 @@ class FactorHistogramVisualizer extends VisualizerDefault {
}

// Draws the box and the text inside the box
if (inBin === true && this.mouseOver === true) {
if (this.mouseOver === true && inBin === true) {
const boxWidth = this.sketch.width * 0.15
const textVerticalSpacing = this.sketch.textAscent()
const boxHeight = textVerticalSpacing * 2.3
Expand Down

0 comments on commit 395982c

Please sign in to comment.