@malloydata/render 0.0.43-dev230616164521 → 0.0.43-dev230616201638

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,8 @@
1
1
  import { DataColumn } from '@malloydata/malloy';
2
2
  import { Renderer } from '../renderer';
3
- import { RendererOptions } from '../renderer_types';
4
3
  export declare class HTMLDateRenderer implements Renderer {
5
4
  private readonly document;
6
- private readonly options;
7
- constructor(document: Document, options: RendererOptions);
5
+ private readonly queryTimezone;
6
+ constructor(document: Document, queryTimezone: string | undefined);
8
7
  render(data: DataColumn): Promise<HTMLElement>;
9
8
  }
package/dist/html/date.js CHANGED
@@ -26,9 +26,9 @@ exports.HTMLDateRenderer = void 0;
26
26
  const malloy_1 = require("@malloydata/malloy");
27
27
  const utils_1 = require("./utils");
28
28
  class HTMLDateRenderer {
29
- constructor(document, options) {
29
+ constructor(document, queryTimezone) {
30
30
  this.document = document;
31
- this.options = options;
31
+ this.queryTimezone = queryTimezone;
32
32
  }
33
33
  async render(data) {
34
34
  if (data.isNull()) {
@@ -39,7 +39,7 @@ class HTMLDateRenderer {
39
39
  }
40
40
  const timeframe = data.field.timeframe ||
41
41
  (data.isTimestamp() ? malloy_1.TimestampTimeframe.Second : malloy_1.DateTimeframe.Day);
42
- const timestring = (0, utils_1.timeToString)(data.value, timeframe);
42
+ const timestring = (0, utils_1.timeToString)(data.value, timeframe, this.queryTimezone);
43
43
  const element = this.document.createElement('span');
44
44
  element.appendChild(this.document.createTextNode(timestring));
45
45
  return element;
@@ -12,4 +12,4 @@ export declare class JSONView {
12
12
  constructor(document: Document);
13
13
  render(table: DataArray): Promise<HTMLElement>;
14
14
  }
15
- export declare function makeRenderer(field: Explore | Field, document: Document, options: RendererOptions, styleDefaults: StyleDefaults): Renderer;
15
+ export declare function makeRenderer(field: Explore | Field, document: Document, options: RendererOptions, styleDefaults: StyleDefaults, queryTimezone: string | undefined): Renderer;
@@ -59,7 +59,7 @@ class HTMLView {
59
59
  async render(table, options) {
60
60
  const renderer = makeRenderer(table.field, this.document, options, {
61
61
  size: 'large',
62
- });
62
+ }, table.field.structDef.queryTimezone);
63
63
  try {
64
64
  // TODO Implement row streaming capability for some renderers: some renderers should be usable
65
65
  // as a builder with `begin(field: StructDef)`, `row(field: StructDef, row: QueryDataRow)`,
@@ -159,7 +159,7 @@ function isContainer(field) {
159
159
  throw new Error(`${field.name} does not contain fields and cannot be rendered this way`);
160
160
  }
161
161
  }
162
- function makeRenderer(field, document, options, styleDefaults) {
162
+ function makeRenderer(field, document, options, styleDefaults, queryTimezone) {
163
163
  const renderDef = getRendererOptions(field, options.dataStyles) || {};
164
164
  options.dataStyles[field.name] = renderDef;
165
165
  if (renderDef.renderer === 'shape_map') {
@@ -230,7 +230,7 @@ function makeRenderer(field, document, options, styleDefaults) {
230
230
  field.isAtomicField() &&
231
231
  (field.type === malloy_1.AtomicFieldType.Date ||
232
232
  field.type === malloy_1.AtomicFieldType.Timestamp))) {
233
- return new date_1.HTMLDateRenderer(document, options);
233
+ return new date_1.HTMLDateRenderer(document, queryTimezone);
234
234
  }
235
235
  else if (renderDef.renderer === 'currency') {
236
236
  return new currency_1.HTMLCurrencyRenderer(document);
@@ -280,7 +280,7 @@ function makeContainerRenderer(cType, document, explore, options) {
280
280
  const c = container_1.ContainerRenderer.make(cType, document, explore, options);
281
281
  const result = {};
282
282
  explore.intrinsicFields.forEach((field) => {
283
- result[field.name] = makeRenderer(field, document, options, c.defaultStylesForChildren);
283
+ result[field.name] = makeRenderer(field, document, options, c.defaultStylesForChildren, explore.queryTimezone);
284
284
  });
285
285
  c.childRenderers = result;
286
286
  return c;
@@ -27,6 +27,7 @@ const drill_1 = require("../drill");
27
27
  const container_1 = require("./container");
28
28
  const number_1 = require("./number");
29
29
  const utils_1 = require("./utils");
30
+ const date_1 = require("./date");
30
31
  class HTMLTableRenderer extends container_1.ContainerRenderer {
31
32
  constructor() {
32
33
  super(...arguments);
@@ -40,9 +41,10 @@ class HTMLTableRenderer extends container_1.ContainerRenderer {
40
41
  }
41
42
  const header = this.document.createElement('tr');
42
43
  table.field.intrinsicFields.forEach(field => {
43
- const name = (0, utils_1.formatTitle)(this.options, field.name, this.options.dataStyles[field.name]);
44
+ let name = (0, utils_1.formatTitle)(this.options, field.name, this.options.dataStyles[field.name]);
44
45
  const childRenderer = this.childRenderers[name];
45
46
  const isNumeric = childRenderer instanceof number_1.HTMLNumberRenderer;
47
+ const isDateTime = childRenderer instanceof date_1.HTMLDateRenderer;
46
48
  const headerCell = this.document.createElement('th');
47
49
  headerCell.style.cssText = `
48
50
  padding: 8px;
@@ -50,7 +52,11 @@ class HTMLTableRenderer extends container_1.ContainerRenderer {
50
52
  border-bottom: 1px solid var(--malloy-border-color, #eaeaea);
51
53
  text-align: ${isNumeric ? 'right' : 'left'};
52
54
  `;
53
- headerCell.innerHTML = name.replace(/_/g, '_&#8203;');
55
+ name = name.replace(/_/g, '_&#8203;');
56
+ if (isDateTime && field.parentExplore.structDef.queryTimezone) {
57
+ name = `${name} (${field.parentExplore.structDef.queryTimezone})`;
58
+ }
59
+ headerCell.innerHTML = name;
54
60
  header.appendChild(headerCell);
55
61
  });
56
62
  if (this.options.isDrillingEnabled) {
@@ -4,7 +4,7 @@ import { RendererOptions } from '../renderer_types';
4
4
  export declare function getColorScale(type: 'temporal' | 'ordinal' | 'quantitative' | 'nominal' | undefined, isRectMark: boolean, hasOverlappingText?: boolean): {
5
5
  range: string[];
6
6
  } | undefined;
7
- export declare function timeToString(time: Date, timeframe: DateTimeframe | TimestampTimeframe): string;
7
+ export declare function timeToString(time: Date, timeframe: DateTimeframe | TimestampTimeframe, timezone?: string): string;
8
8
  export declare function yieldTask(): Promise<void>;
9
9
  export declare function createErrorElement(document: Document, error: string | Error): HTMLElement;
10
10
  export declare function createNullElement(document: Document): HTMLElement;
@@ -28,6 +28,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
28
28
  exports.formatTitle = exports.createDrillIcon = exports.createNullElement = exports.createErrorElement = exports.yieldTask = exports.timeToString = exports.getColorScale = void 0;
29
29
  const malloy_1 = require("@malloydata/malloy");
30
30
  const startCase_1 = __importDefault(require("lodash/startCase"));
31
+ const luxon_1 = require("luxon");
31
32
  function getColorScale(type, isRectMark, hasOverlappingText = false) {
32
33
  if (type === undefined) {
33
34
  return undefined;
@@ -74,61 +75,62 @@ exports.getColorScale = getColorScale;
74
75
  function numberFixedDigits(value, digits) {
75
76
  return value.toString().padStart(digits, '0');
76
77
  }
77
- function timeToString(time, timeframe) {
78
+ function timeToString(time, timeframe, timezone) {
79
+ const dateTime = luxon_1.DateTime.fromJSDate(time, { zone: timezone });
78
80
  switch (timeframe) {
79
81
  case malloy_1.TimestampTimeframe.Year:
80
82
  case malloy_1.DateTimeframe.Year: {
81
- const year = numberFixedDigits(time.getUTCFullYear(), 4);
83
+ const year = numberFixedDigits(dateTime.year, 4);
82
84
  return `${year}`;
83
85
  }
84
86
  case malloy_1.TimestampTimeframe.Quarter:
85
87
  case malloy_1.DateTimeframe.Quarter: {
86
- const year = numberFixedDigits(time.getUTCFullYear(), 4);
87
- const quarter = Math.floor(time.getUTCMonth() / 3) + 1;
88
+ const year = numberFixedDigits(dateTime.year, 4);
89
+ const quarter = Math.floor(dateTime.month / 3) + 1;
88
90
  return `${year}-Q${quarter}`;
89
91
  }
90
92
  case malloy_1.TimestampTimeframe.Month:
91
93
  case malloy_1.DateTimeframe.Month: {
92
- const year = numberFixedDigits(time.getUTCFullYear(), 2);
93
- const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
94
+ const year = numberFixedDigits(dateTime.year, 2);
95
+ const month = numberFixedDigits(dateTime.month, 2);
94
96
  return `${year}-${month}`;
95
97
  }
96
98
  case malloy_1.TimestampTimeframe.Week:
97
99
  case malloy_1.DateTimeframe.Week: {
98
- const year = numberFixedDigits(time.getUTCFullYear(), 2);
99
- const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
100
- const day = numberFixedDigits(time.getUTCDate(), 2);
100
+ const year = numberFixedDigits(dateTime.year, 2);
101
+ const month = numberFixedDigits(dateTime.month, 2);
102
+ const day = numberFixedDigits(dateTime.day, 2);
101
103
  return `WK${year}-${month}-${day}`;
102
104
  }
103
105
  case malloy_1.DateTimeframe.Day:
104
106
  case malloy_1.TimestampTimeframe.Day: {
105
- const year = numberFixedDigits(time.getUTCFullYear(), 2);
106
- const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
107
- const day = numberFixedDigits(time.getUTCDate(), 2);
107
+ const year = numberFixedDigits(dateTime.year, 2);
108
+ const month = numberFixedDigits(dateTime.month, 2);
109
+ const day = numberFixedDigits(dateTime.day, 2);
108
110
  return `${year}-${month}-${day}`;
109
111
  }
110
112
  case malloy_1.TimestampTimeframe.Hour: {
111
- const year = numberFixedDigits(time.getUTCFullYear(), 2);
112
- const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
113
- const day = numberFixedDigits(time.getUTCDate(), 2);
114
- const hour = numberFixedDigits(time.getUTCHours(), 2);
113
+ const year = numberFixedDigits(dateTime.year, 2);
114
+ const month = numberFixedDigits(dateTime.month, 2);
115
+ const day = numberFixedDigits(dateTime.day, 2);
116
+ const hour = numberFixedDigits(dateTime.hour, 2);
115
117
  return `${year}-${month}-${day} ${hour}:00 for 1 hour`;
116
118
  }
117
119
  case malloy_1.TimestampTimeframe.Minute: {
118
- const year = numberFixedDigits(time.getUTCFullYear(), 2);
119
- const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
120
- const day = numberFixedDigits(time.getUTCDate(), 2);
121
- const hour = numberFixedDigits(time.getUTCHours(), 2);
122
- const minute = numberFixedDigits(time.getUTCMinutes(), 2);
120
+ const year = numberFixedDigits(dateTime.year, 2);
121
+ const month = numberFixedDigits(dateTime.month, 2);
122
+ const day = numberFixedDigits(dateTime.day, 2);
123
+ const hour = numberFixedDigits(dateTime.hour, 2);
124
+ const minute = numberFixedDigits(dateTime.minute, 2);
123
125
  return `${year}-${month}-${day} ${hour}:${minute}`;
124
126
  }
125
127
  case malloy_1.TimestampTimeframe.Second: {
126
- const year = numberFixedDigits(time.getUTCFullYear(), 2);
127
- const month = numberFixedDigits(time.getUTCMonth() + 1, 2);
128
- const day = numberFixedDigits(time.getUTCDate(), 2);
129
- const hour = numberFixedDigits(time.getUTCHours(), 2);
130
- const minute = numberFixedDigits(time.getUTCMinutes(), 2);
131
- const second = numberFixedDigits(time.getUTCSeconds(), 2);
128
+ const year = numberFixedDigits(dateTime.year, 2);
129
+ const month = numberFixedDigits(dateTime.month, 2);
130
+ const day = numberFixedDigits(dateTime.day, 2);
131
+ const hour = numberFixedDigits(dateTime.hour, 2);
132
+ const minute = numberFixedDigits(dateTime.minute, 2);
133
+ const second = numberFixedDigits(dateTime.second, 2);
132
134
  return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
133
135
  }
134
136
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/render",
3
- "version": "0.0.43-dev230616164521",
3
+ "version": "0.0.43-dev230616201638",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,8 +18,10 @@
18
18
  "prepublishOnly": "npm run build"
19
19
  },
20
20
  "dependencies": {
21
- "@malloydata/malloy": "^0.0.43-dev230616164521",
21
+ "@malloydata/malloy": "^0.0.43-dev230616201638",
22
+ "@types/luxon": "^2.4.0",
22
23
  "lodash": "^4.17.20",
24
+ "luxon": "^2.4.0",
23
25
  "us-atlas": "^3.0.0",
24
26
  "vega": "^5.21.0",
25
27
  "vega-lite": "^5.2.0"