From 4a9d3b2b0c544123ec20e4c0385e2e40ba7887f3 Mon Sep 17 00:00:00 2001 From: Manuel Roth Date: Wed, 17 Feb 2021 12:03:43 +0100 Subject: [PATCH 1/5] Fix text measure --- Dockerfile | 1 + helpers/textMeasure.js | 18 +++++------------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4f9e2b61..80fac714 100755 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ RUN apt-get update && apt-get -y install build-essential libcairo2-dev libpango1 COPY package.json /app/package.json COPY package-lock.json /app/package-lock.json RUN npm install --production +RUN npm install canvas --build-from-source # Copy everthing else in work directory COPY . /app diff --git a/helpers/textMeasure.js b/helpers/textMeasure.js index 7b768b42..0ede4dbe 100644 --- a/helpers/textMeasure.js +++ b/helpers/textMeasure.js @@ -3,26 +3,18 @@ const canvas = createCanvas(200, 200); const context = canvas.getContext("2d"); function getLabelTextWidth(text, toolRuntimeConfig) { - context.font = - toolRuntimeConfig.text.fontWeight + - " " + - toolRuntimeConfig.text.fontSize + - " " + - toolRuntimeConfig.text.font; + // CanvasRenderingContext2D.font expects the font string to be same form as CSS font specifier - https://developer.mozilla.org/en-US/docs/Web/CSS/font + context.font = `${toolRuntimeConfig.text.fontWeight} ${toolRuntimeConfig.text.fontSize}px ${toolRuntimeConfig.text.font}`; return context.measureText(text).width; } function getAxisLabelTextWidth(text, toolRuntimeConfig) { - context.font = - toolRuntimeConfig.axis.labelFontWeight + - " " + - toolRuntimeConfig.axis.labelFontSize + - " " + - toolRuntimeConfig.axis.labelFont; + // CanvasRenderingContext2D.font expects the font string to be same form as CSS font specifier - https://developer.mozilla.org/en-US/docs/Web/CSS/font + context.font = `${toolRuntimeConfig.axis.labelFontWeight} ${toolRuntimeConfig.axis.labelFontSize}px ${toolRuntimeConfig.axis.labelFont}`; return context.measureText(text).width; } module.exports = { getLabelTextWidth, - getAxisLabelTextWidth + getAxisLabelTextWidth, }; From 2a14046af2fa02055e5d5cbdf09a35d5c13e3222 Mon Sep 17 00:00:00 2001 From: Manuel Roth Date: Wed, 17 Feb 2021 20:59:29 +0100 Subject: [PATCH 2/5] Add 4px of padding to left of chart to avoid cut off labels --- chartTypes/area/vega-spec.json | 3 ++- chartTypes/line/vega-spec.json | 3 ++- config/vega-default.json | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/chartTypes/area/vega-spec.json b/chartTypes/area/vega-spec.json index 4af9fffb..3f749843 100644 --- a/chartTypes/area/vega-spec.json +++ b/chartTypes/area/vega-spec.json @@ -1,7 +1,8 @@ { "$schema": "https://vega.github.io/schema/vega/v5.json", "autosize": { - "type": "fit" + "type": "fit", + "contains": "padding" }, "height": 220, "data": [ diff --git a/chartTypes/line/vega-spec.json b/chartTypes/line/vega-spec.json index 8aa6f37e..7b398d81 100644 --- a/chartTypes/line/vega-spec.json +++ b/chartTypes/line/vega-spec.json @@ -1,7 +1,8 @@ { "$schema": "https://vega.github.io/schema/vega/v5.json", "autosize": { - "type": "fit" + "type": "fit", + "contains": "padding" }, "height": 220, "scales": [ diff --git a/config/vega-default.json b/config/vega-default.json index 2674472f..8d1820b0 100644 --- a/config/vega-default.json +++ b/config/vega-default.json @@ -14,5 +14,6 @@ "labelPadding": 8, "labelLimit": false, "tickRound": true - } + }, + "padding": { "left": 4 } } From 0e0794d322b3bfa6fd95871985e541b7b10497a9 Mon Sep 17 00:00:00 2001 From: Manuel Roth Date: Thu, 18 Feb 2021 10:37:34 +0100 Subject: [PATCH 3/5] Add padding on right --- config/vega-default.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/vega-default.json b/config/vega-default.json index 8d1820b0..b5520019 100644 --- a/config/vega-default.json +++ b/config/vega-default.json @@ -15,5 +15,5 @@ "labelLimit": false, "tickRound": true }, - "padding": { "left": 4 } + "padding": { "left": 4, "right": 4 } } From c9f3373b834fd04754bd1c78c519fc10f6ac2afe Mon Sep 17 00:00:00 2001 From: Manuel Roth Date: Thu, 18 Feb 2021 10:59:49 +0100 Subject: [PATCH 4/5] Remove build canvas from source --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 80fac714..4f9e2b61 100755 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,6 @@ RUN apt-get update && apt-get -y install build-essential libcairo2-dev libpango1 COPY package.json /app/package.json COPY package-lock.json /app/package-lock.json RUN npm install --production -RUN npm install canvas --build-from-source # Copy everthing else in work directory COPY . /app From be20c8d25278135ff65593c935f43de829d45cc3 Mon Sep 17 00:00:00 2001 From: Manuel Roth Date: Thu, 18 Feb 2021 11:35:11 +0100 Subject: [PATCH 5/5] Release v3.5.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 94053554..18db27b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "q-chart", - "version": "3.5.0", + "version": "3.5.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3a26da85..072dace5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "q-chart", - "version": "3.5.0", + "version": "3.5.1", "description": "", "main": "index.js", "scripts": {