File size: 4,203 Bytes
dae061a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Quadrants</title>
  <style>
    :root {
      color-scheme: light;
    }
    body {
      margin: 0;
      padding: 20px;
      font-family: Segoe UI, Arial, sans-serif;
      background: #f5f7fb;
      color: #1f2a37;
    }
    h1 {
      margin: 0 0 10px 0;
      font-size: 20px;
      font-weight: 600;
    }
    #legend-container {
      margin-bottom: 8px;
    }
    #chart-wrap {
      position: relative;
      width: min(1100px, 100%);
      height: 520px;
      background: #ffffff;
      border: 1px solid #e2e8f0;
      border-radius: 10px;
      padding: 12px;
      box-sizing: border-box;
    }
    #chart {
      width: 100%;
      height: 100%;
    }
  </style>
  <script src="./luxon.min.js"></script>
  <script src="./chart.umd.min.js"></script>
  <script src="./chartjs-adapter-luxon.umd.min.js"></script>
</head>
<body>
  <h1>Quadrants</h1>
  <div id="legend-container"></div>
  <div id="chart-wrap">
    <canvas id="chart"></canvas>
  </div>
    <script type="text/plain" data-chart-inline="true">
  const DATA_COUNT = 7;
  const NUMBER_CFG = {count: DATA_COUNT, min: -100, max: 100};
  const data = {
    datasets: [
      {
        label: 'Dataset 1',
        data: [{x: -74.08521948, y: -12.27280521}, {x: 50.00085734, y: -67.40483539}, {x: -40.93364198, y: -68.42163923}, {x: 40.76560357, y: 53.81258573}, {x: 75.34550754, y: 49.91512346}, {x: -8.79886831, y: 40.87362826}, {x: -46.23542524, y: -59.73165295}],
        borderColor: Utils.CHART_COLORS.red,
        backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
      },
      {
        label: 'Dataset 2',
        data: [{x: 9.8276749, y: 24.31498628}, {x: -51.6829561, y: -11.47548011}, {x: -86.2388546, y: 11.78755144}, {x: 78.9994856, y: -73.79715364}, {x: -79.42472565, y: 23.12842936}, {x: 40.95764746, y: 8.73713992}, {x: -75.90277778, y: 92.90552126}],
        borderColor: Utils.CHART_COLORS.blue,
        backgroundColor: Utils.transparentize(Utils.CHART_COLORS.blue, 0.5),
      }
    ]
  };
  
  const quadrants = {
    id: 'quadrants',
    beforeDraw(chart, args, options) {
      const {ctx, chartArea: {left, top, right, bottom}, scales: {x, y}} = chart;
      const midX = x.getPixelForValue(0);
      const midY = y.getPixelForValue(0);
      ctx.save();
      ctx.fillStyle = options.topLeft;
      ctx.fillRect(left, top, midX - left, midY - top);
      ctx.fillStyle = options.topRight;
      ctx.fillRect(midX, top, right - midX, midY - top);
      ctx.fillStyle = options.bottomRight;
      ctx.fillRect(midX, midY, right - midX, bottom - midY);
      ctx.fillStyle = options.bottomLeft;
      ctx.fillRect(left, midY, midX - left, bottom - midY);
      ctx.restore();
    }
  };
  
  const config = {
    type: 'scatter',
    data: data,
    options: {
      plugins: {
        quadrants: {
          topLeft: Utils.CHART_COLORS.red,
          topRight: Utils.CHART_COLORS.blue,
          bottomRight: Utils.CHART_COLORS.green,
          bottomLeft: Utils.CHART_COLORS.yellow,
        }
      }
    },
    plugins: [quadrants]
  };
  
  function forceEnableHoverTooltip(chartConfig) {
    if (!chartConfig || typeof chartConfig !== 'object') {
      return;
    }
  
    if (!chartConfig.options || typeof chartConfig.options !== 'object') {
      chartConfig.options = {};
    }
  
    const options = chartConfig.options;
    if (!options.plugins || typeof options.plugins !== 'object') {
      options.plugins = {};
    }
  
    const plugins = options.plugins;
    if (plugins.tooltip === false) {
      plugins.tooltip = {};
    }
  
    if (!plugins.tooltip || typeof plugins.tooltip !== 'object') {
      plugins.tooltip = {};
    }
  
    const hasExternalTooltip = typeof plugins.tooltip.external === 'function';
    if (!hasExternalTooltip) {
      plugins.tooltip.enabled = true;
    }
  }
  
  forceEnableHoverTooltip(config);
  
  const sampleCanvas = document.getElementById('chart');
  const sampleChart = new Chart(sampleCanvas, config);
</script>
  <script src="./chart_0053_scatter.inline01.js"></script>
</body>
</html>