Skip to content

Commit

Permalink
Merge pull request #104 from nzzdev/release-1.13.0
Browse files Browse the repository at this point in the history
Release 1.13.0
  • Loading branch information
benib authored Oct 10, 2018
2 parents 8c578e6 + 6333f09 commit de834fe
Show file tree
Hide file tree
Showing 23 changed files with 2,051 additions and 2,080 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"DIVERGING_COLOR_SCHEMES": "[{ \"label\": \"one\", \"key\": 0, \"scheme_name\": \"diverging_one\" }, { \"label\": \"two\", \"key\": 1, \"scheme_name\": \"diverging_two\" }, { \"label\": \"three\", \"key\": 2, \"scheme_name\": \"diverging_three\" } ]",
"FONTS": "[{\"url\": \"https://assets.static-nzz.ch/nzz-niobe/assets/fonts/GT-America-Standard-Regular.otf\",\"name\": \"nzz-sans-serif\",\"filename\": \"nzz-sans-serif.otf\"}]"
},
"runtimeVersion": "10.6.0",
"runtimeVersion": "10.11.0",
"program": "${workspaceRoot}/index.js"
}
]
Expand Down
62 changes: 35 additions & 27 deletions chartTypes/arrow/mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const textMetrics = require("vega").textMetrics;

const configuredDivergingColorSchemes = require("../../helpers/colorSchemes.js").getConfiguredDivergingColorSchemes();

