Skip to content

Commit 0ffe4c2

Browse files
Add absolute circle size (#65)
Add absolute circle size - Add option for absolute circle size, rather than using a dynamic range (disabled by default and as fallback) - Use prefactor for absolute values, defaulting to 1.0 - Absolute circles are still being clamped by min/max settings
1 parent e0e00b0 commit 0ffe4c2

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

src/partials/editor.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,16 @@ <h5>Circle parameters</h5>
408408
<input type="text" class="input-small gf-form-input width-10" ng-model="ctrl.panel.circleMaxSize" ng-change="ctrl.render()"
409409
placeholder="10" ng-model-onblur />
410410
</div>
411+
<div class="gf-form">
412+
<label class="gf-form-label width-10">Absolute size</label>
413+
<gf-form-switch checked="ctrl.panel.circleSizeAbsoluteEnabled" on-change="ctrl.render()">
414+
</gf-form-switch>
415+
</div>
416+
<div class="gf-form" ng-show="ctrl.panel.circleSizeAbsoluteEnabled">
417+
<label class="gf-form-label width-10">Size factor</label>
418+
<input type="text" class="input-small gf-form-input width-10" ng-model="ctrl.panel.circleSizeAbsoluteFactor" ng-change="ctrl.render()"
419+
placeholder="1.0" ng-model-onblur />
420+
</div>
411421
<div class="gf-form">
412422
<label class="gf-form-label width-10">Enable strokes</label>
413423
<gf-form-switch checked="ctrl.panel.circleOptions.strokeEnabled" on-change="ctrl.redrawCircles()">

src/worldmap.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ describe('Worldmap', () => {
6161
.build();
6262
ctrl.panel.circleMinSize = '2';
6363
ctrl.panel.circleMaxSize = '10';
64+
// Ensure factor is ignored
65+
ctrl.panel.circleSizeAbsoluteFactor = '3';
6466
worldMap.drawCircles();
6567
});
6668

@@ -82,6 +84,37 @@ describe('Worldmap', () => {
8284
});
8385
});
8486

87+
describe('when the data has three points and absolute mode is enabled', () => {
88+
beforeEach(() => {
89+
ctrl.data = new DataBuilder()
90+
.withCountryAndValue('SE', 4)
91+
.withCountryAndValue('IE', 1)
92+
.withCountryAndValue('US', 8)
93+
.withDataRange(0, 8, 8)
94+
.build();
95+
ctrl.panel.circleMinSize = '3';
96+
ctrl.panel.circleMaxSize = '10';
97+
ctrl.panel.circleSizeAbsoluteEnabled = true;
98+
ctrl.panel.circleSizeAbsoluteFactor = '1.5';
99+
worldMap.drawCircles();
100+
});
101+
102+
it('should three four circles on the map', () => {
103+
expect(worldMap.circles.length).toBe(3);
104+
});
105+
106+
it('should create a circle with the specified size times the factor', () => {
107+
expect(worldMap.circles[0].options.radius).toBe(6);
108+
});
109+
110+
it('should create a a circle with the minimum size if the factored absolute is too small', () => {
111+
expect(worldMap.circles[1].options.radius).toBe(3);
112+
});
113+
it('should create a a circle with the maximum size if the factored absolute is too small', () => {
114+
expect(worldMap.circles[2].options.radius).toBe(10);
115+
});
116+
});
117+
85118
describe('when units option is set', () => {
86119
beforeEach(() => {
87120
ctrl.data = new DataBuilder()

src/worldmap.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,13 @@ export default class WorldMap {
293293
}
294294

295295
calcCircleSize(dataPointValue) {
296-
const circleMinSize = parseInt(this.ctrl.settings.circleMinSize, 10) || 1;
297-
const circleMaxSize = parseInt(this.ctrl.settings.circleMaxSize, 10) || 10;
296+
const circleMinSize = parseFloat(this.ctrl.settings.circleMinSize) || 1;
297+
const circleMaxSize = parseFloat(this.ctrl.settings.circleMaxSize) || 10;
298+
299+
if (this.ctrl.settings.circleSizeAbsoluteEnabled) {
300+
const size = dataPointValue * (parseFloat(this.ctrl.settings.circleSizeAbsoluteFactor) || 1.0);
301+
return Math.min(circleMaxSize, Math.max(circleMinSize, size));
302+
}
298303

299304
// If measurement value equals zero, use minimum circle size.
300305
if (dataPointValue === 0) {

src/worldmap_ctrl.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const panelDefaults = {
2424
valueName: 'total',
2525
circleMinSize: 2,
2626
circleMaxSize: 30,
27+
circleSizeAbsoluteEnabled: false,
28+
circleSizeAbsoluteFactor: 1.0,
2729
circleOptions: {
2830
strokeEnabled: true,
2931
strokeWeight: 3,

0 commit comments

Comments
 (0)