@makechart/viewer 0.0.4 → 0.0.6

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Change Logs
2
2
 
3
+ ## v0.0.6
4
+
5
+ - dash cases load the panel block from `@plotdb/dash`'s `block/panel/index.html` ( versioned in the package )
6
+ instead of `web/static/initiative/1st/...`, a generated demo path that has been renamed
7
+ - add `timeout` ( case or suite, default 30000ms ): a case that takes longer is an `error` naming the stage
8
+ it stopped at ( `load`, `render` or `step n` ), instead of hanging the whole run
9
+ - `settle` also resolves by a timer after `limit`, in case `requestAnimationFrame` stops firing
10
+
11
+
12
+ ## v0.0.5
13
+
14
+ - `block`: the chart's block data ( e.g. a map's `{level: 'town'}` ), on the suite or on a case ( the case
15
+ wins ). charts that take block data could only be tested with an empty one
16
+ - playground: `?block=<json>` for the same
17
+
18
+
3
19
  ## v0.0.4
4
20
 
5
21
  - upgrade `@makechart/base` to `^0.2.0` ( `lite/index.html` / `d3/index.html` ) and `@plotdb/chart` to
package/README.md CHANGED
@@ -78,8 +78,14 @@ engine 自己起一個 server,前端依賴走與 makechart 相同的路徑 `/a
78
78
  - `ctx`:`root` ( 這個 case 的容器 )、`snap(label)`、`drag(node, [x0, y0], [x1, y1])` ( 相對座標 0~1,送 pointer 事件 )、`chart(id)` ( dash 時取某個 panel 的圖 )、`wait(ms)`、`random(seed)`。
79
79
  - helper:`mctest.combo {type: <[column bar]>, multiple: <[stack group]>}` 產生所有組合,`mctest.label o` 把組合轉成名字,`mctest.random seed` 是固定種子的亂數。
80
80
  - `skip: true` 略過。`suite.chart` 預設是 package.json 的 name。
81
-
82
- 資料請用固定種子產生,否則每次跑都不一樣。
81
+ - `block`:圖的 block data ( 例如地圖的 `{level: \town}` ),suite 與 case 都可以給,case 的優先。
82
+ playground 用網址參數 `?block=<json>`。
83
+ - `timeout`:整個 case ( 載入、第一次畫完、所有 step ) 超過這麼多 ms 就算 `error`,訊息會寫停在哪一步。
84
+ suite 與 case 都可以給,預設 30000。
85
+
86
+ 資料請用固定種子產生,否則每次跑都不一樣。在 step 裡 ( 執行時 ) 才產生的資料要用自己的種子
87
+ ( `mctest.random seed` ),不要跟載入時共用同一個產生器:共用的話數字會隨之前跑過哪些 case 而變,
88
+ 單獨跑 ( `-g` ) 跟全部跑的結果會不同。
83
89
 
84
90
 
85
91
  ## 怎麼比對
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makechart/viewer",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "makechart 圖表的 test suite engine: 用不同資料、參數跑圖, 比對輸出 snapshot, 並以 @plotdb/dash 測 crossfilter",
5
5
  "homepage": "https://github.com/makechart/viewer",
6
6
  "repository": {
package/src/playground.ls CHANGED
@@ -214,7 +214,14 @@ mctest.boot!
214
214
  $(\#target).textContent = "#{mctest.info.name}@#{mctest.info.version}"
215
215
  document.title = "playground · #{mctest.info.name}"
216
216
  mctest.manager.get {name: mctest.info.name, version: \main}
217
- .then (bc) -> bc.create {data: {}}
217
+ # ?block=<json>: 圖的 block data, 例如 ?block={"level":"town"}
218
+ .then (bc) ->
219
+ data = {}
220
+ try
221
+ data = JSON.parse((new URLSearchParams(location.search)).get(\block) or '{}')
222
+ catch e
223
+ console.warn "[mctest] bad ?block=", e
224
+ bc.create {data}
218
225
  .then (bi) -> bi.attach({root: $(\#stage)}).then -> bi.interface!
219
226
  .then (chart) ->
220
227
  pg.chart = window.chart = chart
package/src/suite.ls CHANGED
@@ -161,22 +161,30 @@ mctest.split-snaps = (text) ->
161
161
  # 150ms 後才發 filter, board 再重畫 ). 期間每一幀都 flush, 有 anim 的圖補間會直接跳到終點.
162
162
  # list 是回傳目前所有圖的 function ( dash 的 panel 圖是非同步建立的, 每次都重抓 ),
163
163
  # 新抓到的圖一律切 manual. 沒有 anim 的圖 ( 還在用 d3 transition ) 只能靠 quiet 等它跑完
164
+ # rAF 停掉時 ( 例如頁面被當成在背景 ) tick 不會再跑, 所以另用 timer 保底, limit 一定會生效
164
165
  settle = (root, list, quiet = 250, limit = 10000) ->
165
166
  new Promise (res) ->
166
167
  last = performance.now!
167
168
  t0 = last
168
169
  mo = new MutationObserver -> last := performance.now!
169
170
  mo.observe root, {subtree: true, childList: true, attributes: true, characterData: true}
171
+ done = false
172
+ finish = ->
173
+ if done => return
174
+ done := true
175
+ mo.disconnect!
176
+ clearTimeout timer
177
+ res!
178
+ timer = setTimeout finish, limit + 1000
170
179
  tick = ->
180
+ if done => return
171
181
  charts = list!filter -> it
172
182
  charts.map ->
173
183
  if !it.anim => return
174
184
  if !it.anim._manual => it.anim.manual true
175
185
  it.anim.flush!
176
186
  now = performance.now!
177
- if now - last >= quiet or now - t0 > limit =>
178
- mo.disconnect!
179
- return res!
187
+ if now - last >= quiet or now - t0 > limit => return finish!
180
188
  requestAnimationFrame tick
181
189
  requestAnimationFrame tick
182
190
 
@@ -199,9 +207,11 @@ get-data = (s, d) ->
199
207
 
200
208
  chart-ref = (s) -> ({version: \main} <<< (s.chart or {name: mctest.info.name}))
201
209
 
202
- make-chart = (s, root) ->
210
+ # block: 圖的 block data ( 例如地圖的 level ), suite 與 case 都可以給, case 的優先
211
+ make-chart = (s, root, c = {}) ->
212
+ data = {} <<< (s.block or {}) <<< (c.block or {})
203
213
  mgr.get chart-ref(s)
204
- .then (bc) -> bc.create {data: {}}
214
+ .then (bc) -> bc.create {data}
205
215
  .then (bi) -> bi.attach {root} .then -> bi.interface!
206
216
  .then (chart) ->
207
217
  if chart.anim => chart.anim.manual true
@@ -221,7 +231,20 @@ load-dash = ->
221
231
  document.head.appendChild js
222
232
 
223
233
  # 跑一個 case. root 是給它用的容器 ( 大小由這裡設 ). 回傳 {snaps, chart | board}
234
+ # 整個 case 超過 timeout ms ( case 或 suite 的 `timeout`, 預設 30000 ) 就算 error, 並寫出停在哪一步,
235
+ # 否則一個不會 resolve 的 step ( 或載不到的模組 ) 會讓整個 run 停住
224
236
  mctest.run-case = (c, root) ->
237
+ t = c.timeout ? c.suite.timeout ? 30000
238
+ at = {v: \load}
239
+ timer = null
240
+ Promise.race [
241
+ run-case c, root, at
242
+ new Promise (res, rej) ->
243
+ timer := setTimeout (-> rej new Error("[mctest] timeout after #{t}ms ( at #{at.v} )")), t
244
+ ]
245
+ .finally -> clearTimeout timer
246
+
247
+ run-case = (c, root, at) ->
225
248
  s = c.suite
226
249
  [w, h] = c.size or (c.dash and c.dash.size) or s.size
227
250
  root.style <<< {width: "#{w}px", height: "#{h}px"}
@@ -242,7 +265,8 @@ mctest.run-case = (c, root) ->
242
265
  random: mctest.random
243
266
  run-steps = (target) ->
244
267
  # 先等第一次畫完, step 才找得到節點
245
- ([].concat(c.steps or [])).reduce ((p, f) -> p.then(-> f target, ctx).then -> settle(root, list, q)), settle(root, list, q)
268
+ at.v = \render
269
+ ([].concat(c.steps or [])).reduce ((p, f, i) -> p.then(-> at.v = "step #{i + 1}"; f target, ctx).then -> settle(root, list, q)), settle(root, list, q)
246
270
  .then -> snaps.push {label: \final, markup: normalize(root, s.normalize)}
247
271
  .then -> {snaps, target}
248
272
  if c.dash => return load-dash!then (dash) ->
@@ -250,12 +274,12 @@ mctest.run-case = (c, root) ->
250
274
  root: root
251
275
  manager: mgr
252
276
  def: JSON.parse(JSON.stringify(c.dash.def))
253
- panel: {name: "@plotdb/dash", version: \main, path: "web/static/initiative/1st/block/panel/0.0.1/index.html"}
277
+ panel: {name: "@plotdb/dash", version: \main, path: "block/panel/index.html"}
254
278
  ctx.chart = (id) -> ((board.panels.filter(-> it.id == id).0 or {}).itf or {}).chart
255
279
  list := -> board.panels.map -> (it.itf or {}).chart
256
280
  board.init!then -> settle root, list, q
257
281
  .then -> run-steps board
258
- make-chart s, root
282
+ make-chart s, root, c
259
283
  .then (chart) ->
260
284
  charts.push chart
261
285
  cfg = merge {}, (s.config or {}), (c.config or {})