module.exports = function getMapping(config = {}) {
module.exports = function getMapping() {
return [
{
path: "data",
mapToSpec: function(itemData, spec, item) {
path: "item.data",
mapToSpec: function(itemData, spec) {
// set the x axis title
objectPath.set(spec, "axes.1.title", itemData[0][0]);

Expand Down Expand Up @@ -126,8 +126,8 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "options.hideAxisLabel",
mapToSpec: function(hideAxisLabel, spec, item) {
path: "item.options.hideAxisLabel",
mapToSpec: function(hideAxisLabel, spec) {
if (hideAxisLabel === true) {
// unset the x axis label
objectPath.set(spec, "axes.1.title", undefined);
Expand All @@ -136,12 +136,12 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "options.arrowOptions.minValue",
mapToSpec: function(minValue, spec, item) {
path: "item.options.arrowOptions.minValue",
mapToSpec: function(minValue, spec, mappingData) {
// check if we need to shorten the number labels
const divisor = dataHelpers.getDivisor(item.data);
const divisor = dataHelpers.getDivisor(mappingData.item.data);

const dataMinValue = dataHelpers.getMinValue(item.data);
const dataMinValue = dataHelpers.getMinValue(mappingData.item.data);
if (dataMinValue < minValue) {
minValue = dataMinValue;
}
Expand All @@ -151,12 +151,12 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "options.arrowOptions.maxValue",
mapToSpec: function(maxValue, spec, item) {
path: "item.options.arrowOptions.maxValue",
mapToSpec: function(maxValue, spec, mappingData) {
// check if we need to shorten the number labels
const divisor = dataHelpers.getDivisor(item.data);
const divisor = dataHelpers.getDivisor(mappingData.item.data);

const dataMaxValue = dataHelpers.getMaxValue(item.data);
const dataMaxValue = dataHelpers.getMaxValue(mappingData.item.data);
if (dataMaxValue > maxValue) {
maxValue = dataMaxValue;
}
Expand All @@ -166,8 +166,8 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "options.arrowOptions.colorScheme",
mapToSpec: function(colorScheme, spec, item) {
path: "item.options.arrowOptions.colorScheme",
mapToSpec: function(colorScheme, spec) {
if (
configuredDivergingColorSchemes &&
configuredDivergingColorSchemes[colorScheme]
Expand All @@ -181,8 +181,8 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "options.annotations.first",
mapToSpec: function(showFirstAnimation, spec, item) {
path: "item.options.annotations.first",
mapToSpec: function(showFirstAnimation, spec) {
if (!showFirstAnimation) {
return;
}
Expand Down Expand Up @@ -229,8 +229,8 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "options.annotations.last",
mapToSpec: function(showLastAnnotation, spec, item) {
path: "item.options.annotations.last",
mapToSpec: function(showLastAnnotation, spec) {
if (!showLastAnnotation) {
return;
}
Expand Down Expand Up @@ -277,8 +277,8 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "options.annotations.diff",
mapToSpec: function(showDiffAnnotation, spec, item) {
path: "item.options.annotations.diff",
mapToSpec: function(showDiffAnnotation, spec) {
if (!showDiffAnnotation) {
return;
}
Expand All @@ -303,11 +303,19 @@ module.exports = function getMapping(config = {}) {
from: { data: "diffAnnotationSeries" },
encode: {
enter: {
text: {
signal: `format(datum.diffToNext, "${
d3config.formatLocale.decimal
}")`
},
text: [
{
test: "datum.diffToNext > 0",
signal: `format(datum.diffToNext, "+${
d3config.formatLocale.decimal
}")`
},
{
signal: `format(datum.diffToNext, "${
d3config.formatLocale.decimal
}")`
}
],
y: {
signal: "arrowGroupHeight / 2 - 4"
},
Expand All @@ -325,5 +333,5 @@ module.exports = function getMapping(config = {}) {
spec.marks[0].marks[0].marks.push(diffTextMarksSpec);
}
}
].concat(commonMappings.getBarLabelColorMappings(config));
].concat(commonMappings.getBarLabelColorMappings());
};
40 changes: 21 additions & 19 deletions chartTypes/bar-stacked/mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,33 @@ const getLongestDataLabel = require("../../helpers/data.js")
.getLongestDataLabel;
const textMetrics = require("vega").textMetrics;

function shouldHaveLabelsOnTopOfBar(item, config) {
function shouldHaveLabelsOnTopOfBar(mappingData) {
const item = mappingData.item;
// this does not work for positive and negative values. so if we have both, we do not show the labels on top
const minValue = dataHelpers.getMinValue(item.data);
const maxValue = dataHelpers.getMaxValue(item.data);
if (minValue < 0 && maxValue > 0) {
return false;
}

const longestLabel = getLongestDataLabel(item, config, true);
const longestLabel = getLongestDataLabel(mappingData, true);
const textItem = {
text: longestLabel
};
const longestLabelWidth = textMetrics.width(textItem);

if (config.width / 3 < longestLabelWidth) {
if (mappingData.width / 3 < longestLabelWidth) {
return true;
}
return false;
}

module.exports = function getMapping(config = {}) {
module.exports = function getMapping() {
return [
{
path: "data",
mapToSpec: function(itemData, spec, item) {
path: "item.data",
mapToSpec: function(itemData, spec, mappingData) {
const item = mappingData.item;
// set the x axis title
objectPath.set(spec, "axes.1.title", itemData[0][0]);

Expand Down Expand Up @@ -81,7 +83,7 @@ module.exports = function getMapping(config = {}) {
);
numberOfDataSeriesSignal.value = itemData[0].length - 1; // the first column is not a data column, so we subtract it

if (shouldHaveLabelsOnTopOfBar(item, config)) {
if (shouldHaveLabelsOnTopOfBar(mappingData)) {
spec.axes[1].labels = false;

// flush the X axis labels if we have the labels on top of the bar
Expand All @@ -98,7 +100,7 @@ module.exports = function getMapping(config = {}) {
// if we have a date series, we need to format the label accordingly
// otherwise we use the exact xValue as the label
const labelText = {};
if (config.dateFormat) {
if (mappingData.dateFormat) {
const d3format =
intervals[item.options.dateSeriesOptions.interval].d3format;
labelText.signal = `timeFormat(datum.xValue, '${
Expand Down Expand Up @@ -130,8 +132,8 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "data",
mapToSpec: function(itemData, spec, item, id) {
path: "item.data",
mapToSpec: function(itemData, spec) {
// check if all rows sum up to 100
const stackedSums = itemData
.slice(1)
Expand All @@ -158,8 +160,8 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "options.hideAxisLabel",
mapToSpec: function(hideAxisLabel, spec, item) {
path: "item.options.hideAxisLabel",
mapToSpec: function(hideAxisLabel, spec) {
if (hideAxisLabel === true) {
// unset the x axis label
objectPath.set(spec, "axes.1.title", undefined);
Expand All @@ -168,12 +170,12 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "options.barOptions.maxValue",
mapToSpec: function(maxValue, spec, item) {
path: "item.options.barOptions.maxValue",
mapToSpec: function(maxValue, spec, mappingData) {
// check if we need to shorten the number labels
const divisor = dataHelpers.getDivisor(item.data);
const divisor = dataHelpers.getDivisor(mappingData.item.data);

const dataMaxValue = dataHelpers.getMaxValue(item.data);
const dataMaxValue = dataHelpers.getMaxValue(mappingData.item.data);
if (dataMaxValue > maxValue) {
maxValue = dataMaxValue;
}
Expand All @@ -183,7 +185,7 @@ module.exports = function getMapping(config = {}) {
}
}
]
.concat(commonMappings.getBarDateSeriesHandlingMappings(config))
.concat(commonMappings.getBarPrognosisMappings(config))
.concat(commonMappings.getBarLabelColorMappings(config));
.concat(commonMappings.getBarDateSeriesHandlingMappings())
.concat(commonMappings.getBarPrognosisMappings())
.concat(commonMappings.getBarLabelColorMappings());
};
40 changes: 21 additions & 19 deletions chartTypes/bar/mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,45 @@ const getLongestDataLabel = require("../../helpers/data.js")
.getLongestDataLabel;
const textMetrics = require("vega").textMetrics;

function shouldHaveLabelsOnTopOfBar(item, config) {
function shouldHaveLabelsOnTopOfBar(mappingData) {
const item = mappingData.item;
// this does not work for positive and negative values. so if we have both, we do not show the labels on top
const minValue = dataHelpers.getMinValue(item.data);
const maxValue = dataHelpers.getMaxValue(item.data);
if (minValue < 0 && maxValue > 0) {
return false;
}

const longestLabel = getLongestDataLabel(item, config, true);
const longestLabel = getLongestDataLabel(mappingData, true);
const textItem = {
text: longestLabel
};
const longestLabelWidth = textMetrics.width(textItem);

if (config.width / 3 < longestLabelWidth) {
if (mappingData.width / 3 < longestLabelWidth) {
return true;
}
return false;
}

module.exports = function getMapping(config = {}) {
module.exports = function getMapping() {
return [
{
path: "data",
mapToSpec: function(itemData, spec, item) {
path: "item.data",
mapToSpec: function(itemData, spec, mappingData) {
const item = mappingData.item;
// set the x axis title
objectPath.set(spec, "axes.1.title", itemData[0][0]);

// set the barWidth depending on the number of bars we will get
const numberOfBars = (itemData.length - 1) * itemData[0].length;
const barWidthSignal = spec.signals.find(signal => {
return signal.name === 'barWidth'
return signal.name === "barWidth";
});
if (numberOfBars > 10) {
barWidthSignal.value = 16
barWidthSignal.value = 16;
} else {
barWidthSignal.value = 24
barWidthSignal.value = 24;
}

// check if we need to shorten the number labels
Expand Down Expand Up @@ -80,7 +82,7 @@ module.exports = function getMapping(config = {}) {
);
numberOfDataSeriesSignal.value = itemData[0].length - 1; // the first column is not a data column, so we subtract it

if (shouldHaveLabelsOnTopOfBar(item, config)) {
if (shouldHaveLabelsOnTopOfBar(mappingData)) {
spec.axes[1].labels = false;

// flush the X axis labels if we have the labels on top of the bar
Expand All @@ -97,7 +99,7 @@ module.exports = function getMapping(config = {}) {
// if we have a date series, we need to format the label accordingly
// otherwise we use the exact xValue as the label
const labelText = {};
if (config.dateFormat) {
if (mappingData.dateFormat) {
const d3format =
intervals[item.options.dateSeriesOptions.interval].d3format;
labelText.signal = `timeFormat(datum.xValue, '${
Expand Down Expand Up @@ -129,8 +131,8 @@ module.exports = function getMapping(config = {}) {
}
},
{
path: "options.hideAxisLabel",
mapToSpec: function(hideAxisLabel, spec, item) {
path: "item.options.hideAxisLabel",
mapToSpec: function(hideAxisLabel, spec) {
if (hideAxisLabel === true) {
// unset the x axis label
objectPath.set(spec, "axes.1.title", undefined);
Expand All @@ -140,11 +142,11 @@ module.exports = function getMapping(config = {}) {
},
{
path: "options.barOptions.maxValue",
mapToSpec: function(maxValue, spec, item) {
mapToSpec: function(maxValue, spec, mappingData) {
// check if we need to shorten the number labels
const divisor = dataHelpers.getDivisor(item.data);
const divisor = dataHelpers.getDivisor(mappingData.item.data);

const dataMaxValue = dataHelpers.getMaxValue(item.data);
const dataMaxValue = dataHelpers.getMaxValue(mappingData.item.data);
if (dataMaxValue > maxValue) {
maxValue = dataMaxValue;
}
Expand All @@ -154,7 +156,7 @@ module.exports = function getMapping(config = {}) {
}
}
]
.concat(commonMappings.getBarDateSeriesHandlingMappings(config))
.concat(commonMappings.getBarPrognosisMappings(config))
.concat(commonMappings.getBarLabelColorMappings(config));
.concat(commonMappings.getBarDateSeriesHandlingMappings())
.concat(commonMappings.getBarPrognosisMappings())
.concat(commonMappings.getBarLabelColorMappings());
};
Loading

0 comments on commit de834fe

Please sign in to comment.