Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto test docs tutorial #598

Merged
merged 49 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3ed54e7
Auto test the tutorial, refactor MdChart
veghdev Oct 29, 2024
73a23fa
replace include prefix, cause formatting issues
veghdev Oct 30, 2024
a66a6b0
rewrite aggregating data
veghdev Oct 30, 2024
07d6bf7
tutorial, use snippet config
veghdev Oct 30, 2024
5f43645
refactor mdchart, add replace config
veghdev Oct 30, 2024
d32ac50
rewrite tutorial geometry
veghdev Oct 30, 2024
43cacc3
tutorial, rewrite channels legend
veghdev Oct 30, 2024
e2f480e
tutorial, remove config
veghdev Oct 30, 2024
56af4b5
tutorial, reqrite group stack
veghdev Oct 30, 2024
47ce75f
tutorial, rewrite sorting
veghdev Oct 30, 2024
eb9fe27
tutorial, rewrite align range
veghdev Oct 30, 2024
979cdef
tutorial, rewrite changing dimensions
veghdev Oct 30, 2024
1ab1d1b
tutorial, rewrite orientation split polar
veghdev Oct 30, 2024
78b1394
tutorial, rewrite without coordinates
veghdev Oct 30, 2024
cdc3887
tutorial, remove old js
veghdev Oct 30, 2024
3b76c70
tutorial, rewrite color palette fonts
veghdev Oct 31, 2024
f1d2358
tutorial, rewirte chart layout
veghdev Oct 31, 2024
ea52536
tutorial, rewrite anim options
veghdev Oct 31, 2024
d7f4311
tutorial, rewrite chart presets
veghdev Oct 31, 2024
3e66c96
tutorial, add data parameter
veghdev Oct 31, 2024
a3ee166
tutorial, rewrite stacking explanation
veghdev Oct 31, 2024
7a2bff9
tutorial, refactor setup code snippets, rewrite setup a
veghdev Oct 31, 2024
7a623ac
tutorial, rewrite setup b
veghdev Oct 31, 2024
25dd3c8
tutorial, rewrite setup c
veghdev Oct 31, 2024
de8dd23
tutorial, refactor, use config js, add first test case
veghdev Nov 4, 2024
fe3a183
refactor tutorial test
veghdev Nov 4, 2024
a28f09e
Add tutorial test cases
veghdev Nov 4, 2024
62c75b2
tutorial, rewrite anim control
veghdev Nov 4, 2024
2a5a562
tutorial, rewrite shorthands
veghdev Nov 4, 2024
c08ae55
fix lint
veghdev Nov 4, 2024
00febd9
tutorial, rewrite filter
veghdev Nov 4, 2024
7a7589d
add test for filter tutorial chapter
veghdev Nov 4, 2024
9612dfd
tutorial, event base
veghdev Nov 5, 2024
c491d8d
tutorial, rewrite events, test not working
veghdev Nov 5, 2024
0d28ab0
tutiral, add test for events
veghdev Nov 6, 2024
577c312
tutorial, fix geometry chapter
veghdev Nov 6, 2024
7c87694
tutorial, fix axes title chapter
veghdev Nov 6, 2024
3740c8c
tutorial, fix aggregating data chapter
veghdev Nov 6, 2024
e6dc77d
tutorial, fix channel legen chapter
veghdev Nov 6, 2024
29a0dd0
tutorial, fix group stack chapter
veghdev Nov 6, 2024
fb6fa73
tutorial, fic chapter sorting
veghdev Nov 6, 2024
baf57ed
tutorial, fix orientation chapter
veghdev Nov 6, 2024
4610f97
tutorial, fix without coordinates chapter
veghdev Nov 6, 2024
c21f54d
tutorial, fix layout chapter
veghdev Nov 6, 2024
1f9caf0
tutorial, fix anim opt chapter
veghdev Nov 6, 2024
dffa33b
tutorial, fix anim control chapter
veghdev Nov 6, 2024
4a23318
tutorial, fix shorthands chapter
veghdev Nov 6, 2024
eb91377
tutorial tests, add hashes
veghdev Nov 6, 2024
60276aa
fix test run
veghdev Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ module.exports = {
files: ['*.js', '*.mjs', '*.cjs'],
extends: ['@vizzu/eslint-config/standard']
},
{
files: ['docs/tutorial/shorthands_store/03_b.js'],
extends: ['@vizzu/eslint-config/standard'],
rules: {
'no-var': 'off',
'no-unused-vars': 'off'
}
},
{
files: ['test/e2e/test_cases/**', 'test/e2e/test_data/**'],
extends: ['@vizzu/eslint-config/standard'],
Expand Down
15 changes: 8 additions & 7 deletions docs/assets/javascripts/mdchart.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import Vizzu from '../dist/vizzu.min.js'
import { loadAnimations } from './snippet.js'

class MdChart {
constructor(data, id) {
this.data = data
this.id = id
}

create(snippets) {
async create(snippets) {
const animations = await loadAnimations(snippets)
let chart = Promise.resolve()
for (let i = 0; i < snippets.length; i++) {
for (let i = 0; i < animations.length; i++) {
const number = i + 1
chart = this.animate(('0' + number).slice(-2), snippets[i], chart)
chart = this.animate(('0' + number).slice(-2), animations[i], chart)
}
}

Expand All @@ -30,9 +32,8 @@ class MdChart {
if (prevChart) {
animTarget.config = Object.assign({}, prevChart.config)
animTarget.style = Object.assign({}, prevChart.style)
// remove if it can be found in the prevChart
if (snippet.initDataFilter) {
animTarget.data = { filter: snippet.initDataFilter }
if (snippet?.assets?.initDataFilter) {
animTarget.data = { filter: snippet.assets.initDataFilter }
}
}
}
Expand Down Expand Up @@ -70,7 +71,7 @@ class MdChart {
})
for (let i = 0; i < snippet.anims.length; i++) {
chart = chart.then((chart) => {
chart = snippet.anims[i](chart, {})
chart = snippet.anims[i](chart, this.data, snippet?.assets)
if (this.id === 'tutorial' && firstRun && chart.activated) {
chart.activated.then((control) => control.seek('100%'))
}
Expand Down
74 changes: 74 additions & 0 deletions docs/assets/javascripts/snippet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
export async function loadAnimation(url, config) {
try {
let code
if (
typeof window === 'undefined' &&
typeof process !== 'undefined' &&
process.versions?.node
) {
const fs = await import('fs').then((module) => module.promises)
code = await fs.readFile(
config?.nodeBaseUrl ? `${config.nodeBaseUrl}/${url}` : url,
'utf8'
)
} else {
const response = await fetch(
config?.browserBaseUrl ? `${config.browserBaseUrl}/${url}` : url
)
if (!response.ok) throw new Error(`Error fetching: ${response.statusText}`)
code = await response.text()
}
const replace = config?.replace
if (Array.isArray(replace)) {
replace.forEach(([searchValue, replaceValue]) => {
code = code.replaceAll(searchValue, replaceValue)
})
}
const returnOriginal = config?.returnOriginal
return new Function( // eslint-disable-line no-new-func
'chart',
'data',
'assets',
returnOriginal ? `${code}; return chart;` : `return ${code}`
)
} catch (error) {
console.error('Error during animation load or execution:', error)
}
}

export async function loadAnimations(
animations,
nodeBaseUrl = undefined,
browserBaseUrl = undefined
) {
const steps = []
const baseUrl = {
nodeBaseUrl,
browserBaseUrl
}

for (const animation of animations) {
const step = { anims: [] }

let subAnimations
if (Array.isArray(animation)) {
subAnimations = animation
} else {
subAnimations = animation?.anims ?? []
if (animation?.assets) step.assets = animation.assets
}

for (const subAnimation of subAnimations) {
let anim
if (typeof subAnimation === 'string') {
anim = await loadAnimation(`${subAnimation}.js`, baseUrl)
} else if (typeof animation === 'object' && subAnimation.name) {
const { name, ...config } = subAnimation
anim = await loadAnimation(`${name}.js`, Object.assign({}, config, baseUrl))
}
step.anims.push((chart, data, assets) => anim(chart, data, assets))
}
steps.push(step)
}
return steps
}
12 changes: 12 additions & 0 deletions docs/tutorial/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
globals: {
chart: true,
Vizzu: true,
assets: true,
image: true,
clickHandler: true,
labelDrawHandler: true,
logoDrawHandler: true,
backgroundImageHandler: true
}
}
167 changes: 0 additions & 167 deletions docs/tutorial/aggregating_data.js

This file was deleted.

Loading