|
|
{% extends "layout.html" %}
|
|
|
{% block content %}
|
|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
<head>
|
|
|
<meta charset="UTF-8" />
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
<title>Decision Tree Regression - Interactive Flow Visualization</title>
|
|
|
<style>
|
|
|
body {
|
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
|
background: #f0f4ff;
|
|
|
margin: 0;
|
|
|
padding: 40px 20px;
|
|
|
color: #333;
|
|
|
display: flex;
|
|
|
justify-content: center;
|
|
|
}
|
|
|
|
|
|
.container {
|
|
|
max-width: 900px;
|
|
|
background: white;
|
|
|
border-radius: 20px;
|
|
|
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
|
|
padding: 30px 40px;
|
|
|
}
|
|
|
|
|
|
h1 {
|
|
|
text-align: center;
|
|
|
color: #4facfe;
|
|
|
margin-bottom: 30px;
|
|
|
font-weight: 700;
|
|
|
}
|
|
|
|
|
|
.stepper {
|
|
|
display: flex;
|
|
|
justify-content: space-between;
|
|
|
margin-bottom: 40px;
|
|
|
}
|
|
|
|
|
|
.step {
|
|
|
flex: 1;
|
|
|
text-align: center;
|
|
|
position: relative;
|
|
|
cursor: pointer;
|
|
|
color: #bbb;
|
|
|
font-weight: 600;
|
|
|
user-select: none;
|
|
|
}
|
|
|
|
|
|
.step.active, .step.completed {
|
|
|
color: #4facfe;
|
|
|
}
|
|
|
|
|
|
.step::after {
|
|
|
content: '';
|
|
|
position: absolute;
|
|
|
top: 18px;
|
|
|
right: -50%;
|
|
|
width: 100%;
|
|
|
height: 4px;
|
|
|
background: #bbb;
|
|
|
z-index: -1;
|
|
|
transition: background 0.3s;
|
|
|
}
|
|
|
|
|
|
.step:last-child::after {
|
|
|
display: none;
|
|
|
}
|
|
|
|
|
|
.step.completed::after {
|
|
|
background: #4facfe;
|
|
|
}
|
|
|
|
|
|
.step-circle {
|
|
|
width: 36px;
|
|
|
height: 36px;
|
|
|
border-radius: 50%;
|
|
|
border: 3px solid currentColor;
|
|
|
margin: 0 auto 8px;
|
|
|
line-height: 30px;
|
|
|
font-size: 18px;
|
|
|
color: inherit;
|
|
|
background: white;
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
justify-content: center;
|
|
|
}
|
|
|
|
|
|
.content {
|
|
|
min-height: 280px;
|
|
|
position: relative;
|
|
|
}
|
|
|
|
|
|
.content > div {
|
|
|
position: absolute;
|
|
|
top: 0; left: 0; right: 0; bottom: 0;
|
|
|
opacity: 0;
|
|
|
pointer-events: none;
|
|
|
transition: opacity 0.5s ease;
|
|
|
}
|
|
|
|
|
|
.content > div.active {
|
|
|
opacity: 1;
|
|
|
pointer-events: auto;
|
|
|
position: relative;
|
|
|
}
|
|
|
|
|
|
.content h2 {
|
|
|
color: #4facfe;
|
|
|
margin-bottom: 15px;
|
|
|
}
|
|
|
|
|
|
.content p {
|
|
|
font-size: 1.1rem;
|
|
|
line-height: 1.5;
|
|
|
margin-bottom: 25px;
|
|
|
}
|
|
|
|
|
|
.svg-container {
|
|
|
width: 100%;
|
|
|
height: 180px;
|
|
|
}
|
|
|
|
|
|
svg {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
}
|
|
|
|
|
|
.nav-buttons {
|
|
|
text-align: center;
|
|
|
margin-top: 30px;
|
|
|
}
|
|
|
|
|
|
button {
|
|
|
background: #4facfe;
|
|
|
border: none;
|
|
|
color: white;
|
|
|
font-weight: 700;
|
|
|
padding: 12px 28px;
|
|
|
margin: 0 10px;
|
|
|
border-radius: 10px;
|
|
|
cursor: pointer;
|
|
|
font-size: 1rem;
|
|
|
transition: background 0.3s;
|
|
|
}
|
|
|
|
|
|
button:disabled {
|
|
|
background: #a0c8ff;
|
|
|
cursor: not-allowed;
|
|
|
}
|
|
|
|
|
|
button:hover:not(:disabled) {
|
|
|
background: #3a9dfd;
|
|
|
}
|
|
|
|
|
|
|
|
|
.color-data { fill: #ff6b6b; }
|
|
|
.color-split { stroke: #fd746c; stroke-width: 4; }
|
|
|
.color-left { fill: #56ab2f; fill-opacity: 0.3; stroke: #56ab2f; stroke-width: 2; }
|
|
|
.color-right { fill: #fd746c; fill-opacity: 0.3; stroke: #fd746c; stroke-width: 2; }
|
|
|
.color-node { fill: #4facfe; fill-opacity: 0.15; stroke: #4facfe; stroke-width: 2; }
|
|
|
.color-path { stroke: #ff00ff; stroke-width: 3; }
|
|
|
.color-prediction { fill: #ff00ff; }
|
|
|
</style>
|
|
|
|
|
|
<style>
|
|
|
body {
|
|
|
background: #fff;
|
|
|
color: #000;
|
|
|
font-family: 'Inter', sans-serif;
|
|
|
line-height: 1.6;
|
|
|
padding: 1rem 1rem 3rem;
|
|
|
}
|
|
|
h1, h2, h3 {
|
|
|
font-weight: 700;
|
|
|
margin-top: 0;
|
|
|
margin-bottom: 1rem;
|
|
|
}
|
|
|
p, li {
|
|
|
font-weight: 600;
|
|
|
margin-bottom: 1rem;
|
|
|
}
|
|
|
ul {
|
|
|
padding-left: 1.25rem;
|
|
|
margin-bottom: 1rem;
|
|
|
}
|
|
|
.card {
|
|
|
background: #f9fafb;
|
|
|
border: 1px solid #e5e7eb;
|
|
|
border-radius: 12px;
|
|
|
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
|
padding: 1.5rem 2rem;
|
|
|
margin-bottom: 2rem;
|
|
|
}
|
|
|
label {
|
|
|
font-weight: 700;
|
|
|
margin-right: 0.5rem;
|
|
|
min-width: 70px;
|
|
|
display: inline-block;
|
|
|
}
|
|
|
input, button {
|
|
|
background: #e5e7eb;
|
|
|
border: 1px solid #9ca3af;
|
|
|
border-radius: 8px;
|
|
|
padding: 0.5rem 1rem;
|
|
|
font-weight: 600;
|
|
|
color: #000;
|
|
|
font-size: 1rem;
|
|
|
}
|
|
|
input:focus, button:focus {
|
|
|
outline: none;
|
|
|
border-color: #6b7280;
|
|
|
box-shadow: 0 0 5px #6b7280;
|
|
|
}
|
|
|
button {
|
|
|
cursor: pointer;
|
|
|
font-weight: 700;
|
|
|
transition: background-color 0.3s ease;
|
|
|
}
|
|
|
button:hover {
|
|
|
background-color: #d1d5db;
|
|
|
}
|
|
|
#dataPointsList li {
|
|
|
background: #e5e7eb;
|
|
|
padding: 0.5rem 1rem;
|
|
|
border-radius: 8px;
|
|
|
margin: 0.25rem;
|
|
|
font-weight: 600;
|
|
|
display: inline-block;
|
|
|
}
|
|
|
.plot-container {
|
|
|
background: #fff !important;
|
|
|
border-radius: 12px;
|
|
|
padding: 1rem;
|
|
|
border: 1px solid #e5e7eb;
|
|
|
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
|
height: 400px;
|
|
|
}
|
|
|
</style>
|
|
|
|
|
|
<div class="max-w-7xl mx-auto">
|
|
|
<header class="text-center mb-8">
|
|
|
<h1 class="text-4xl sm:text-5xl">Decision Tree Regression (DTR) Visualization</h1>
|
|
|
<p class="text-lg font-semibold">Explore how DTR predicts continuous values with interactive examples.</p>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
<section class="card">
|
|
|
<h3>What is Decision Tree Regression?</h3>
|
|
|
<p>It’s a smart algorithm that predicts numbers — like house prices or temperatures — by splitting data into smaller groups based on features. Imagine a tree where each branch asks a question, and leaves give the final prediction.</p>
|
|
|
</section>
|
|
|
|
|
|
<section class="card">
|
|
|
<h3>How Does It Work?</h3>
|
|
|
<p>The tree splits data recursively, choosing the best points to divide so that each group is as similar as possible. It stops splitting when the groups are small or deep enough.</p>
|
|
|
<ul>
|
|
|
<li><strong>Variance Reduction:</strong> Splits aim to reduce differences within groups.</li>
|
|
|
<li><strong>Mean Squared Error (MSE):</strong> The algorithm picks splits that minimize prediction errors.</li>
|
|
|
</ul>
|
|
|
</section>
|
|
|
|
|
|
<section class="card">
|
|
|
<h3>Making Predictions</h3>
|
|
|
<p>To predict a new value, the data point travels down the tree following the split rules until it reaches a leaf. The prediction is the average of all training points in that leaf.</p>
|
|
|
</section>
|
|
|
|
|
|
<section class="card">
|
|
|
<h3>Key Hyperparameters</h3>
|
|
|
<ul>
|
|
|
<li><strong>max_depth:</strong> Limits tree height to avoid overfitting.</li>
|
|
|
<li><strong>min_samples_split:</strong> Minimum data points to split a node.</li>
|
|
|
<li><strong>min_samples_leaf:</strong> Minimum data points in a leaf.</li>
|
|
|
</ul>
|
|
|
</section>
|
|
|
|
|
|
<section class="card">
|
|
|
<h3>Comparison with Other Models</h3>
|
|
|
<ul>
|
|
|
<li><strong>Decision Tree vs. Linear Regression:</strong>
|
|
|
DTR can model non-linear relationships, whereas Linear Regression assumes a linear relationship.
|
|
|
DTR is generally more flexible but also more prone to overfitting.
|
|
|
</li>
|
|
|
<li><strong>Decision Tree vs. SVR (Support Vector Regression):</strong>
|
|
|
SVR is a powerful model that finds the best fit line (or hyperplane) while tolerating some error.
|
|
|
SVR can be very effective but is often more complex to tune than DTR.
|
|
|
</li>
|
|
|
<li><strong>Decision Tree vs. Random Forest:</strong>
|
|
|
Random Forest is an ensemble of Decision Trees. It builds multiple trees and averages their predictions.
|
|
|
This significantly reduces variance and improves stability, making it a much better and more common choice in practice than a single DTR.
|
|
|
</li>
|
|
|
</ul>
|
|
|
</section>
|
|
|
|
|
|
<section class="card">
|
|
|
<h3>Key Hyperparameters (Detailed)</h3>
|
|
|
<ul>
|
|
|
<li>
|
|
|
<strong>max_depth:</strong> How deep the tree can grow.
|
|
|
<br>👉 Bigger depth = tree keeps splitting → very detailed → <em>more overfitting</em>.
|
|
|
<br>👉 Smaller depth = tree stops early → simpler → <em>less overfitting</em>.
|
|
|
</li>
|
|
|
|
|
|
<li>
|
|
|
<strong>min_samples_split:</strong> Minimum samples needed to split a node.
|
|
|
<br>👉 Smaller value (like 2) = splits happen easily → <em>more overfitting</em>.
|
|
|
<br>👉 Larger value (like 10) = splits happen only with many samples → <em>less overfitting</em>.
|
|
|
<br><em>Example:</em> If <code>min_samples_split=2</code>, even 2 points can split → tree memorizes tiny patterns.
|
|
|
If <code>min_samples_split=10</code>, need 10+ points to split → tree generalizes.
|
|
|
</li>
|
|
|
|
|
|
<li>
|
|
|
<strong>min_samples_leaf:</strong> Minimum samples in a leaf node.
|
|
|
<br>👉 Smaller value (like 1) = tiny leaves → <em>more overfitting</em>.
|
|
|
<br>👉 Larger value (like 5 or 10) = bigger leaves → <em>less overfitting</em>.
|
|
|
<br><em>Example:</em> If <code>min_samples_leaf=1</code>, each data point might get its own leaf.
|
|
|
If <code>min_samples_leaf=10</code>, each leaf must cover at least 10 points → tree generalizes.
|
|
|
</li>
|
|
|
|
|
|
<li>
|
|
|
<strong>max_features:</strong> Number of features considered at each split.
|
|
|
<br>👉 Smaller value = fewer features per split → adds randomness → can reduce overfitting (especially in Random Forests).
|
|
|
<br>👉 Larger value = considers all features → risk of overfitting.
|
|
|
</li>
|
|
|
</ul>
|
|
|
|
|
|
<p><strong>✅ Summary Memory Trick:</strong><br>
|
|
|
Big numbers (<code>min_samples_split ↑</code>, <code>min_samples_leaf ↑</code>) + small <code>max_depth ↓</code> → simpler tree → less overfitting.<br>
|
|
|
Small numbers (<code>min_samples_split ↓</code>, <code>min_samples_leaf ↓</code>) + big <code>max_depth ↑</code> → complex tree → more overfitting.
|
|
|
</p>
|
|
|
</section>
|
|
|
decis
|
|
|
|
|
|
<section class="card">
|
|
|
<h3>Why Use DTR?</h3>
|
|
|
<ul>
|
|
|
<li>Easy to understand and visualize.</li>
|
|
|
<li>Captures complex, non-linear relationships.</li>
|
|
|
<li>No need to scale features.</li>
|
|
|
</ul>
|
|
|
</section>
|
|
|
|
|
|
<section class="card">
|
|
|
<h3>Limitations</h3>
|
|
|
<ul>
|
|
|
<li>Can overfit if not controlled.</li>
|
|
|
<li>Small data changes can cause big model changes.</li>
|
|
|
<li>Less stable than ensemble methods like Random Forest.</li>
|
|
|
</ul>
|
|
|
</section>
|
|
|
|
|
|
<section class="card">
|
|
|
<h3>Evaluation Metrics</h3>
|
|
|
<ul>
|
|
|
<li><strong>MSE:</strong> Average squared error.</li>
|
|
|
<li><strong>RMSE:</strong> Square root of MSE, same units as target.</li>
|
|
|
<li><strong>R² Score:</strong> How well predictions fit actual data (1 = perfect).</li>
|
|
|
</ul>
|
|
|
</section>
|
|
|
|
|
|
<section class="card">
|
|
|
<h3>Applications</h3>
|
|
|
<ul>
|
|
|
<li>Predicting house prices.</li>
|
|
|
<li>Estimating medical costs.</li>
|
|
|
<li>Forecasting sales.</li>
|
|
|
<li>Predicting energy consumption.</li>
|
|
|
</ul>
|
|
|
</section>
|
|
|
|
|
|
<a href="/dtrg"
|
|
|
class="inline-block bg-white text-black font-bold px-4 py-2 rounded shadow-md
|
|
|
border border-black relative
|
|
|
hover:after:content-[''] hover:after:absolute hover:after:right-0 hover:after:bottom-0
|
|
|
hover:after:w-full hover:after:h-[2px] hover:after:bg-black
|
|
|
hover:before:content-[''] hover:before:absolute hover:before:right-0 hover:before:bottom-0
|
|
|
hover:before:w-[2px] hover:before:h-full hover:before:bg-black">
|
|
|
try your self
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
|
|
|
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/browser/math.js"></script>
|
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
|
|
</head>
|
|
|
<body>
|
|
|
<div class="container" role="main" aria-label="Decision Tree Regression Flow Visualization">
|
|
|
<h1>Decision Tree Regression: Step-by-Step Flow</h1>
|
|
|
|
|
|
<div class="stepper" role="tablist" aria-label="Steps of Decision Tree Regression">
|
|
|
<div class="step active" role="tab" aria-selected="true" tabindex="0" aria-controls="step1" id="tab1" data-step="0">
|
|
|
<div class="step-circle">1</div>
|
|
|
Input Data
|
|
|
</div>
|
|
|
<div class="step" role="tab" aria-selected="false" tabindex="-1" aria-controls="step2" id="tab2" data-step="1">
|
|
|
<div class="step-circle">2</div>
|
|
|
Find Split
|
|
|
</div>
|
|
|
<div class="step" role="tab" aria-selected="false" tabindex="-1" aria-controls="step3" id="tab3" data-step="2">
|
|
|
<div class="step-circle">3</div>
|
|
|
Split Data
|
|
|
</div>
|
|
|
<div class="step" role="tab" aria-selected="false" tabindex="-1" aria-controls="step4" id="tab4" data-step="3">
|
|
|
<div class="step-circle">4</div>
|
|
|
Build Tree
|
|
|
</div>
|
|
|
<div class="step" role="tab" aria-selected="false" tabindex="-1" aria-controls="step5" id="tab5" data-step="4">
|
|
|
<div class="step-circle">5</div>
|
|
|
Predict
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="content">
|
|
|
|
|
|
<div id="step1" class="active" role="tabpanel" aria-labelledby="tab1">
|
|
|
<h2>1. Input Data Points</h2>
|
|
|
<p>The algorithm starts with your input data points (X, y). These points represent the relationship we want to model.</p>
|
|
|
<div class="svg-container" aria-hidden="true">
|
|
|
<svg viewBox="0 0 300 180" >
|
|
|
<rect x="20" y="20" width="260" height="140" fill="#4facfe" fill-opacity="0.1" stroke="#4facfe" stroke-width="2" rx="12" ry="12"/>
|
|
|
<circle cx="60" cy="140" r="8" class="color-data" />
|
|
|
<circle cx="120" cy="100" r="8" class="color-data" />
|
|
|
<circle cx="180" cy="70" r="8" class="color-data" />
|
|
|
<circle cx="240" cy="130" r="8" class="color-data" />
|
|
|
<text x="100" y="40" fill="#4facfe" font-weight="700" font-size="16">Data Points (X, y)</text>
|
|
|
</svg>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div id="step2" role="tabpanel" aria-labelledby="tab2">
|
|
|
<h2>2. Find Best Split</h2>
|
|
|
<p>The algorithm tries different thresholds on the feature (X) to split the data into two groups, aiming to reduce variance in each group.</p>
|
|
|
<div class="svg-container" aria-hidden="true">
|
|
|
<svg viewBox="0 0 300 180" >
|
|
|
<rect x="20" y="20" width="260" height="140" fill="#4facfe" fill-opacity="0.1" stroke="#4facfe" stroke-width="2" rx="12" ry="12"/>
|
|
|
<line x1="150" y1="20" x2="150" y2="160" class="color-split" />
|
|
|
<circle cx="60" cy="140" r="8" class="color-data" />
|
|
|
<circle cx="120" cy="100" r="8" class="color-data" />
|
|
|
<circle cx="180" cy="70" r="8" class="color-data" />
|
|
|
<circle cx="240" cy="130" r="8" class="color-data" />
|
|
|
<text x="160" y="40" fill="#fd746c" font-weight="700" font-size="16">Split Threshold</text>
|
|
|
</svg>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div id="step3" role="tabpanel" aria-labelledby="tab3">
|
|
|
<h2>3. Split Data</h2>
|
|
|
<p>Data is split into left and right groups based on the threshold. Each group is more homogeneous (less variance).</p>
|
|
|
<div class="svg-container" aria-hidden="true">
|
|
|
<svg viewBox="0 0 300 180" >
|
|
|
<rect x="20" y="20" width="120" height="140" class="color-left" rx="12" ry="12"/>
|
|
|
<rect x="160" y="20" width="120" height="140" class="color-right" rx="12" ry="12"/>
|
|
|
<circle cx="60" cy="140" r="8" fill="#56ab2f" />
|
|
|
<circle cx="90" cy="100" r="8" fill="#56ab2f" />
|
|
|
<circle cx="200" cy="70" r="8" fill="#fd746c" />
|
|
|
<circle cx="230" cy="130" r="8" fill="#fd746c" />
|
|
|
<text x="50" y="40" fill="#56ab2f" font-weight="700" font-size="16">Left Group</text>
|
|
|
<text x="190" y="40" fill="#fd746c" font-weight="700" font-size="16">Right Group</text>
|
|
|
</svg>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div id="step4" role="tabpanel" aria-labelledby="tab4">
|
|
|
<h2>4. Recursively Build Subtrees</h2>
|
|
|
<p>The algorithm repeats the splitting process on each group until max depth or minimum variance is reached, building a tree structure.</p>
|
|
|
<div class="svg-container" aria-hidden="true">
|
|
|
<svg viewBox="0 0 300 180" >
|
|
|
|
|
|
<rect x="120" y="10" width="60" height="40" class="color-node" rx="10" ry="10"/>
|
|
|
<text x="150" y="35" fill="#4facfe" font-weight="700" font-size="16" text-anchor="middle">Root</text>
|
|
|
|
|
|
|
|
|
<rect x="40" y="90" width="60" height="40" class="color-left" rx="10" ry="10"/>
|
|
|
<text x="70" y="115" fill="#56ab2f" font-weight="700" font-size="16" text-anchor="middle">Left</text>
|
|
|
|
|
|
|
|
|
<rect x="200" y="90" width="60" height="40" class="color-right" rx="10" ry="10"/>
|
|
|
<text x="230" y="115" fill="#fd746c" font-weight="700" font-size="16" text-anchor="middle">Right</text>
|
|
|
|
|
|
|
|
|
<line x1="150" y1="50" x2="70" y2="90" class="color-split" stroke-width="3" />
|
|
|
<line x1="150" y1="50" x2="230" y2="90" class="color-split" stroke-width="3" />
|
|
|
</svg>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div id="step5" role="tabpanel" aria-labelledby="tab5">
|
|
|
<h2>5. Make Predictions</h2>
|
|
|
<p>To predict a new point, the tree is traversed from root to leaf by comparing the input to thresholds, returning the leaf's average value.</p>
|
|
|
<div class="svg-container" aria-hidden="true">
|
|
|
<svg viewBox="0 0 300 180" >
|
|
|
|
|
|
<rect x="120" y="10" width="60" height="40" class="color-node" rx="10" ry="10"/>
|
|
|
<text x="150" y="35" fill="#4facfe" font-weight="700" font-size="16" text-anchor="middle">Root</text>
|
|
|
|
|
|
|
|
|
<rect x="40" y="90" width="60" height="40" class="color-left" rx="10" ry="10"/>
|
|
|
<text x="70" y="115" fill="#56ab2f" font-weight="700" font-size="16" text-anchor="middle">Left Leaf</text>
|
|
|
|
|
|
|
|
|
<rect x="200" y="90" width="60" height="40" class="color-right" rx="10" ry="10"/>
|
|
|
<text x="230" y="115" fill="#fd746c" font-weight="700" font-size="16" text-anchor="middle">Right Leaf</text>
|
|
|
|
|
|
|
|
|
<line x1="150" y1="50" x2="70" y2="90" class="color-split" stroke-width="3" />
|
|
|
<line x1="150" y1="50" x2="230" y2="90" class="color-split" stroke-width="3" />
|
|
|
|
|
|
|
|
|
<circle cx="140" cy="5" r="10" class="color-prediction" />
|
|
|
<text x="160" y="15" fill="#ff00ff" font-weight="700" font-size="14">New X</text>
|
|
|
|
|
|
|
|
|
<line x1="140" y1="15" x2="70" y2="90" class="color-path" />
|
|
|
</svg>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="nav-buttons" role="group" aria-label="Step navigation">
|
|
|
<button id="prevBtn" disabled aria-disabled="true" aria-label="Previous step">← Previous</button>
|
|
|
<button id="nextBtn" aria-label="Next step">Next →</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
const steps = document.querySelectorAll('.step');
|
|
|
const contents = document.querySelectorAll('.content > div');
|
|
|
const prevBtn = document.getElementById('prevBtn');
|
|
|
const nextBtn = document.getElementById('nextBtn');
|
|
|
|
|
|
let currentStep = 0;
|
|
|
|
|
|
function updateUI() {
|
|
|
steps.forEach((step, i) => {
|
|
|
step.classList.toggle('active', i === currentStep);
|
|
|
step.classList.toggle('completed', i < currentStep);
|
|
|
step.setAttribute('aria-selected', i === currentStep ? 'true' : 'false');
|
|
|
step.tabIndex = i === currentStep ? 0 : -1;
|
|
|
});
|
|
|
|
|
|
contents.forEach((content, i) => {
|
|
|
content.classList.toggle('active', i === currentStep);
|
|
|
});
|
|
|
|
|
|
prevBtn.disabled = currentStep === 0;
|
|
|
prevBtn.setAttribute('aria-disabled', currentStep === 0 ? 'true' : 'false');
|
|
|
nextBtn.disabled = currentStep === steps.length - 1;
|
|
|
nextBtn.setAttribute('aria-disabled', currentStep === steps.length - 1 ? 'true' : 'false');
|
|
|
}
|
|
|
|
|
|
prevBtn.addEventListener('click', () => {
|
|
|
if (currentStep > 0) {
|
|
|
currentStep--;
|
|
|
updateUI();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
nextBtn.addEventListener('click', () => {
|
|
|
if (currentStep < steps.length - 1) {
|
|
|
currentStep++;
|
|
|
updateUI();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
steps.forEach(step => {
|
|
|
step.addEventListener('click', () => {
|
|
|
currentStep = parseInt(step.dataset.step);
|
|
|
updateUI();
|
|
|
});
|
|
|
step.addEventListener('keydown', e => {
|
|
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
|
e.preventDefault();
|
|
|
currentStep = parseInt(step.dataset.step);
|
|
|
updateUI();
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
updateUI();
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{% endblock %}
|
|
|
|