Skip to content

Commit

Permalink
Merge pull request #29 from geoblink/feature/CORE-8000-GeoScatterPlot…
Browse files Browse the repository at this point in the history
…-dot-coordinates

Feature/core 8000 geo scatter plot dot coordinates
  • Loading branch information
Navas23 authored Feb 26, 2020
2 parents 55f5ad0 + a8c1d25 commit 2a5a6ce
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 29.5.1

New:

- `GeoChartScatterPlot` returns coordinates on click event

## 29.4.3

Changed:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@geoblink/design-system",
"version": "29.4.3",
"version": "29.5.1",
"description": "Geoblink Design System for Vue.js",
"author": "Geoblink <[email protected]>",
"main": "dist/system.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function renderSingleGroup (group, d3TipInstance, singleGroupOptions, globalOpti

if (d.isClicked) {
unclickedStyle(d3.select(this), d)
return singleGroupOptions.onDotClick(null, null)
return singleGroupOptions.onDotClick(null, null, null)
}

const previouslyClickedDot = getPreviouslyClickedDot()
Expand All @@ -255,8 +255,10 @@ function renderSingleGroup (group, d3TipInstance, singleGroupOptions, globalOpti
unclickedStyle(dotToUnclick, previouslyClickedDot)
}

clickedStyle(d3.select(this), d)
return singleGroupOptions.onDotClick(d, d.index)
const clickedDot = d3.select(this)
const dotCoordinates = [parseFloat(clickedDot.attr('cx')), parseFloat(clickedDot.attr('cy'))]
clickedStyle(clickedDot, d)
return singleGroupOptions.onDotClick(d, d.index, dotCoordinates)
}

function clickedStyle (element, d) {
Expand Down
18 changes: 18 additions & 0 deletions test/unit/specs/elements/GeoChart/GeoChartScatterPlot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const axisDimensions = {
}
}

const mockHandleClick = jest.fn()

describe('GeoChartScatterPlot', function () {
const stubGetBBox = stubGetBBoxFactory()
const stubGetScreenCTM = stubGetScreenCTMFactory()
Expand Down Expand Up @@ -96,6 +98,7 @@ describe('GeoChartScatterPlot', function () {
idHorizontalAxis: numericalAxisConfig.id,
mainDimension: GeoChart.constants.DIMENSIONS.DIMENSIONS_2D.horizontal,
data: scatterPlotData,
onDotClick: mockHandleClick,
getRadius: function () { return 4 },
getFillColor: function (d, i) { return i < (mockDomain1 / 2) ? 'orange' : 'green' },
tooltip: {
Expand Down Expand Up @@ -164,5 +167,20 @@ describe('GeoChartScatterPlot', function () {

wrapper.destroy()
})

it('Should return dot coordinates (array) on click', () => {
const wrapper = mount(GeoChart, {
propsData: {
config: scatterPlotConfig
}
})

flushD3Transitions()

wrapper.find('.geo-chart .geo-chart-scatter-plot-group--0 .geo-chart-scatter-plot__dot').trigger('click')
expect(mockHandleClick.mock.calls.length).toBe(1)
expect(Array.isArray(mockHandleClick.mock.calls[0][2])).toBe(true)
wrapper.destroy()
})
})
})

1 comment on commit 2a5a6ce

@vercel
Copy link

@vercel vercel bot commented on 2a5a6ce Feb 26, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.