Skip to content

Commit

Permalink
Merge pull request #30 from KaiVolland/hide-rect
Browse files Browse the repository at this point in the history
Some small changes
  • Loading branch information
KaiVolland committed Feb 27, 2019
2 parents 3b12fa1 + 66bcb7c commit 5efe557
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "@terrestris/legend-util",
"version": "0.0.2",
"description": "A set of helper classes to render legends.",
"main": "src/index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"release": "np --no-yarn && git push git@github.com:terrestris/legend-util.git master --tags",
"lint": "tslint --project tsconfig.json --config tslint.json && tsc --noEmit --project tsconfig.json",
Expand All @@ -28,7 +29,6 @@
"peerDependencies": {
"d3": "~5"
},
"types": "dist/index.d.ts",
"devDependencies": {
"@babel/core": "7.3.4",
"@babel/plugin-proposal-class-properties": "7.3.4",
Expand Down
33 changes: 22 additions & 11 deletions src/LegendRenderer/LegendRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Style,
Symbolizer,
Rule
} from 'geostyler-style';
} from 'geostyler-style';

import OlStyleParser from 'geostyler-openlayers-parser';

Expand All @@ -34,6 +34,7 @@ interface LegendsConfiguration {
maxColumnHeight?: number;
maxColumnWidth?: number;
overflow?: 'auto' | 'group';
hideRect?: boolean;
}

const iconSize = [45, 30];
Expand Down Expand Up @@ -85,19 +86,28 @@ class LegendRenderer {
item: LegendItemConfiguration,
position: [number, number]
) {

const {
hideRect,
maxColumnHeight,
maxColumnWidth
} = this.config;

if (item.rule) {
container = container.append('g')
.attr('class', 'legend-item')
.attr('title', item.title);
const img = this.getRuleIcon(item.rule);
return img.then((uri: string) => {
container.append('rect')
.attr('x', position[0] + 1)
.attr('y', position[1])
.attr('width', iconSize[0])
.attr('height', iconSize[1])
.style('fill-opacity', 0)
.style('stroke', 'black');
if (!hideRect) {
container.append('rect')
.attr('x', position[0] + 1)
.attr('y', position[1])
.attr('width', iconSize[0])
.attr('height', iconSize[1])
.style('fill-opacity', 0)
.style('stroke', 'black');
}
container.append('image')
.attr('x', position[0] + 1)
.attr('y', position[1])
Expand All @@ -109,9 +119,9 @@ class LegendRenderer {
.attr('x', position[0] + iconSize[0] + 5)
.attr('y', position[1] + 20);
position[1] += iconSize[1] + 5;
if (this.config.maxColumnHeight && position[1] + iconSize[1] + 5 >= this.config.maxColumnHeight) {
if (maxColumnHeight && position[1] + iconSize[1] + 5 >= maxColumnHeight) {
position[1] = 5;
position[0] += this.config.maxColumnWidth;
position[0] += maxColumnWidth;
}
});
}
Expand Down Expand Up @@ -235,8 +245,9 @@ class LegendRenderer {
if (config.title) {
container.append('text')
.text(config.title)
.attr('class', 'legend-title')
.attr('text-anchor', 'start')
.attr('dy', position[1] + 10)
.attr('dy', '1em')
.attr('dx', position[0]);
position[1] += 20;
}
Expand Down
5 changes: 0 additions & 5 deletions src/index.js

This file was deleted.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './LegendRenderer/LegendRenderer';

0 comments on commit 5efe557

Please sign in to comment.