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

Cwalker functions course #368

Open
wants to merge 495 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
495 commits
Select commit Hold shift + click to select a range
c189943
Changes from instructional call with Philipp
polytroper Feb 9, 2021
9cec8cc
Complete relation plotting interactive
polytroper Feb 9, 2021
3d7b65e
Removed stray TODO for tutor prompts
polytroper Feb 9, 2021
56c513f
Remove stray TODO
polytroper Feb 10, 2021
2feb1a6
Add section ID
polytroper Feb 10, 2021
e2e1149
Stub in hacky version of string-labeled plot
polytroper Feb 10, 2021
638b12f
Incomplete version of Vertical Line Test interactive
polytroper Feb 13, 2021
2b77397
Added markdown for remaining VLT interactives
polytroper Feb 13, 2021
64798c7
Fix bug with label text showing X value for both X and Y coords
polytroper Feb 13, 2021
0f07c83
Expand top padding for VLT interactives
polytroper Feb 13, 2021
cd9e50a
Hide all point labels when pointer exits VLT interactive
polytroper Feb 13, 2021
57a4c99
Remove position property from RelationValue type
polytroper Feb 14, 2021
6e972e4
Comments
polytroper Feb 14, 2021
8ee9001
Semicolon
polytroper Feb 14, 2021
cf4583a
Put VLT interactive graphs into columns and add questions
polytroper Feb 15, 2021
aac3123
Fix geopad svg selection
polytroper Feb 15, 2021
9e8408e
Resize VLT interactives
polytroper Feb 15, 2021
acd2485
Use map function for RelationValue array
polytroper Feb 15, 2021
371408c
Use $geopad.points instead of $$ selection to retrieve point values
polytroper Feb 15, 2021
d0f4ea7
Resize VLT Interactives (again)
polytroper Feb 15, 2021
2fe9c2b
Visible overflow on VLT interactives
polytroper Feb 15, 2021
af5f5d7
Padding on VLT interactives
polytroper Feb 15, 2021
b21f505
Positioning of VLT vertical line text
polytroper Feb 15, 2021
b00277b
Spaces in VLT vertical line label
polytroper Feb 15, 2021
f60f5b7
Multiple-choice prompts for VLT interactives
polytroper Feb 15, 2021
78f4ea0
Stubbing in hints.yaml
polytroper Feb 15, 2021
4e276e8
x-relation components for function identification section
polytroper Feb 15, 2021
9ab93c8
Phrasing
polytroper Feb 15, 2021
91538a9
Section ID
polytroper Feb 15, 2021
3a24b94
Technical correction to function explanation
polytroper Feb 15, 2021
23d7ad8
Section IDs
polytroper Feb 16, 2021
866eef2
Stub in new function machine interactive
polytroper Feb 16, 2021
1baf1eb
Revert "Section IDs"
polytroper Feb 16, 2021
2315510
Section IDs
polytroper Feb 16, 2021
5fa1fee
Fix broken section IDs
polytroper Feb 16, 2021
84378f6
Basic but working function machine component
polytroper Feb 17, 2021
51622d8
Add gesture prompt to hat machine interactive
polytroper Feb 17, 2021
26c5e67
Add scoring and hints to function machine
polytroper Feb 18, 2021
837c543
Remove test multiple choice
polytroper Feb 18, 2021
1123c97
Semicolons
polytroper Feb 18, 2021
86a158a
Section on function notation
polytroper Feb 18, 2021
204168d
Sorting hat written content
polytroper Feb 18, 2021
1fe03a1
Function machine styling
polytroper Feb 18, 2021
837ebd4
Bind $step to +1 function machine
polytroper Feb 18, 2021
4699312
Conditionalize scoring on whether $step is bound
polytroper Feb 18, 2021
04e165d
Nudge text upward by one pixel
polytroper Feb 18, 2021
b5138e4
Image paths
polytroper Feb 18, 2021
397c4e3
Stub in sorting hat interactive
polytroper Feb 18, 2021
d0e55cc
Questions about sorting hat function
polytroper Feb 18, 2021
fa671fa
"Functions with Numbers" section
polytroper Feb 18, 2021
7627773
Questions about numerical functions
polytroper Feb 18, 2021
4822a11
Nudge hat up by a pixel
polytroper Feb 18, 2021
edb58ce
Numerical function on coordinate plane interactive
polytroper Feb 18, 2021
87e5ca5
Colon
polytroper Feb 18, 2021
2b1a583
Section ID
polytroper Feb 19, 2021
310adbc
Section title. Replace dead content
polytroper Feb 19, 2021
f8e46ca
Writing
polytroper Feb 19, 2021
917b4bd
Domain/Range pickers
polytroper Feb 19, 2021
f36c54f
Hints for domain/range pickers
polytroper Feb 19, 2021
e53af49
Domain/range input tests
polytroper Feb 19, 2021
cc413d6
Finding domain/range section quizzes
polytroper Feb 19, 2021
b047b3c
Interactive plotter for domain and range section
polytroper Feb 19, 2021
66ac993
Cleanup
polytroper Feb 19, 2021
c3d8d80
Writing
polytroper Feb 19, 2021
02f4d26
Additional "Find domain+range" quiz
polytroper Feb 19, 2021
aba1cb6
Latex
polytroper Feb 20, 2021
cf3c915
Olympic vault video interactive
polytroper Mar 2, 2021
21ebed9
Removed dead comments
polytroper Mar 3, 2021
9067a00
Add section ID
polytroper Mar 3, 2021
68f0876
Videos and images for all other olympic sports
polytroper Mar 3, 2021
dc12e17
Add relation interactive for matching events to graphs
polytroper Mar 3, 2021
59e1b83
Remove dead text
polytroper Mar 3, 2021
e2eed65
Add swim event
polytroper Mar 3, 2021
f723416
Add randomize option to relation component
polytroper Mar 3, 2021
c2a668e
Randomize event/graph matching interactive
polytroper Mar 3, 2021
b08d50b
Add matches to events
polytroper Mar 3, 2021
d4979dc
Adapt relation component to score matching exercise
polytroper Mar 3, 2021
0046cb2
Remove logging
polytroper Mar 3, 2021
a9814f7
Margin and titles on events/graphs
polytroper Mar 3, 2021
0c2c955
Use Ri's face instead of a circle
polytroper Mar 4, 2021
638b2d8
Create VideoGraph shared component
polytroper Mar 4, 2021
21faad5
Wording
polytroper Mar 4, 2021
f31a95d
Add VideoGraph for time/height perspective of vault
polytroper Mar 4, 2021
5402c3e
Axes labels
polytroper Mar 4, 2021
e380cc7
Add questions to first vault section
polytroper Mar 4, 2021
8cf042a
Iron out time/height graph section
polytroper Mar 4, 2021
be0658d
Time/Distance graph section
polytroper Mar 4, 2021
f263e0f
TODO comment
polytroper Mar 4, 2021
78a3882
Uppercasing variable names
polytroper Mar 4, 2021
320110e
Stub in Distance/Time swim graph and remove dead text
polytroper Mar 4, 2021
1aa739f
Constrain swimmer function to match end of race
polytroper Mar 14, 2021
ad0c456
Further constrain swimmer graph to make it perfectly linear
polytroper Mar 14, 2021
f78599e
Add Cesar Cielo face avatar
polytroper Mar 14, 2021
5e03eb0
Fix variable quiz section
polytroper Mar 14, 2021
94d1d9c
Remove needless comma
polytroper Mar 14, 2021
2a20d6a
Attempt targeting of swim-x-axis and swim-y-axis
polytroper Mar 14, 2021
07dc6c8
Quiz questions
polytroper Mar 14, 2021
2d07d82
Comment
polytroper Mar 14, 2021
2f47559
Use precise value for swimmer speed
polytroper Mar 14, 2021
4a54e2c
Slope calculation questions
polytroper Mar 14, 2021
cb5a726
Typo
polytroper Mar 14, 2021
b208056
Function format prompt
polytroper Mar 14, 2021
618bab7
y=mx+b quiz
polytroper Mar 14, 2021
0aa8368
Portraits of Ri and Cielo
polytroper Mar 14, 2021
9d624c0
Break slope calculation into several sections
polytroper Mar 14, 2021
c690194
More sections, text work
polytroper Mar 14, 2021
4e458e2
± fuzzy input for m
polytroper Mar 14, 2021
b3374af
Fuzzy inputs for Ri's vault quizzes
polytroper Mar 14, 2021
714cc13
More text reworking
polytroper Mar 14, 2021
6cd4f3c
Add rise/run graphs
polytroper Mar 14, 2021
779b344
Text
polytroper Mar 15, 2021
33d0363
Quizzes and text
polytroper Mar 15, 2021
5a8a964
Text clarity
polytroper Mar 15, 2021
ec93bbc
Text
polytroper Mar 15, 2021
23fefa0
Text and quizzes
polytroper Mar 15, 2021
0f93985
Reformat graphs to be vertical, and make lots of changes to accomodat…
polytroper Mar 15, 2021
006ddc5
Remove dead text
polytroper Mar 15, 2021
cd1a658
Add section plus ID
polytroper Mar 15, 2021
5fd1a95
Reformat text
polytroper Mar 15, 2021
0b4f178
Graph widths
polytroper Mar 15, 2021
e732219
Algebra section
polytroper Mar 15, 2021
7b4f243
Swimmer system of equations graph
polytroper Mar 15, 2021
05b46fb
Text
polytroper Mar 15, 2021
928b878
Remove dead code
polytroper Mar 15, 2021
68abba7
Minor code simplification
polytroper Mar 15, 2021
739cc53
Fix incorrect numerical answer
polytroper Mar 15, 2021
7caed9b
Comment
polytroper Mar 15, 2021
b4ad0e9
Widen graph to make lines a bit more visible
polytroper Mar 15, 2021
f544b2c
Add slider and reactive t=0 variable
polytroper Mar 15, 2021
8e3c2b0
Lines left out from last commit
polytroper Mar 15, 2021
38e466e
Give latex structure to equations in swimmer time table
polytroper Mar 15, 2021
7b3c7bd
Tag swimmer function text with html IDs
polytroper Mar 17, 2021
f1dfeef
Swimmer distances react to slider changes
polytroper Mar 17, 2021
f87d02e
Finish quizzes and text for remainder of swim section
polytroper Mar 17, 2021
dd07b52
Fix broken ±
polytroper Mar 17, 2021
aaac635
Add vertical time line to swimmer graph
polytroper Mar 17, 2021
9eabb70
Add ren qian video graph
polytroper Mar 17, 2021
c0a0a0a
Dive function
polytroper Mar 17, 2021
c269f80
Trim dive video a bit
polytroper Mar 17, 2021
3b9bd37
Further clip ren dive video
polytroper Mar 17, 2021
5a02ca6
Ren dive graph/function
polytroper Mar 17, 2021
f6ceee2
Ren portrait
polytroper Mar 17, 2021
7d1d262
Ren dive card interactive
polytroper Mar 18, 2021
2a02cdc
Remaining text for diving section
polytroper Mar 18, 2021
85111d9
Event names
polytroper Mar 18, 2021
43e1021
Add 800m running video
polytroper Mar 18, 2021
159c022
Adapt VideoGraph to handle multiple functions. Also added support for…
polytroper Mar 19, 2021
0bd5b3f
Pole vault video clip
polytroper Mar 19, 2021
00427fa
Plot functions for runner graph
polytroper Mar 19, 2021
f3bc7f1
Running video poster
polytroper Mar 19, 2021
1d03fa9
Add faces for runners
polytroper Mar 19, 2021
a8fd5a5
Add name/face reference key for running graph
polytroper Mar 19, 2021
737f673
Add function labels to runner key
polytroper Mar 19, 2021
7830d91
Runner quiz numbers
polytroper Mar 19, 2021
71036aa
Runner quiz numbers and text
polytroper Mar 19, 2021
323ec2a
Create a CSS class for horizontally-oriented VideoGraphs
polytroper Mar 19, 2021
512b5a6
Slope calculation section for Boufaarirane and Rogers
polytroper Mar 20, 2021
1f8ef63
Clean up dead VideoGraph imports
polytroper Mar 20, 2021
75c32a9
Clean up imports
polytroper Mar 20, 2021
1571d23
Move video graph styles into separate file
polytroper Mar 20, 2021
388c920
Fix and clean up imports
polytroper Mar 20, 2021
2d633fd
Runner function
polytroper Mar 20, 2021
f5e939f
Runner text and quizzes
polytroper Mar 22, 2021
cdc4d87
Add default color arg to VideoGraph
polytroper Mar 22, 2021
dee0f4e
Break out dive card matching interactive into its own shared component
polytroper Mar 22, 2021
af0c927
Adjust card graph viewbox
polytroper Mar 22, 2021
e77f636
Class name typo
polytroper Mar 22, 2021
bbc6dfd
Adapt card matching component to accept ranges
polytroper Mar 24, 2021
6f9877c
Fix incorrect answer on range finding quiz
polytroper Mar 24, 2021
375ffc4
Remove youtube link
polytroper Mar 24, 2021
f51427e
Remove dead text
polytroper Mar 24, 2021
e88efa8
Running quizzes and text
polytroper Mar 24, 2021
c7db7e0
Replace diving interval quiz with interval graph card matching intera…
polytroper Mar 24, 2021
6ddf2ac
Remove volleyball section
polytroper Mar 24, 2021
4498053
Nudge card range
polytroper Mar 25, 2021
f69099c
Clean up component file
polytroper Mar 25, 2021
330b9d2
Pole vault video
polytroper Mar 25, 2021
9e7bd24
Section ID
polytroper Mar 25, 2021
f4bafc5
Stub in x-draw-graph component
polytroper Mar 25, 2021
143cefd
x-draw-graph component
polytroper Mar 25, 2021
a5dddab
Cleanup dead notes
polytroper Mar 25, 2021
12e24da
Add a goal
polytroper Mar 25, 2021
d6aff2c
Pole vault text
polytroper Mar 25, 2021
8716615
Set pole vault function
polytroper Mar 25, 2021
c014cae
Render x-draw-graph function after it is set
polytroper Mar 25, 2021
81eed05
Adjust pole vault function
polytroper Mar 25, 2021
2c716ea
Complete you-draw-it style component
polytroper Mar 30, 2021
ebea731
Move misplaced interactives
polytroper Mar 30, 2021
29d1349
Hint points on DrawGraph component
polytroper Mar 31, 2021
e268ed9
context-sensitive hints on DrawGraph
polytroper Mar 31, 2021
86b8dcb
Pointer cursor on points
polytroper Mar 31, 2021
7d953ac
Added a gesture prompt to pole vault graph
polytroper Apr 1, 2021
b415649
Piecewise function picker interactive
polytroper Apr 1, 2021
1dc9576
VLT interactive for swimming relay
polytroper Apr 1, 2021
ac85e93
VLT quiz section
polytroper Apr 1, 2021
ac22dc9
Break graph segments into groups
polytroper Apr 1, 2021
dffaa9b
Piecewise expression quiz
polytroper Apr 1, 2021
836c079
TODO
polytroper Apr 1, 2021
fdfafce
Vertically shrink graph
polytroper Apr 1, 2021
6882032
Add text labels and clean up code
polytroper Apr 1, 2021
85bf3d0
Widen graph
polytroper Apr 1, 2021
a7d1568
Change ids to match stroke names
polytroper Apr 2, 2021
b51f798
Add piecewise graph
polytroper Apr 2, 2021
8115893
Colored and formatted step function table
polytroper Apr 2, 2021
794c7d6
Text formatting
polytroper Apr 2, 2021
f6fa422
Clarity
polytroper Apr 2, 2021
352504d
Add DrawGraph interactive for triathlon
polytroper Apr 4, 2021
09b8f48
Rewritten intro section for piecewise chapter
polytroper Apr 4, 2021
de6cf85
Explanation of cases
polytroper Apr 4, 2021
3a797a3
Piecewise endpoint puzzle
polytroper Apr 7, 2021
bece540
Snapping feature for DrawGraph
polytroper Apr 9, 2021
d5a2f4d
Use attributes instead of function call for DrawGraph
polytroper Apr 9, 2021
f560e4f
Endpoint puzzle writing
polytroper Apr 9, 2021
ac5aec5
Triathlon DrawGraph written section
polytroper Apr 9, 2021
fc8d8a1
Hints and other goodies for triathlon DrawGraph
polytroper Apr 9, 2021
ec547ec
Adjust margins
polytroper Apr 9, 2021
2e01e79
Wording
polytroper Apr 9, 2021
6786786
Removed ambiguity of quiz section
polytroper Apr 9, 2021
d82d24b
Writing
polytroper Apr 9, 2021
a655038
Slope calculation section
polytroper Apr 9, 2021
1106289
Triathlon rate adjustments section
polytroper Apr 9, 2021
c5a8c9f
Nix the ice cream section and wrap up the chapter.
polytroper Apr 9, 2021
4a052ce
Convert .less to .scss
polytroper Apr 26, 2021
4a29f90
Merge branch 'cwalker-functions-course' of https://github.com/polytro…
polytroper Apr 26, 2021
01611a2
Fix style imports
polytroper Apr 26, 2021
230fea8
Update image URLs
plegner Apr 29, 2021
1b98e0d
Merge branch 'cwalker-functions-course' of https://github.com/polytro…
polytroper Apr 29, 2021
bcfbdbc
Update imports in shared components
polytroper Apr 29, 2021
01f9e43
Qualify presence of $step in FunctionMachine
polytroper Apr 29, 2021
f25ace4
Assert existence of values in VideoGraph
polytroper Apr 29, 2021
6f93764
Recast video element as any to access currentTime value
polytroper Apr 29, 2021
5887b25
Require full path for CardGraph images
polytroper Apr 29, 2021
0b60878
Move functions chapter components into dedicated local component folders
polytroper Apr 29, 2021
35041da
Fix import in DrawGraph
polytroper Apr 29, 2021
dc40758
Move PiecewiseEndpointPuzzle into specific component directory
polytroper Apr 29, 2021
e6e7555
Fix imports in PiecewiseEndpointPuzzle
polytroper Apr 29, 2021
44a247e
Fix import paths of custom function components
polytroper Apr 29, 2021
faa1fd7
Fix CSS paths for components
polytroper Apr 29, 2021
c10225f
Delete .less files
polytroper Apr 29, 2021
8d99b0c
Check to make sure label exists before applying in PiecewiseEndpointP…
polytroper Apr 29, 2021
540bb49
Fix improperly converted percentage in relation.scss
polytroper Apr 29, 2021
a3b8993
Add color classes back to x-coordinate-system lines and paths
polytroper Apr 29, 2021
8311bf8
Stub in pong component
polytroper May 6, 2021
c053112
Fill out pong functionality a bit
polytroper May 6, 2021
707b1a5
Merging in fix to broken cachebusting
polytroper May 13, 2021
3e392a6
Pong interactive
polytroper Jun 9, 2021
c15c866
Merge https://github.com/mathigon/textbooks into cwalker-functions-co…
polytroper Jun 9, 2021
c70aaa5
Automatic lint fixes
polytroper Jun 16, 2021
e78c4ad
Lint
polytroper Jun 16, 2021
63faae7
Remaining lint
polytroper Jun 16, 2021
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
86 changes: 86 additions & 0 deletions content/functions/components/card-graph/card-graph.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

