User talk:Yurik/rightwidth signal (chart Graph Lines blank space) issue

To describe briefly what I found out on this issue with mw:Template:Graph:Lines, here provided series of graphs based on JSON models obtained with  parameters, and then slightly modified in few places.

In case of    - using simply 0 in place of expression explains root-cause of issue (it seems that at early stage signal obains 0 value which courses plotting area paddings expansion) { //  // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Lines //           Please do not modify it anywhere else, as it may get copied and override your changes. //           Suggestions can be made at https://www.mediawiki.org/wiki/Template_talk:Graph:Lines // // Template translation is in https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab //

"version": 2, "width": 500, "height": 300, "padding": "strict",

// "signals": [{"name": "rightwidth", "expr": "width + padding.right"}], "signals": [{"name": "rightwidth", "expr": "0"}], "data": [{ "name": "chart",

"url": "tabular:///bls.gov/US Women's weekly earnings as a percent of men's by age, annual averages.tab", "format": {"type": "json" , "property": "data"

},   "transform": [ // Convert xField parameter into a field "_xfield" {"type": "formula", "field": "_xfield", "expr": "datetime(datum.year, 0, 1)" }    , {"type": "sort", "by": ["_xfield"]} , {"type": "fold", "fields": ["age_16_24", "age_25_34", "age_35_44", "age_45_54"]} , {"type": "formula", "field": "_yfield", "expr": "datum.value" }

] }, {    "name": "labels", "url": "tabular:///bls.gov/US Women's weekly earnings as a percent of men's by age, annual averages.tab", "format": {"type": "json", "property": "fields"} } ],  "scales": [ {     "name": "x", "type": "time", "domain": {"data": "chart", "field": "_xfield"}, "range": "width",

},   {      "name": "y", "type": "linear", "range": "height", "domain": {"data": "chart", "field": "_yfield"}, "zero": false,

"domainMax": 100, },   {      "name": "color", "type": "ordinal", "range": "category10", "domain": {"data": "chart", "field": "key"} }, {     "name": "labels", "type": "ordinal", "domain": {"data": "labels", "field": "name"}, "range": {"data": "labels", "field": "title"}, } ], "legends": [{ "fill": "color", "stroke": "color", "title": "Age group", "properties": { "labels": { "text": {"scale": "labels", "field": "data"} } } }], "axes": [ {"scale": "x", "type": "x", "tickSizeEnd": 0 , "ticks": 7 , "title": "Year"

},   {"scale": "y", "type": "y", "tickSizeEnd": 0

, "title": "Percentage"

, "grid": true } ],

"marks": [ // Group data by the group parameter or "key", and draw lines, one line per group {     "type": "group", "from": { "data": "chart", "transform": [{"type": "facet", "groupby": ["key"]}] },     "marks": [ {         "type": "line", "properties": { "enter": { "y": {"scale": "y", "field": "_yfield"}, "x": {"scale": "x", "field": "_xfield"}, "stroke": {"scale": "color", "field": "key"}, "interpolate": {"value": "monotone"}, "strokeWidth": {"value": 2.5} }         }        }      ],    }

// Draw title at the top of the graph ,  {      "type": "text", "properties": { "enter": { "x": {"signal": "rightwidth", "mult": 0.5}, "y": {"value": -15}, "text": {"value": "Gender pay gap in the United States"}, "fontWeight": {"value": "bold"}, "align": {"value": "center"}, "baseline": {"value": "bottom"}, "fill": {"value": "#000"} }     }    }  ] }  - causes the same blank space at the left, while title repositioned +/- properly. { //  // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Lines //           Please do not modify it anywhere else, as it may get copied and override your changes. //           Suggestions can be made at https://www.mediawiki.org/wiki/Template_talk:Graph:Lines // // Template translation is in https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab //

"version": 2, "width": 500, "height": 300, "padding": "strict",

"signals": [{"name": "rightwidth", "expr": "width + padding.right"}], // "signals": [{"name": "rightwidth", "expr": "0"}], "data": [{ "name": "chart",

"url": "tabular:///bls.gov/US Women's weekly earnings as a percent of men's by age, annual averages.tab", "format": {"type": "json" , "property": "data"

},   "transform": [ // Convert xField parameter into a field "_xfield" {"type": "formula", "field": "_xfield", "expr": "datetime(datum.year, 0, 1)" }    , {"type": "sort", "by": ["_xfield"]} , {"type": "fold", "fields": ["age_16_24", "age_25_34", "age_35_44", "age_45_54"]} , {"type": "formula", "field": "_yfield", "expr": "datum.value" }

] }, {    "name": "labels", "url": "tabular:///bls.gov/US Women's weekly earnings as a percent of men's by age, annual averages.tab", "format": {"type": "json", "property": "fields"} } ],  "scales": [ {     "name": "x", "type": "time", "domain": {"data": "chart", "field": "_xfield"}, "range": "width",

},   {      "name": "y", "type": "linear", "range": "height", "domain": {"data": "chart", "field": "_yfield"}, "zero": false,

"domainMax": 100, },   {      "name": "color", "type": "ordinal", "range": "category10", "domain": {"data": "chart", "field": "key"} }, {     "name": "labels", "type": "ordinal", "domain": {"data": "labels", "field": "name"}, "range": {"data": "labels", "field": "title"}, } ], "legends": [{ "fill": "color", "stroke": "color", "title": "Age group", "properties": { "labels": { "text": {"scale": "labels", "field": "data"} } } }], "axes": [ {"scale": "x", "type": "x", "tickSizeEnd": 0 , "ticks": 7 , "title": "Year"

},   {"scale": "y", "type": "y", "tickSizeEnd": 0

, "title": "Percentage"

, "grid": true } ],

