-
Notifications
You must be signed in to change notification settings - Fork 379
Point: change event tests to inRange tests #649
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e0b6754
Point: change event tests to inRange tests
stockiNail 4e75284
apply review
stockiNail 365ec08
changes location of point 3
stockiNail 09e7a24
apply review 2
stockiNail a11cef4
reverts the context removing
stockiNail 1a36fab
removes context from radius 0
stockiNail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,92 +1,78 @@ | ||
| describe('Point annotation', function() { | ||
| describe('auto', jasmine.fixtures('point')); | ||
|
|
||
| const eventIn = function(xScale, yScale, element) { | ||
| const options = element.options; | ||
| const adjust = options.borderWidth / 2 - 1; | ||
| return {x: element.x, y: element.y - element.height / 2 - adjust}; | ||
| }; | ||
| const eventOut = function(xScale, yScale, element) { | ||
| const options = element.options; | ||
| const adjust = options.borderWidth / 2 + 1; | ||
| return {x: element.x, y: element.y - element.height / 2 - adjust}; | ||
| }; | ||
| describe('inRange', function() { | ||
| const annotation1 = { | ||
| type: 'point', | ||
| xValue: 7, | ||
| yValue: 7, | ||
| radius: 30 | ||
| }; | ||
| const annotation2 = { | ||
| type: 'point', | ||
| xValue: 3, | ||
| yValue: 3, | ||
| radius: 5 | ||
| }; | ||
| const annotation3 = { | ||
| type: 'point', | ||
| xValue: 3, | ||
| yValue: 3, | ||
| radius: 0 | ||
| }; | ||
|
|
||
| window.testEvents({ | ||
| type: 'point', | ||
| id: 'test', | ||
| xValue: 5, | ||
| yValue: 5, | ||
| radius: 30, | ||
| borderWidth: 12 | ||
| }, eventIn, eventOut); | ||
| const chart = window.scatter10x10({test1: annotation1, test2: annotation2, test3: annotation3}); | ||
stockiNail marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const elems = window.getAnnotationElements(chart).filter(el => el.options.radius > 0); | ||
| const elemsNoRad = window.getAnnotationElements(chart).filter(el => el.options.radius === 0); | ||
|
|
||
| describe('events, removing borderWidth by callback, ', function() { | ||
| const chartConfig = { | ||
| type: 'scatter', | ||
| options: { | ||
| animation: false, | ||
| scales: { | ||
| x: { | ||
| display: false, | ||
| min: 0, | ||
| max: 10 | ||
| }, | ||
| y: { | ||
| display: false, | ||
| min: 0, | ||
| max: 10 | ||
| } | ||
| }, | ||
| plugins: { | ||
| legend: false, | ||
| annotation: { | ||
| annotations: { | ||
| point: { | ||
| type: 'point', | ||
| xValue: 5, | ||
| yValue: 5, | ||
| radius: 20, | ||
| borderWidth: 10 | ||
| } | ||
| } | ||
| elems.forEach(function(element) { | ||
| it(`should return true inside element '${element.options.id}'`, function() { | ||
| for (const borderWidth of [0, 10]) { | ||
| const halfBorder = borderWidth / 2; | ||
| element.options.borderWidth = borderWidth; | ||
| const radius = element.height / 2; | ||
| for (const angle of [0, 45, 90, 135, 180, 225, 270, 315]) { | ||
| const rad = angle * (Math.PI / 180); | ||
| const {x, y} = { | ||
| x: element.x + Math.cos(rad) * (radius + halfBorder - 1), | ||
| y: element.y + Math.sin(rad) * (radius + halfBorder - 1) | ||
| }; | ||
| expect(element.inRange(x, y)).withContext(`in, angle: ${angle}, radius: ${radius}, borderWidth: ${borderWidth}, {x: ${x.toFixed(1)}, y: ${y.toFixed(1)}}`).toEqual(true); | ||
| } | ||
| } | ||
| }, | ||
| }; | ||
|
|
||
| const pointOpts = chartConfig.options.plugins.annotation.annotations.point; | ||
|
|
||
| it('should detect click event', function(done) { | ||
| const clickSpy = jasmine.createSpy('click'); | ||
| }); | ||
|
|
||
| pointOpts.click = function(ctx) { | ||
| if (ctx.element.options.borderWidth) { | ||
| delete ctx.element.options.borderWidth; | ||
| ctx.chart.draw(); | ||
| } else { | ||
| ctx.element.options.click = clickSpy; | ||
| it(`should return false outside element '${element.options.id}'`, function() { | ||
| for (const borderWidth of [0, 10]) { | ||
| const halfBorder = borderWidth / 2; | ||
| element.options.borderWidth = borderWidth; | ||
| const radius = element.height / 2; | ||
| for (const angle of [0, 45, 90, 135, 180, 225, 270, 315]) { | ||
| const rad = angle * (Math.PI / 180); | ||
| const {x, y} = { | ||
| x: element.x + Math.cos(rad) * (radius + halfBorder + 1), | ||
| y: element.y + Math.sin(rad) * (radius + halfBorder + 1) | ||
| }; | ||
| expect(element.inRange(x, y)).withContext(`in, angle: ${angle}, radius: ${radius}, borderWidth: ${borderWidth}, {x: ${x.toFixed(1)}, y: ${y.toFixed(1)}}`).toEqual(false); | ||
stockiNail marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| }; | ||
|
|
||
| const chart = window.acquireChart(chartConfig); | ||
| const xScale = chart.scales.x; | ||
| const yScale = chart.scales.y; | ||
| const eventPoint = {x: xScale.getPixelForValue(5), y: yScale.getPixelForValue(5)}; | ||
|
|
||
| window.afterEvent(chart, 'click', function() { | ||
| expect(clickSpy.calls.count()).toBe(0); | ||
|
|
||
| window.afterEvent(chart, 'click', function() { | ||
| expect(clickSpy.calls.count()).toBe(1); | ||
| delete pointOpts.click; | ||
| done(); | ||
| }); | ||
| window.triggerMouseEvent(chart, 'click', eventPoint); | ||
| }); | ||
| window.triggerMouseEvent(chart, 'click', eventPoint); | ||
| }); | ||
|
|
||
| elemsNoRad.forEach(function(element) { | ||
| it(`should return false radius is 0 element '${element.options.id}'`, function() { | ||
| element.width = 0; | ||
stockiNail marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for (const borderWidth of [0, 10]) { | ||
| const halfBorder = borderWidth / 2; | ||
| element.options.borderWidth = borderWidth; | ||
| for (const x of [element.x - halfBorder, element.x + halfBorder]) { | ||
| expect(element.inRange(x, element.y)).withContext(`in, borderWidth: ${borderWidth}, {x: ${x.toFixed(1)}, y: ${element.y.toFixed(1)}}`).toEqual(false); | ||
| } | ||
| for (const y of [element.y - halfBorder, element.y + halfBorder]) { | ||
| expect(element.inRange(element.x, y)).withContext(`in, borderWidth: ${borderWidth}, {x: ${element.x.toFixed(1)}, y: ${y.toFixed(1)}}`).toEqual(false); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.