x-card-graph svg {
overflow: visible;
}

x-card-graph .ranges {
stroke-width: 2px;
stroke: $medium-grey;
stroke-dasharray: 4;

.range-tick,.range-line {
transition: 0.2s;
}
}

x-card-graph .ranges:not(.hover) {
.range-line {
opacity: 0;
}
.range-tick {
opacity: 1;
}
}

x-card-graph .ranges.hover {
.range-lines:not(.hover) line {
opacity: 0;
}
.range-lines.hover {
.range-line {
opacity: 1;
}
.range-tick {
opacity: 0;
}
}
}

x-card-graph .dot {
stroke-width: 2px;
stroke: $medium-grey;
fill: $light-grey;
}

x-card-graph .card-content {
cursor: pointer;
transition: 0.2s;

.card-circle {
fill: none;
stroke: $medium-grey;
stroke-width: 2px;
}

.card-fill {
fill: $grey-background;
stroke: none;
}

text {
font-size: 12px;
}
}

x-card-graph .card-instruction {
fill: $medium-grey;
font-style: italic;
transition: 0.2s;
font-size: 22px;
}

x-card-graph .card-description {
transition: 0.2s;
font-size: 22px;
}

x-card-graph .card-outline {
fill: none;
stroke: $light-grey;
stroke-width: 2px;
stroke-dasharray: 4;
}