"marks": [ // Group data by the group parameter or "key", and draw lines, one line per group {     "type": "group", "from": { "data": "chart", "transform": [{"type": "facet", "groupby": ["key"]}] },     "marks": [ {         "type": "line", "properties": { "enter": { "y": {"scale": "y", "field": "_yfield"}, "x": {"scale": "x", "field": "_xfield"}, "stroke": {"scale": "color", "field": "key"}, "interpolate": {"value": "monotone"}, "strokeWidth": {"value": 2.5} }         }        }      ],    }

// Draw title at the top of the graph ,  {      "type": "text", "properties": { "enter": { "x": {"signal": "rightwidth", "mult": 0.5}, "y": {"value": -15}, "text": {"value": "Gender pay gap in the United States"}, "fontWeight": {"value": "bold"}, "align": {"value": "center"}, "baseline": {"value": "bottom"}, "fill": {"value": "#000"} }     }    }  ] } In case of   (or when simply omitting this parameter), it seems that signal not calculated (recalculated) at all, and always equals 0, except case when initialized explicitly ,  {  //  // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Lines //           Please do not modify it anywhere else, as it may get copied and override your changes. //           Suggestions can be made at https://www.mediawiki.org/wiki/Template_talk:Graph:Lines // // Template translation is in https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab //

"version": 2, "width": 500, "height": 300, "padding": "auto", // "padding": "strict",

"signals": [{"name": "rightwidth", "expr": "width + padding.right"}], // "signals": [{"name": "rightwidth", "expr": "0"}], "data": [{ "name": "chart",

"url": "tabular:///bls.gov/US Women's weekly earnings as a percent of men's by age, annual averages.tab", "format": {"type": "json" , "property": "data"

},   "transform": [ // Convert xField parameter into a field "_xfield" {"type": "formula", "field": "_xfield", "expr": "datetime(datum.year, 0, 1)" }    , {"type": "sort", "by": ["_xfield"]} , {"type": "fold", "fields": ["age_16_24", "age_25_34", "age_35_44", "age_45_54"]} , {"type": "formula", "field": "_yfield", "expr": "datum.value" }

] }, {    "name": "labels", "url": "tabular:///bls.gov/US Women's weekly earnings as a percent of men's by age, annual averages.tab", "format": {"type": "json", "property": "fields"} } ],  "scales": [ {     "name": "x", "type": "time", "domain": {"data": "chart", "field": "_xfield"}, "range": "width",

},   {      "name": "y", "type": "linear", "range": "height", "domain": {"data": "chart", "field": "_yfield"}, "zero": false,

"domainMax": 100, },   {      "name": "color", "type": "ordinal", "range": "category10", "domain": {"data": "chart", "field": "key"} }, {     "name": "labels", "type": "ordinal", "domain": {"data": "labels", "field": "name"}, "range": {"data": "labels", "field": "title"}, } ], "legends": [{ "fill": "color", "stroke": "color", "title": "Age group", "properties": { "labels": { "text": {"scale": "labels", "field": "data"} } } }], "axes": [ {"scale": "x", "type": "x", "tickSizeEnd": 0 , "ticks": 7 , "title": "Year"

},   {"scale": "y", "type": "y", "tickSizeEnd": 0

, "title": "Percentage"

, "grid": true } ],

"marks": [ // Group data by the group parameter or "key", and draw lines, one line per group {     "type": "group", "from": { "data": "chart", "transform": [{"type": "facet", "groupby": ["key"]}] },     "marks": [ {         "type": "line", "properties": { "enter": { "y": {"scale": "y", "field": "_yfield"}, "x": {"scale": "x", "field": "_xfield"}, "stroke": {"scale": "color", "field": "key"}, "interpolate": {"value": "monotone"}, "strokeWidth": {"value": 2.5} }         }        }      ],    }

// Draw title at the top of the graph ,  {      "type": "text", "properties": { "enter": { "x": {"signal": "rightwidth", "mult": 0.5}, "y": {"value": -15}, "text": {"value": "Gender pay gap in the United States"}, "fontWeight": {"value": "bold"}, "align": {"value": "center"}, "baseline": {"value": "bottom"}, "fill": {"value": "#000"} }     }    }  ] } Other interesting observation that one could expect that signal defined as   should behave as simple alias to   signal, and should behave quite the same in any situation. But in fact replacing "width" with "width_alias" cause above issue to reproduce (e.g.  and   produces different outcome)

U.84-47-17-91 (talk) 18:04, 20 March 2021 (UTC)