diff --git a/.github/workflows/auto-inspection.yml b/.github/workflows/auto-inspection.yml index 814433b158..797498937e 100644 --- a/.github/workflows/auto-inspection.yml +++ b/.github/workflows/auto-inspection.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@v2 - name: Get branch name (pull request) run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_ENV - - uses: lxfu1/surge-preview@v2.0.1 + - uses: lxfu1/surge-preview@v2.0.1 id: preview_step with: project_name: 'G2Plot' diff --git a/__tests__/data/violin.ts b/__tests__/data/violin.ts new file mode 100644 index 0000000000..aaa76b8d8d --- /dev/null +++ b/__tests__/data/violin.ts @@ -0,0 +1,602 @@ +export const BASE_VIOLIN_DATA = [ + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.5 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.1 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.9 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.3 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.2 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.7 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.1 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.6 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.6 }, + { species: 'I. setosa', type: 'SepalLength', value: 5 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.4 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.7 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.9 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.4 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.3 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.4 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.6 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.4 }, + { species: 'I. setosa', type: 'SepalLength', value: 5 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 2.9 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.4 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.1 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.1 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.9 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.7 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.4 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.6 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.4 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.8 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.1 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.8 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.1 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.1 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.3 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.2 }, + { species: 'I. setosa', type: 'SepalWidth', value: 4 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.8 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.4 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 4.4 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.7 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.4 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.3 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.9 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.4 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.3 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.5 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.1 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.3 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.7 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.8 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.7 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.3 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.8 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.1 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.7 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.4 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.4 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.4 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.7 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.1 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.6 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.6 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.5 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.7 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.3 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.1 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.9 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.4 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.8 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.6 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3 }, + { species: 'I. setosa', type: 'SepalLength', value: 5 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.4 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.6 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.4 }, + { species: 'I. setosa', type: 'SepalLength', value: 5 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.5 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.2 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.4 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.2 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.6 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.2 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.7 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.6 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.1 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.8 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.4 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.4 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.4 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.1 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 4.1 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.2 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 4.2 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.5 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.1 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.9 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.2 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.2 }, + { species: 'I. setosa', type: 'SepalLength', value: 5 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.3 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.5 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.5 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.1 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.6 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.9 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.3 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.4 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.4 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.1 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.3 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.3 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.5 }, + { species: 'I. setosa', type: 'SepalLength', value: 5 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.3 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.3 }, + { species: 'I. setosa', type: 'SepalWidth', value: 2.3 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.5 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.3 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.2 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.4 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.6 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.6 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.5 }, + { species: 'I. setosa', type: 'SepalLength', value: 5 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.4 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.9 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.8 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.1 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.3 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.8 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.6 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.8 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.1 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.2 }, + { species: 'I. setosa', type: 'SepalLength', value: 4.6 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.5 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.7 }, + { species: 'I. setosa', type: 'SepalLength', value: 5.3 }, + { species: 'I. setosa', type: 'PetalWidth', value: 0.2 }, + { species: 'I. setosa', type: 'PetalLength', value: 1.4 }, + { species: 'I. setosa', type: 'SepalWidth', value: 3.3 }, + { species: 'I. setosa', type: 'SepalLength', value: 5 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.4 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.7 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3.2 }, + { species: 'I. versicolor', type: 'SepalLength', value: 7 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.5 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.5 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3.2 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.4 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.5 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.9 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3.1 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.9 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.5 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.5 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.6 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.8 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.5 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.5 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.8 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.7 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.6 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.7 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3.3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.3 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3.3 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.4 }, + { species: 'I. versicolor', type: 'SepalLength', value: 4.9 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.6 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.9 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.4 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3.9 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.7 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.2 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3.5 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.5 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.2 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.9 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.2 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.4 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.7 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.9 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.1 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3.6 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.9 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.4 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.4 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3.1 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.7 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.5 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.5 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.1 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.7 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.8 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.5 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.5 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.2 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.2 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.1 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3.9 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.5 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.8 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.8 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3.2 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.9 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.8 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.1 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.5 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.9 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.5 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.3 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.2 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.7 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.8 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.1 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.3 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.9 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.4 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.4 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.4 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.4 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.8 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.8 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.8 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.7 }, + { species: 'I. versicolor', type: 'PetalLength', value: 5 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.7 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.5 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.5 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.9 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3.5 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.6 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.7 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.1 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3.8 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.4 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.5 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3.7 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.4 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.5 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.2 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3.9 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.7 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.8 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.6 }, + { species: 'I. versicolor', type: 'PetalLength', value: 5.1 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.7 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.5 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.5 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.4 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.6 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.5 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3.4 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.5 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.7 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3.1 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.7 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.4 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.3 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.1 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.5 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.5 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.2 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.4 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.6 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.5 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.4 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.6 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.1 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.2 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.6 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.8 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3.3 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.2 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.7 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.6 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.2 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.2 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 3 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.7 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.2 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.9 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.7 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.3 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.9 }, + { species: 'I. versicolor', type: 'SepalLength', value: 6.2 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.1 }, + { species: 'I. versicolor', type: 'PetalLength', value: 3 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.5 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.1 }, + { species: 'I. versicolor', type: 'PetalWidth', value: 1.3 }, + { species: 'I. versicolor', type: 'PetalLength', value: 4.1 }, + { species: 'I. versicolor', type: 'SepalWidth', value: 2.8 }, + { species: 'I. versicolor', type: 'SepalLength', value: 5.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.5 }, + { species: 'I. virginica', type: 'PetalLength', value: 6 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.3 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.3 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.9 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.1 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.7 }, + { species: 'I. virginica', type: 'SepalLength', value: 5.8 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.1 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.9 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.1 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.6 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.9 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.3 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.2 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.8 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.5 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.1 }, + { species: 'I. virginica', type: 'PetalLength', value: 6.6 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.6 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.7 }, + { species: 'I. virginica', type: 'PetalLength', value: 4.5 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.5 }, + { species: 'I. virginica', type: 'SepalLength', value: 4.9 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 6.3 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.9 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.3 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.8 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.5 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.5 }, + { species: 'I. virginica', type: 'PetalLength', value: 6.1 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.6 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.2 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.1 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.2 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.5 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.9 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.3 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.7 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.4 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.1 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.5 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.8 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2 }, + { species: 'I. virginica', type: 'PetalLength', value: 5 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.5 }, + { species: 'I. virginica', type: 'SepalLength', value: 5.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.4 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.1 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.8 }, + { species: 'I. virginica', type: 'SepalLength', value: 5.8 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.3 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.3 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.2 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.4 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.5 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.5 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.2 }, + { species: 'I. virginica', type: 'PetalLength', value: 6.7 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.8 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.3 }, + { species: 'I. virginica', type: 'PetalLength', value: 6.9 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.6 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.5 }, + { species: 'I. virginica', type: 'PetalLength', value: 5 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.2 }, + { species: 'I. virginica', type: 'SepalLength', value: 6 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.3 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.7 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.2 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.9 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2 }, + { species: 'I. virginica', type: 'PetalLength', value: 4.9 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.8 }, + { species: 'I. virginica', type: 'SepalLength', value: 5.6 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2 }, + { species: 'I. virginica', type: 'PetalLength', value: 6.7 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.8 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 4.9 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.7 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.3 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.1 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.7 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.3 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 6 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.2 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.2 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 4.8 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.8 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.2 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 4.9 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.1 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.1 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.6 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.8 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.4 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.6 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.8 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.2 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.9 }, + { species: 'I. virginica', type: 'PetalLength', value: 6.1 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.8 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.4 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2 }, + { species: 'I. virginica', type: 'PetalLength', value: 6.4 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.8 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.9 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.2 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.6 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.8 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.4 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.5 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.1 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.8 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.3 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.4 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.6 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.6 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.1 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.3 }, + { species: 'I. virginica', type: 'PetalLength', value: 6.1 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 7.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.4 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.6 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.4 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.3 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.5 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.1 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.4 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 4.8 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 6 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.1 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.4 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.1 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.9 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.4 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.6 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.1 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.3 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.1 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.1 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.9 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.9 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.1 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.7 }, + { species: 'I. virginica', type: 'SepalLength', value: 5.8 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.3 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.9 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.2 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.8 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.5 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.7 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.3 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.3 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.2 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.7 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.9 }, + { species: 'I. virginica', type: 'PetalLength', value: 5 }, + { species: 'I. virginica', type: 'SepalWidth', value: 2.5 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.3 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.2 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.5 }, + { species: 'I. virginica', type: 'PetalWidth', value: 2.3 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.4 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3.4 }, + { species: 'I. virginica', type: 'SepalLength', value: 6.2 }, + { species: 'I. virginica', type: 'PetalWidth', value: 1.8 }, + { species: 'I. virginica', type: 'PetalLength', value: 5.1 }, + { species: 'I. virginica', type: 'SepalWidth', value: 3 }, + { species: 'I. virginica', type: 'SepalLength', value: 5.9 }, +]; diff --git a/__tests__/unit/plots/violin/animation-spec.ts b/__tests__/unit/plots/violin/animation-spec.ts new file mode 100644 index 0000000000..1d8d520f94 --- /dev/null +++ b/__tests__/unit/plots/violin/animation-spec.ts @@ -0,0 +1,85 @@ +import { Violin } from '../../../../src'; +import { BASE_VIOLIN_DATA } from '../../../data/violin'; +import { createDiv } from '../../../utils/dom'; + +describe('violin legend', () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + animation: { + enter: { + animation: 'fade-in', + }, + leave: { + animation: 'fade-out', + }, + }, + }); + + violin.render(); + + it('default', () => { + // 新的 geometry violin 暂时未追加 + expect(violin.chart.views[0].geometries[0].animateOption).toEqual({ + enter: { + animation: 'fade-in', + }, + leave: { + animation: 'fade-out', + }, + }); + + // 追加默认的动画配置 + expect(violin.chart.views[1].geometries[0].animateOption).toMatchObject({ + appear: { + duration: 450, + easing: 'easeQuadOut', + }, + update: { + duration: 400, + easing: 'easeQuadInOut', + }, + enter: { + duration: 400, + easing: 'easeQuadInOut', + animation: 'fade-in', + }, + leave: { + duration: 350, + easing: 'easeQuadIn', + animation: 'fade-out', + }, + }); + }); + + it('update', () => { + violin.update({ + animation: { + appear: { + animation: 'fade-in', + }, + leave: { + animation: 'wave-out', + }, + }, + }); + expect(violin.chart.views[0].geometries[0].animateOption).toEqual({ + appear: { + animation: 'fade-in', + }, + enter: { + animation: 'fade-in', + }, + leave: { + animation: 'wave-out', + }, + }); + }); + + afterAll(() => { + violin.destroy(); + }); +}); diff --git a/__tests__/unit/plots/violin/annotation-spec.ts b/__tests__/unit/plots/violin/annotation-spec.ts new file mode 100644 index 0000000000..7f3ca86dce --- /dev/null +++ b/__tests__/unit/plots/violin/annotation-spec.ts @@ -0,0 +1,65 @@ +import { Violin } from '../../../../src'; +import { BASE_VIOLIN_DATA } from '../../../data/violin'; +import { createDiv } from '../../../utils/dom'; + +describe('violin legend', () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + }); + + violin.render(); + + it('text annotation', () => { + violin.update({ + annotations: [ + { + type: 'text', + position: ['median', 'median'], + content: '辅助文本', + }, + ], + }); + + const controller = violin.chart.views[0].getController('annotation'); + expect(controller.getComponents().length).toBe(1); + expect(controller.getComponents()[0].component.get('content')).toBe('辅助文本'); + }); + + it('text annotation and line annotation', () => { + violin.update({ + ...violin.options, + annotations: [ + { + type: 'text', + position: ['min', 'median'], + content: '辅助文本', + offsetY: -4, + style: { + textBaseviolin: 'bottom', + }, + }, + { + type: 'line', + start: ['min', 'median'], + end: ['max', 'median'], + style: { + stroke: 'red', + violinDash: [2, 2], + }, + }, + ], + }); + const controller = violin.chart.views[0].getController('annotation'); + expect(controller.getComponents().length).toBe(2); + expect(controller.getComponents()[0].component.get('content')).toBe('辅助文本'); + expect(controller.getComponents()[1].component.get('type')).toBe('line'); + }); + + afterAll(() => { + violin.destroy(); + }); +}); diff --git a/__tests__/unit/plots/violin/axis-spec.ts b/__tests__/unit/plots/violin/axis-spec.ts new file mode 100644 index 0000000000..3d93a6c0bc --- /dev/null +++ b/__tests__/unit/plots/violin/axis-spec.ts @@ -0,0 +1,65 @@ +import { Violin } from '../../../../src'; +import { BASE_VIOLIN_DATA } from '../../../data/violin'; +import { createDiv } from '../../../utils/dom'; + +describe('violin axis', () => { + it('没有 seriesField', () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + }); + + violin.render(); + + let axisController = violin.chart.views[0].getController('axis'); + expect(axisController.getComponents().length).toBe(4); + + violin.update({ xAxis: { grid: null } }); + axisController = violin.chart.views[0].getController('axis'); + expect(axisController.getComponents().length).toBe(3); + + violin.update({ xAxis: { title: { text: 'xx' } } }); + axisController = violin.chart.views[0].getController('axis'); + expect(axisController.getComponents()[0].component.get('title').text).toBe('xx'); + + // 关闭 xAxis + violin.update({ xAxis: false }); + axisController = violin.chart.views[0].getController('axis'); + expect(axisController.getComponents().length).toBe(2); + + violin.destroy(); + }); + + it('有 seriesField', () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + seriesField: 'species', + }); + + violin.render(); + let axisController = violin.chart.views[0].getController('axis'); + expect(axisController.getComponents().length).toBe(4); + + violin.update({ xAxis: { grid: null } }); + axisController = violin.chart.views[0].getController('axis'); + expect(axisController.getComponents().length).toBe(3); + + violin.update({ xAxis: { title: { text: 'xx' } } }); + axisController = violin.chart.views[0].getController('axis'); + expect(axisController.getComponents()[0].component.get('title').text).toBe('xx'); + + // 关闭 xAxis + violin.update({ xAxis: false }); + axisController = violin.chart.views[0].getController('axis'); + expect(axisController.getComponents().length).toBe(2); + + violin.destroy(); + }); +}); diff --git a/__tests__/unit/plots/violin/box-spec.ts b/__tests__/unit/plots/violin/box-spec.ts new file mode 100644 index 0000000000..67d0b1df42 --- /dev/null +++ b/__tests__/unit/plots/violin/box-spec.ts @@ -0,0 +1,50 @@ +import { Violin } from '../../../../src'; +import { MIN_MAX_VIEW_ID, QUANTILE_VIEW_ID, MEDIAN_VIEW_ID } from '../../../../src/plots/violin/constant'; +import { BASE_VIOLIN_DATA } from '../../../data/violin'; +import { createDiv } from '../../../utils/dom'; + +describe('violin', () => { + it('renders box views.', () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + }); + + violin.render(); + const minMaxView = violin.chart.views.find((view) => view.id === MIN_MAX_VIEW_ID); + const quantileView = violin.chart.views.find((view) => view.id === QUANTILE_VIEW_ID); + const medianView = violin.chart.views.find((view) => view.id === MEDIAN_VIEW_ID); + + expect(minMaxView.geometries[0].type).toBe('interval'); + expect(quantileView.geometries[0].type).toBe('interval'); + expect(medianView.geometries[0].type).toBe('point'); + + violin.destroy(); + }); + + // 暂时不开放 box 配置 + it("should not render box views when 'box' set to false.", () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + box: false, + }); + + violin.render(); + const minMaxView = violin.chart.views.find((view) => view.id === MIN_MAX_VIEW_ID); + const quantileView = violin.chart.views.find((view) => view.id === QUANTILE_VIEW_ID); + const medianView = violin.chart.views.find((view) => view.id === MEDIAN_VIEW_ID); + + expect(minMaxView).toBeUndefined(); + expect(quantileView).toBeUndefined(); + expect(medianView).toBeUndefined(); + + violin.destroy(); + }); +}); diff --git a/__tests__/unit/plots/violin/change-data-spec.ts b/__tests__/unit/plots/violin/change-data-spec.ts new file mode 100644 index 0000000000..5e150c3e17 --- /dev/null +++ b/__tests__/unit/plots/violin/change-data-spec.ts @@ -0,0 +1,30 @@ +import { group } from '@antv/util'; +import { Violin } from '../../../../src'; +import { VIOLIN_VIEW_ID } from '../../../../src/plots/violin/constant'; +import { BASE_VIOLIN_DATA } from '../../../data/violin'; +import { createDiv } from '../../../utils/dom'; + +describe('violin change data', () => { + it('renders new violins when data changed', () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + }); + + violin.render(); + const g = violin.chart.views.find((view) => view.id === VIOLIN_VIEW_ID).geometries[0]; + expect(g.elements.length).toBe(group(BASE_VIOLIN_DATA, 'type').length); + + const newData = BASE_VIOLIN_DATA.filter((data) => data.type !== 'PetalWidth'); + + violin.changeData(newData); + const newG = violin.chart.views.find((view) => view.id === VIOLIN_VIEW_ID).geometries[0]; + expect(violin.options.data).toEqual(newData); + expect(newG.elements.length).toBe(group(newData, 'type').length); + + violin.destroy(); + }); +}); diff --git a/__tests__/unit/plots/violin/index-spec.ts b/__tests__/unit/plots/violin/index-spec.ts new file mode 100644 index 0000000000..b44abaf4c7 --- /dev/null +++ b/__tests__/unit/plots/violin/index-spec.ts @@ -0,0 +1,117 @@ +import { group } from '@antv/util'; +import { Violin } from '../../../../src'; +import { + DEFAULT_OPTIONS, + MEDIAN_FIELD, + MIN_MAX_FIELD, + QUANTILE_FIELD, + VIOLIN_VIEW_ID, + VIOLIN_Y_FIELD, + X_FIELD, +} from '../../../../src/plots/violin/constant'; +import { BASE_VIOLIN_DATA } from '../../../data/violin'; +import { createDiv } from '../../../utils/dom'; + +describe('violin', () => { + it("renders N violins, where N equals to xField's length.", () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + }); + + violin.render(); + expect(violin.type).toBe('violin'); + // @ts-ignore + expect(violin.getDefaultOptions()).toEqual(Violin.getDefaultOptions()); + + const g = violin.chart.views.find((view) => view.id === VIOLIN_VIEW_ID).geometries[0]; + + // 个数 + expect(g.elements.length).toBe(group(BASE_VIOLIN_DATA, 'type').length); + // 类型 + expect(g.type).toBe('violin'); + + violin.destroy(); + }); + + it("renders N violins, where N equals to (xField * sierisField)'s length.", () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + seriesField: 'species', + }); + + violin.render(); + const g = violin.chart.views.find((view) => view.id === VIOLIN_VIEW_ID).geometries[0]; + + // 个数 + expect(g.elements.length).toBe(group(BASE_VIOLIN_DATA, ['type', 'species']).length); + // 类型 + expect(g.type).toBe('violin'); + + violin.destroy(); + }); + + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + xAxis: { + tickCount: 5, + }, + yAxis: { + tickCount: 7, + // fixme 设置 min 为 10 不生效 + // min: 10, + minLimit: 10, + max: 20, + }, + }); + + violin.render(); + + it('axis & meta', () => { + const geometry = violin.chart.views[0].geometries[0]; + const geometry1 = violin.chart.views[1].geometries[0]; + const geometry2 = violin.chart.views[2].geometries[0]; + const geometry3 = violin.chart.views[3].geometries[0]; + expect(geometry.scales[X_FIELD].tickCount).toBe(5); + expect(geometry.scales[VIOLIN_Y_FIELD].min).toBe(10); + expect(geometry.scales[VIOLIN_Y_FIELD].max).toBe(20); + expect(geometry.scales[VIOLIN_Y_FIELD].tickCount).toBe(7); + + expect(geometry1.scales[MIN_MAX_FIELD].min).toBe(10); + expect(geometry1.scales[MIN_MAX_FIELD].max).toBe(20); + expect(geometry1.scales[MIN_MAX_FIELD].tickCount).toBe(7); + // @ts-ignore + expect(geometry1.scales[MIN_MAX_FIELD].sync).toBe(VIOLIN_Y_FIELD); + + expect(geometry2.scales[QUANTILE_FIELD].min).toBe(10); + expect(geometry2.scales[QUANTILE_FIELD].max).toBe(20); + expect(geometry2.scales[QUANTILE_FIELD].tickCount).toBe(7); + // @ts-ignore + expect(geometry2.scales[QUANTILE_FIELD].sync).toBe(VIOLIN_Y_FIELD); + + expect(geometry3.scales[MEDIAN_FIELD].min).toBe(10); + expect(geometry3.scales[MEDIAN_FIELD].max).toBe(20); + expect(geometry3.scales[MEDIAN_FIELD].tickCount).toBe(7); + // @ts-ignore + expect(geometry3.scales[MEDIAN_FIELD].sync).toBe(VIOLIN_Y_FIELD); + }); + + it('defaultOptions 保持从 constants 中获取', () => { + expect(Violin.getDefaultOptions()).toEqual(DEFAULT_OPTIONS); + }); + + afterAll(() => { + violin.destroy(); + }); +}); diff --git a/__tests__/unit/plots/violin/legend-spec.ts b/__tests__/unit/plots/violin/legend-spec.ts new file mode 100644 index 0000000000..3455d4ccdb --- /dev/null +++ b/__tests__/unit/plots/violin/legend-spec.ts @@ -0,0 +1,144 @@ +import { Violin } from '../../../../src'; +import { X_FIELD } from '../../../../src/plots/violin/constant'; +import { BASE_VIOLIN_DATA } from '../../../data/violin'; +import { createDiv } from '../../../utils/dom'; + +describe('violin legend', () => { + it('没有 seriesField', () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + }); + + violin.render(); + + const legendController = violin.chart.getController('legend'); + const legendComponent = legendController.getComponents()[0].component; + let legendItems = legendComponent.get('items'); + expect(legendItems.length).toBe(4); + + violin.update({ legend: { position: 'left' } }); + expect(legendController.getComponents()[0].direction).toBe('left'); + + // 自定义 legend + violin.update({ + legend: { + custom: true, + position: 'bottom', + items: [ + { + value: '1', + name: '3', + marker: { symbol: 'square', style: { fill: 'red', r: 5 } }, + }, + { + value: '2', + name: '3', + marker: { symbol: 'square', style: { fill: '#000', r: 5 } }, + }, + { + value: '3', + name: '3', + marker: { symbol: 'circle', style: { stroke: '#eee', r: 5 } }, + }, + ], + }, + }); + expect(legendController.getComponents()[0].direction).toBe('bottom'); + legendItems = legendController.getComponents()[0].component.get('items'); + expect(legendItems.length).toBe(3); + expect(legendItems[0].marker.symbol).toBe('square'); + expect(legendItems[0].marker.style.fill).toBe('red'); + expect(legendItems[2].marker.style.stroke).toBe('#eee'); + expect(legendItems[2].marker.symbol).toBe('circle'); + + // 关闭 legend + violin.update({ legend: false }); + expect(legendComponent.get('items')).toBeUndefined(); + + violin.destroy(); + }); + + it('有 seriesField', () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + seriesField: 'species', + }); + + violin.render(); + + const legendController = violin.chart.getController('legend'); + const legendComponent = legendController.getComponents()[0].component; + let legendItems = legendComponent.get('items'); + expect(legendItems.length).toBe(3); + + violin.update({ legend: { position: 'left' } }); + expect(legendController.getComponents()[0].direction).toBe('left'); + + // 自定义 legend + violin.update({ + legend: { + custom: true, + position: 'bottom', + items: [ + { + value: '1', + name: '3', + marker: { symbol: 'square', style: { fill: 'red', r: 5 } }, + }, + { + value: '3', + name: '3', + marker: { symbol: 'circle', style: { stroke: '#eee', r: 5 } }, + }, + ], + }, + }); + expect(legendController.getComponents()[0].direction).toBe('bottom'); + legendItems = legendController.getComponents()[0].component.get('items'); + expect(legendItems.length).toBe(2); + expect(legendItems[0].marker.symbol).toBe('square'); + expect(legendItems[0].marker.style.fill).toBe('red'); + expect(legendItems[1].marker.style.stroke).toBe('#eee'); + expect(legendItems[1].marker.symbol).toBe('circle'); + + // 关闭 legend + violin.update({ legend: false }); + expect(legendComponent.get('items')).toBeUndefined(); + + violin.destroy(); + }); + + it('除了 view0, 其他没有图例', () => { + const violin = new Violin(createDiv(), { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + }); + + violin.render(); + + violin.chart.views.forEach((view, idx) => { + if (idx !== 0) { + // @ts-ignore + expect(view.options.legends).toBe(false); + } + }); + + violin.update({ legend: { position: 'left', marker: { style: { fill: 'red' } } } }); + // @ts-ignore + expect(violin.chart.options.legends[X_FIELD]).toMatchObject({ + position: 'left', + marker: { style: { fill: 'red' } }, + }); + }); +}); diff --git a/__tests__/unit/plots/violin/tooltip-spec.ts b/__tests__/unit/plots/violin/tooltip-spec.ts new file mode 100644 index 0000000000..a7b23c31ca --- /dev/null +++ b/__tests__/unit/plots/violin/tooltip-spec.ts @@ -0,0 +1,96 @@ +import { Violin } from '../../../../src'; +import { BASE_VIOLIN_DATA } from '../../../data/violin'; +import { createDiv } from '../../../utils/dom'; + +describe('violin tooltip', () => { + const div = createDiv(); + const violin = new Violin(div, { + width: 400, + height: 500, + data: BASE_VIOLIN_DATA, + xField: 'type', + yField: 'value', + }); + + violin.render(); + + it('default', () => { + const box = violin.chart.views[0].geometries[0].elements[0].shape.getBBox(); + const point = { x: box.x + box.width / 2, y: box.y + box.height / 2 }; + + violin.chart.showTooltip(point); + expect(div.querySelectorAll('.g2-tooltip-list-item').length).toBe(5); + violin.chart.hideTooltip(); + }); + + it('tooltip: fields', () => { + violin.update({ + seriesField: 'species', + tooltip: { + fields: ['species', 'high', 'q1', 'q3', 'low', 'median'], + }, + }); + const box = violin.chart.views[0].geometries[0].elements[0].shape.getBBox(); + const point = { x: box.x + box.width / 2, y: box.y + box.height / 2 }; + violin.chart.showTooltip(point); + expect(div.querySelectorAll('.g2-tooltip-list-item').length).toBe(6); + violin.chart.hideTooltip(); + }); + + it('tooltip + meta', () => { + violin.update({ + meta: { + high: { + alias: '最大值', + formatter: (v) => `${v.toFixed(2)} %`, + }, + low: { + alias: '最小值', + formatter: (v) => `${v.toFixed(2)} %`, + }, + species: { + alias: '品类', + }, + }, + }); + + const box = violin.chart.views[0].geometries[0].elements[0].shape.getBBox(); + const point = { x: box.x + box.width / 2, y: box.y + box.height / 2 }; + violin.chart.showTooltip(point); + const items = div.querySelectorAll('.g2-tooltip-name'); + expect((items[0] as HTMLElement).innerText).toBe('品类'); + expect((items[1] as HTMLElement).innerText).toBe('最大值'); + expect((items[4] as HTMLElement).innerText).toBe('最小值'); + expect((div.querySelectorAll('.g2-tooltip-value')[4] as HTMLElement).innerText).toMatch('%'); + violin.chart.hideTooltip(); + }); + + it('tooltip: customContent', () => { + violin.update({ + tooltip: { + customContent: () => '