x-card-graph svg .labels {
pointer-events: none;
}
212 changes: 212 additions & 0 deletions content/functions/components/card-graph/card-graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
// =============================================================================
// Card Graph Component
// (c) Mathigon
// =============================================================================

import {Step} from '@mathigon/studio';
import {$N, animate, CustomElementView, Draggable, ease, ElementView, hover, register, SVGView} from '@mathigon/boost';
import {Point} from '@mathigon/euclid';
import {lerp} from '@mathigon/fermat';
import {shuffle} from '@mathigon/fermat/src/random';
import {CoordinateSystem} from '../../../shared/types';

type Plot = {
color: string,
function: (x: number) => number,
}

type Card = {
description?: string,
imagePath?: string,
label?: string,
hint?: string,
point: Point,
domain?: number[],
invertDomainLines?: boolean,
}

@register('x-card-graph')
export class CardGraph extends CustomElementView {
private $graph!: CoordinateSystem;
private $overlay!: ElementView;
private $instructionText!: ElementView;
private $descriptionText!: ElementView;
private graphWidth!: number;
private graphHeight!: number;
private $step?: Step;

ready() {
this.$graph = this.$('x-coordinate-system')! as CoordinateSystem;
this.$overlay = this.$graph.$svg.$('.overlay')!;

this.graphWidth = parseInt(this.$graph.attr('width'));
this.graphHeight = parseInt(this.$graph.attr('height'));

this.$graph.$svg.setAttr('height', this.graphHeight + 100);
this.$graph.$svg.setAttr('viewBox', `0 0 ${this.graphWidth} ${this.graphHeight - 50}`);

this.$instructionText = $N('text', {class: 'card-instruction', 'alignment-baseline': 'middle', 'text-anchor': 'middle', transform: `translate(${this.graphWidth / 2}, ${this.graphHeight + 20})`}, this.$overlay);
this.$descriptionText = $N('text', {class: 'card-description', 'alignment-baseline': 'middle', 'text-anchor': 'middle', transform: `translate(${this.graphWidth / 2}, ${this.graphHeight + 20})`}, this.$overlay);

this.$instructionText.text = 'Drag each card onto its corresponding point';
}

bindStep($step: Step) {
this.$step = $step;
}

setPlots(plots: Plot[]) {
this.$graph.setFunctions(...plots.map((plot) => plot.function));

for (let i = 0; i < plots.length; i++) {
this.$graph.$('.plot')!.$$('g')[i].$('path')!.setAttr('class', plots[i].color);
}
}

setCards(cards: Card[]) {
cards = shuffle(cards);

const $rangeGroup = $N('g', {class: 'ranges'}, this.$overlay);
const $dotGroup = $N('g', {class: 'dots'}, this.$overlay);
const $cardGroup = $N('g', {class: 'cards'}, this.$overlay);

let $hoverDot: ElementView|null = null;
let $dragCard: ElementView|null = null;

const _$cards = cards.map((card, i) => {
const origin = new Point(this.graphWidth * (i + 1 / 2) / cards.length, -30);

const _$outline = $N('circle', {cx: origin.x, cy: origin.y, r: 30, class: 'card-outline'}, $cardGroup);

const $g = $N('g', {transform: `translate(${origin.x}, ${origin.y})`}, $cardGroup) as SVGView;

const $content = $N('g', {class: 'card-content'}, $g);

if (card.imagePath) {
$N('image', {href: card.imagePath, x: -30, y: -30, width: 60, height: 60}, $content);
} else {
$N('circle', {r: 30, class: 'card-fill'}, $content);
$N('text', {'alignment-baseline': 'middle', 'text-anchor': 'middle'}, $content).text = card.label!;
}

const _$circle = $N('circle', {cx: 0, cy: 0, r: 30, class: 'card-circle'}, $content);

const dotPosition = this.$graph.toViewportCoords(card.domain ? new Point((card.domain[0] + card.domain[1]) / 2, card.point.y) : card.point);
const $dot = $N('circle', {class: 'dot', transform: `translate(${dotPosition.x}, ${dotPosition.y})`, r: 15}, $dotGroup);

const $rangeLines = $N('g', {class: 'range-lines'}, $rangeGroup);

if (card.domain) {
const rangeStartPoint = new Point(card.domain[0]!, card.point.y);
const rangeEndPoint = new Point(card.domain[1]!, card.point.y);

const rangeStartPosition = this.$graph.toViewportCoords(rangeStartPoint);
const rangeEndPosition = this.$graph.toViewportCoords(rangeEndPoint);

const axisHeight = this.$graph.$yAxis!.height;
const yOffset = (this.graphHeight - axisHeight) / 2;

const _$rangeSpan = $N('line', {x1: rangeStartPosition.x, x2: rangeEndPosition.x, y1: rangeStartPosition.y, y2: rangeEndPosition.y}, $rangeLines);

const _$rangeStartLine = $N('line', {class: 'range-line', x1: rangeStartPosition.x, x2: rangeStartPosition.x, y1: yOffset, y2: axisHeight + yOffset}, $rangeLines);
const _$rangeEndLine = $N('line', {class: 'range-line', x1: rangeEndPosition.x, x2: rangeEndPosition.x, y1: yOffset, y2: axisHeight + yOffset}, $rangeLines);

const _$rangeStartTick = $N('line', {class: 'range-tick', x1: rangeStartPosition.x, x2: rangeStartPosition.x, y1: rangeStartPosition.y - 10, y2: rangeStartPosition.y + 10}, $rangeLines);
const _$rangeEndTick = $N('line', {class: 'range-tick', x1: rangeEndPosition.x, x2: rangeEndPosition.x, y1: rangeStartPosition.y - 10, y2: rangeStartPosition.y + 10}, $rangeLines);
}

hover($g, {
enter: () => {
if (!$dragCard && card.description) {
this.$descriptionText.text = card.description;
this.$descriptionText.css('opacity', 1);
this.$instructionText.css('opacity', 0);
}
},
exit: () => {
if (!$dragCard && card.description) {
this.$descriptionText.css('opacity', 0);
this.$instructionText.css('opacity', 1);
}
}
});

hover($dot, {
enter: () => {
$hoverDot = $dot;

$rangeGroup.addClass('hover');
$rangeLines.addClass('hover');

if ($dragCard) {
$dragCard.$('.card-content')!.setAttr('transform', `scale(${1 / 2})`);
}
},
exit: () => {
$hoverDot = null;

$rangeGroup.removeClass('hover');
$rangeLines.removeClass('hover');

if ($dragCard) {
$dragCard.$('.card-content')!.setAttr('transform', `scale(1)`);
}
}
});

const drag = new Draggable($g, this.$graph.$svg, {useTransform: true, margin: -60});

drag.setPosition(origin.x, origin.y);

drag.on('start', () => {
$dragCard = $g;

$g.css('pointer-events', 'none');
});

drag.on('end', () => {
$dragCard = null;

const dropPosition = drag.position;
let restPosition: Point;

if ($hoverDot == $dot) {
if (this.$step) {
this.$step.addHint('correct');

if (card.hint) {
this.$step.addHint(card.hint);
}

this.$step.score('card' + i);
}

restPosition = dotPosition;

this.$descriptionText.css('opacity', 0);
this.$instructionText.css('opacity', 1);
} else if ($hoverDot) {
if (this.$step) {
this.$step.addHint('incorrect');
}

restPosition = origin;

$content.setAttr('transform', 'scale(1)');
$g.css('pointer-events', 'all');
} else {
restPosition = origin;

$g.css('pointer-events', 'all');
}

animate((p) => {
const q = ease('sine', p);
drag.setPosition(lerp(dropPosition.x, restPosition.x, q), lerp(dropPosition.y, restPosition.y, q));
}, 500);
});

return $g;
});
}
}
Loading