Skip to content
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

Extended label config to support styles by key #409

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
jquery.jvectormap.min.js
node_modules
dist
51 changes: 51 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var gulp = require('gulp'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify');

gulp.task('build', function(){
return gulp.src([
'jquery-jvectormap.js',
'lib/jquery-mousewheel.js',
'src/jvectormap.js',
'src/abstract-element.js',
'src/abstract-canvas-element.js',
'src/abstract-shape-element.js',
'src/svg-element.js',
'src/svg-group-element.js',
'src/svg-canvas-element.js',
'src/svg-shape-element.js',
'src/svg-path-element.js',
'src/svg-circle-element.js',
'src/svg-image-element.js',
'src/svg-text-element.js',
'src/vml-element.js',
'src/vml-group-element.js',
'src/vml-canvas-element.js',
'src/vml-shape-element.js',
'src/vml-path-element.js',
'src/vml-circle-element.js',
'src/vector-canvas.js',
'src/simple-scale.js',
'src/ordinal-scale.js',
'src/numeric-scale.js',
'src/color-scale.js',
'src/legend.js',
'src/data-series.js',
'src/proj.js',
'src/map-object.js',
'src/region.js',
'src/marker.js',
'src/map.js',
'src/multimap.js'
])
.pipe(concat('jquery.jvectormap.js'))
.pipe(gulp.dest('dist'))
.pipe(rename('jquery.jvectormap.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});

gulp.task('default', ['build'], function(){});


31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "jvectormap",
"version": "1.0.0",
"description": "jVectorMap is a vector-based, cross-browser and cross-platform component for interactive geography-related data visualization on the web. It provides numerious features like smooth zooming and panning, fully-customizable styling, markers, labels and tooltips.",
"main": "gulp.js",
"directories": {
"test": "tests"
},
"dependencies": {
"gulp": "^3.9.1",
"gulp-uglify": "^2.0.1"
},
"devDependencies": {
"gulp-concat": "^2.6.1",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^2.0.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/micdemarco/jvectormap.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/micdemarco/jvectormap/issues"
},
"homepage": "https://github.com/micdemarco/jvectormap#readme"
}
13 changes: 13 additions & 0 deletions src/map-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ jvm.MapObject.prototype.getLabelOffsets = function(key){
return offsets || [0, 0];
}

jvm.MapObject.prototype.getLabelStyle = function(key){
var style;

if (this.config.label) {
if (typeof this.config.label.styles === 'function') {
style = this.config.label.styles(key);
} else if (typeof this.config.label.styles === 'object') {
style = this.config.label.styles[key];
}
}
return style || {};
}

/**
* Set hovered state to the element. Hovered state means mouse cursor is over element. Styles will be updates respectively.
* @param {Boolean} isHovered <code>true</code> to make element hovered, <code>false</code> otherwise.
Expand Down
4 changes: 3 additions & 1 deletion src/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jvm.Marker = function(config){

text = this.getLabelText(config.index);
if (this.config.label && text) {
var labelStyle = this.getLabelStyle(config.index);
this.labelStyle = jvm.$.extend(true, {}, config.labelStyle, {initial: labelStyle || {}});
this.offsets = this.getLabelOffsets(config.index);
this.labelX = config.cx / this.map.scale - this.map.transX;
this.labelY = config.cy / this.map.scale - this.map.transY;
Expand All @@ -19,7 +21,7 @@ jvm.Marker = function(config){
dy: "0.6ex",
x: this.labelX,
y: this.labelY
}, config.labelStyle, config.labelsGroup);
}, this.labelStyle, config.labelsGroup);

this.label.addClass('jvectormap-marker jvectormap-element');
}
Expand Down