Skip to content

Commit

Permalink
Merge pull request #111 from nzzdev/release-1.14.0
Browse files Browse the repository at this point in the history
v1.14.0
  • Loading branch information
benib authored Oct 25, 2018
2 parents f882ce4 + e3887f0 commit 4a8bcae
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 13 deletions.
22 changes: 20 additions & 2 deletions chartTypes/bar-stacked/mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module.exports = function getMapping() {
labelText.field = "xValue";
}

spec.marks[0].marks[0].marks.push({
const labelMark = {
type: "text",
name: "bar-top-label",
from: {
Expand All @@ -127,7 +127,16 @@ module.exports = function getMapping() {
}
}
}
});
};

// if all the values are negative, we right align the label
const maxValue = dataHelpers.getMaxValue(itemData);
if (maxValue <= 0) {
labelMark.encode.update.x = { signal: "width" };
labelMark.encode.update.align = { value: "right" };
}

spec.marks[0].marks[0].marks.push(labelMark);
}
}
},
Expand Down Expand Up @@ -183,6 +192,15 @@ module.exports = function getMapping() {
objectPath.set(spec, "scales.0.nice", false);
objectPath.set(spec, "scales.0.domainMax", maxValue / divisor);
}
},
{
path: "item.data",
mapToSpec: function(data, spec, mappingData) {
// if we will only display one single bar, we should not show the Y axis label
if (data.length === 2) {
objectPath.set(spec, "axes.1.labels", false);
}
}
}
]
.concat(commonMappings.getBarDateSeriesHandlingMappings())
Expand Down
13 changes: 11 additions & 2 deletions chartTypes/bar/mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = function getMapping() {
labelText.field = "xValue";
}

spec.marks[0].marks[0].marks.push({
const labelMark = {
type: "text",
name: "bar-top-label",
from: {
Expand All @@ -126,7 +126,16 @@ module.exports = function getMapping() {
}
}
}
});
};

// if all the values are negative, we right align the label
const maxValue = dataHelpers.getMaxValue(itemData);
if (maxValue <= 0) {
labelMark.encode.update.x = { signal: "width" };
labelMark.encode.update.align = { value: "right" };
}

spec.marks[0].marks[0].marks.push(labelMark);
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "q-chart",
"version": "1.13.2",
"version": "1.14.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions resources/fixtures/data/bar-dates-days-year-interval.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@
{
"link": {},
"text": "FRED"
},
{
"link": { "isValid": true, "url": "https://nzz.ch"},
"text": "NZZ"
}
],
"options": {
Expand Down
2 changes: 1 addition & 1 deletion resources/fixtures/data/bar-dates-null-values.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"dateSeriesOptions": {
"interval": "year",
"prognosisStart": false
"prognosisStart": null
},
"lineChartOptions": {},
"colorOverwrite": [],
Expand Down
69 changes: 69 additions & 0 deletions resources/fixtures/data/bar-qualitative-negative-only.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"title": "FIXTURE: Bar - qualitative - only negative",
"subtitle": "in % des BIP",
"data": [
[
"Art",
"Wert"
],
[
"Schuldenanstieg",
"-8.7"
],
[
"Wertverlust Anlagen und Immobilien",
"-5.6"
],
[
"Wertverlust Hypotheken",
"-0.6"
],
[
"Verluste Pensionskassen",
"-7.3"
],
[
"andere Verluste",
"-3.9"
],
[
"Total Einbusse",
"-26.1"
]
],
"sources": [
{
"link": {},
"text": "IMF"
}
],
"options": {
"chartType": "Bar",
"hideAxisLabel": true,
"annotations": {},
"barOptions": {
"isBarChart": true,
"forceBarsOnSmall": false
},
"dateSeriesOptions": {
"interval": "year",
"prognosisStart": null
},
"lineChartOptions": {
"reverseYScale": false,
"lineInterpolation": "linear",
"isStockChart": false
},
"dotplotOptions": {},
"arrowOptions": {
"colorScheme": 0
},
"colorOverwrite": [
{
"color": "#e66e4a",
"position": 1
}
],
"highlightDataSeries": null
}
}
2 changes: 1 addition & 1 deletion resources/fixtures/data/bar-stacked-100.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"options": {
"chartType": "StackedBar",
"hideAxisLabel": false,
"hideAxisLabel": true,
"barOptions": {
"isBarChart": false,
"forceBarsOnSmall": true
Expand Down
33 changes: 33 additions & 0 deletions resources/fixtures/data/bar-stacked-qualitative-negative-only.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"title": "FIXTURE: StackedBar - qualitative - negative only",
"subtitle": "some subtitle here",
"data": [
[
"Cat",
"A",
"B"
],
[
"A very long label so it's on top of bars",
"-1000",
"-200"
],
[
"B",
"-200",
"-50"
]
],
"options": {
"chartType": "StackedBar",
"hideAxisLabel": false,
"barOptions": {
"isBarChart": false,
"forceBarsOnSmall": true
},
"dateSeriesOptions": {},
"lineChartOptions": {},
"colorOverwrite": [],
"highlightDataSeries": null
}
}
3 changes: 3 additions & 0 deletions routes/fixtures/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ const fixtureData = [
require(`${fixtureDataDirectory}/arrow-two-categories-same-value.json`),
require(`${fixtureDataDirectory}/bar-color-overwrite-highlight.json`),
require(`${fixtureDataDirectory}/bar-dates-days-prognosis.json`),
require(`${fixtureDataDirectory}/bar-dates-days-year-interval.json`),
require(`${fixtureDataDirectory}/bar-dates-null-values.json`),
require(`${fixtureDataDirectory}/bar-dates-quarter.json`),
require(`${fixtureDataDirectory}/bar-dates-years.json`),
require(`${fixtureDataDirectory}/bar-qualitative-negative-only.json`),
require(`${fixtureDataDirectory}/bar-qualitative-negative.json`),
require(`${fixtureDataDirectory}/bar-qualitative-single-serie.json`),
require(`${fixtureDataDirectory}/bar-stacked-100.json`),
require(`${fixtureDataDirectory}/bar-stacked-days-prognosis.json`),
require(`${fixtureDataDirectory}/bar-stacked-qualitative-negative-only.json`),
require(`${fixtureDataDirectory}/bar-stacked-qualitative-negative.json`),
require(`${fixtureDataDirectory}/dotplot-empty-cells.json`),
require(`${fixtureDataDirectory}/dotplot-floating-point.json`),
Expand Down
8 changes: 3 additions & 5 deletions views/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
{%- endif %}
{%- if item.sources.length > 0 %}
{%- if item.sources.length > 1 %}
Quellen:&nbsp;
Quellen:
{%- else %}
Quelle:&nbsp;
Quelle:
{%- endif %}

{%- for source in item.sources %}

{%- if source.text !== "" %}
{%- if source.link and source.link.isValid %}<a href="{{ source.link.url }}" target="blank" rel="noopener noreferrer">{{ source.text }}</a>
{%- else %} {{ source.text }}{%- endif %}
{% if not loop.last %}, {% endif %}
{%- if source.link and source.link.isValid %}<a href="{{ source.link.url }}" target="blank" rel="noopener noreferrer">{{ source.text }}</a>{%- else %} {{ source.text }}{%- endif %}{% if not loop.last %}, {% endif %}
{%- endif %}

{%- endfor %}
Expand Down

0 comments on commit 4a8bcae

Please sign in to comment.