svelte-plots-basic 1.1.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +54 -69
  2. package/package.json +28 -33
  3. package/src/2d/Area.svelte +61 -0
  4. package/src/2d/Axes.svelte +500 -0
  5. package/src/2d/Axis.svelte +50 -0
  6. package/src/2d/AxisLines.svelte +54 -0
  7. package/src/2d/AxisTickLabels.svelte +82 -0
  8. package/src/2d/Bars.svelte +65 -0
  9. package/src/2d/Box.svelte +50 -0
  10. package/src/2d/ColorLegend.svelte +36 -0
  11. package/src/2d/Legend.svelte +148 -0
  12. package/src/2d/Lines.svelte +49 -0
  13. package/src/2d/Multilines.svelte +67 -0
  14. package/src/2d/Points.svelte +79 -0
  15. package/src/2d/Rectangles.svelte +74 -0
  16. package/src/2d/Segments.svelte +65 -0
  17. package/src/2d/TextLabels.svelte +107 -0
  18. package/src/2d/TextLegend.svelte +53 -0
  19. package/src/2d/XAxis.svelte +99 -0
  20. package/src/2d/YAxis.svelte +99 -0
  21. package/src/{index.js → 2d/index.js} +10 -6
  22. package/src/3d/Axes.svelte +445 -0
  23. package/src/3d/Axis.svelte +64 -0
  24. package/src/3d/AxisLines.svelte +50 -0
  25. package/src/3d/AxisTickLabels.svelte +54 -0
  26. package/src/3d/Lines.svelte +49 -0
  27. package/src/3d/Mesh.svelte +188 -0
  28. package/src/3d/Points.svelte +61 -0
  29. package/src/3d/Segments.svelte +69 -0
  30. package/src/3d/TextLabels.svelte +79 -0
  31. package/src/3d/XAxis.svelte +123 -0
  32. package/src/3d/YAxis.svelte +123 -0
  33. package/src/3d/ZAxis.svelte +123 -0
  34. package/src/3d/index.js +13 -0
  35. package/src/Colors.js +36 -1
  36. package/src/Utils.js +205 -0
  37. package/dist/index.js +0 -4209
  38. package/dist/index.mjs +0 -4187
  39. package/src/AreaSeries.svelte +0 -53
  40. package/src/Axes.svelte +0 -538
  41. package/src/BarSeries.svelte +0 -78
  42. package/src/Box.svelte +0 -35
  43. package/src/LineSeries.svelte +0 -50
  44. package/src/Rectangles.svelte +0 -64
  45. package/src/ScatterSeries.svelte +0 -85
  46. package/src/Segments.svelte +0 -48
  47. package/src/TextLabels.svelte +0 -78
  48. package/src/TextLegend.svelte +0 -38
  49. package/src/XAxis.svelte +0 -69
  50. package/src/YAxis.svelte +0 -72
package/dist/index.mjs DELETED
@@ -1,4187 +0,0 @@
1
- function noop() { }
2
- function assign(tar, src) {
3
- // @ts-ignore
4
- for (const k in src)
5
- tar[k] = src[k];
6
- return tar;
7
- }
8
- function run(fn) {
9
- return fn();
10
- }
11
- function blank_object() {
12
- return Object.create(null);
13
- }
14
- function run_all(fns) {
15
- fns.forEach(run);
16
- }
17
- function is_function(thing) {
18
- return typeof thing === 'function';
19
- }
20
- function safe_not_equal(a, b) {
21
- return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
22
- }
23
- function is_empty(obj) {
24
- return Object.keys(obj).length === 0;
25
- }
26
- function subscribe(store, ...callbacks) {
27
- if (store == null) {
28
- return noop;
29
- }
30
- const unsub = store.subscribe(...callbacks);
31
- return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
32
- }
33
- function component_subscribe(component, store, callback) {
34
- component.$$.on_destroy.push(subscribe(store, callback));
35
- }
36
- function create_slot(definition, ctx, $$scope, fn) {
37
- if (definition) {
38
- const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
39
- return definition[0](slot_ctx);
40
- }
41
- }
42
- function get_slot_context(definition, ctx, $$scope, fn) {
43
- return definition[1] && fn
44
- ? assign($$scope.ctx.slice(), definition[1](fn(ctx)))
45
- : $$scope.ctx;
46
- }
47
- function get_slot_changes(definition, $$scope, dirty, fn) {
48
- if (definition[2] && fn) {
49
- const lets = definition[2](fn(dirty));
50
- if ($$scope.dirty === undefined) {
51
- return lets;
52
- }
53
- if (typeof lets === 'object') {
54
- const merged = [];
55
- const len = Math.max($$scope.dirty.length, lets.length);
56
- for (let i = 0; i < len; i += 1) {
57
- merged[i] = $$scope.dirty[i] | lets[i];
58
- }
59
- return merged;
60
- }
61
- return $$scope.dirty | lets;
62
- }
63
- return $$scope.dirty;
64
- }
65
- function update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) {
66
- if (slot_changes) {
67
- const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
68
- slot.p(slot_context, slot_changes);
69
- }
70
- }
71
- function get_all_dirty_from_scope($$scope) {
72
- if ($$scope.ctx.length > 32) {
73
- const dirty = [];
74
- const length = $$scope.ctx.length / 32;
75
- for (let i = 0; i < length; i++) {
76
- dirty[i] = -1;
77
- }
78
- return dirty;
79
- }
80
- return -1;
81
- }
82
- function append(target, node) {
83
- target.appendChild(node);
84
- }
85
- function append_styles(target, style_sheet_id, styles) {
86
- const append_styles_to = get_root_for_style(target);
87
- if (!append_styles_to.getElementById(style_sheet_id)) {
88
- const style = element('style');
89
- style.id = style_sheet_id;
90
- style.textContent = styles;
91
- append_stylesheet(append_styles_to, style);
92
- }
93
- }
94
- function get_root_for_style(node) {
95
- if (!node)
96
- return document;
97
- const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
98
- if (root && root.host) {
99
- return root;
100
- }
101
- return node.ownerDocument;
102
- }
103
- function append_stylesheet(node, style) {
104
- append(node.head || node, style);
105
- return style.sheet;
106
- }
107
- function insert(target, node, anchor) {
108
- target.insertBefore(node, anchor || null);
109
- }
110
- function detach(node) {
111
- node.parentNode.removeChild(node);
112
- }
113
- function destroy_each(iterations, detaching) {
114
- for (let i = 0; i < iterations.length; i += 1) {
115
- if (iterations[i])
116
- iterations[i].d(detaching);
117
- }
118
- }
119
- function element(name) {
120
- return document.createElement(name);
121
- }
122
- function svg_element(name) {
123
- return document.createElementNS('http://www.w3.org/2000/svg', name);
124
- }
125
- function text(data) {
126
- return document.createTextNode(data);
127
- }
128
- function space() {
129
- return text(' ');
130
- }
131
- function empty() {
132
- return text('');
133
- }
134
- function listen(node, event, handler, options) {
135
- node.addEventListener(event, handler, options);
136
- return () => node.removeEventListener(event, handler, options);
137
- }
138
- function attr(node, attribute, value) {
139
- if (value == null)
140
- node.removeAttribute(attribute);
141
- else if (node.getAttribute(attribute) !== value)
142
- node.setAttribute(attribute, value);
143
- }
144
- function children(element) {
145
- return Array.from(element.childNodes);
146
- }
147
- function set_data(text, data) {
148
- data = '' + data;
149
- if (text.wholeText !== data)
150
- text.data = data;
151
- }
152
- function set_style(node, key, value, important) {
153
- if (value === null) {
154
- node.style.removeProperty(key);
155
- }
156
- else {
157
- node.style.setProperty(key, value, important ? 'important' : '');
158
- }
159
- }
160
- function toggle_class(element, name, toggle) {
161
- element.classList[toggle ? 'add' : 'remove'](name);
162
- }
163
- function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) {
164
- const e = document.createEvent('CustomEvent');
165
- e.initCustomEvent(type, bubbles, cancelable, detail);
166
- return e;
167
- }
168
-
169
- let current_component;
170
- function set_current_component(component) {
171
- current_component = component;
172
- }
173
- function get_current_component() {
174
- if (!current_component)
175
- throw new Error('Function called outside component initialization');
176
- return current_component;
177
- }
178
- function onMount(fn) {
179
- get_current_component().$$.on_mount.push(fn);
180
- }
181
- function onDestroy(fn) {
182
- get_current_component().$$.on_destroy.push(fn);
183
- }
184
- function createEventDispatcher() {
185
- const component = get_current_component();
186
- return (type, detail, { cancelable = false } = {}) => {
187
- const callbacks = component.$$.callbacks[type];
188
- if (callbacks) {
189
- // TODO are there situations where events could be dispatched
190
- // in a server (non-DOM) environment?
191
- const event = custom_event(type, detail, { cancelable });
192
- callbacks.slice().forEach(fn => {
193
- fn.call(component, event);
194
- });
195
- return !event.defaultPrevented;
196
- }
197
- return true;
198
- };
199
- }
200
- function setContext(key, context) {
201
- get_current_component().$$.context.set(key, context);
202
- return context;
203
- }
204
- function getContext(key) {
205
- return get_current_component().$$.context.get(key);
206
- }
207
-
208
- const dirty_components = [];
209
- const binding_callbacks = [];
210
- const render_callbacks = [];
211
- const flush_callbacks = [];
212
- const resolved_promise = Promise.resolve();
213
- let update_scheduled = false;
214
- function schedule_update() {
215
- if (!update_scheduled) {
216
- update_scheduled = true;
217
- resolved_promise.then(flush);
218
- }
219
- }
220
- function add_render_callback(fn) {
221
- render_callbacks.push(fn);
222
- }
223
- // flush() calls callbacks in this order:
224
- // 1. All beforeUpdate callbacks, in order: parents before children
225
- // 2. All bind:this callbacks, in reverse order: children before parents.
226
- // 3. All afterUpdate callbacks, in order: parents before children. EXCEPT
227
- // for afterUpdates called during the initial onMount, which are called in
228
- // reverse order: children before parents.
229
- // Since callbacks might update component values, which could trigger another
230
- // call to flush(), the following steps guard against this:
231
- // 1. During beforeUpdate, any updated components will be added to the
232
- // dirty_components array and will cause a reentrant call to flush(). Because
233
- // the flush index is kept outside the function, the reentrant call will pick
234
- // up where the earlier call left off and go through all dirty components. The
235
- // current_component value is saved and restored so that the reentrant call will
236
- // not interfere with the "parent" flush() call.
237
- // 2. bind:this callbacks cannot trigger new flush() calls.
238
- // 3. During afterUpdate, any updated components will NOT have their afterUpdate
239
- // callback called a second time; the seen_callbacks set, outside the flush()
240
- // function, guarantees this behavior.
241
- const seen_callbacks = new Set();
242
- let flushidx = 0; // Do *not* move this inside the flush() function
243
- function flush() {
244
- const saved_component = current_component;
245
- do {
246
- // first, call beforeUpdate functions
247
- // and update components
248
- while (flushidx < dirty_components.length) {
249
- const component = dirty_components[flushidx];
250
- flushidx++;
251
- set_current_component(component);
252
- update(component.$$);
253
- }
254
- set_current_component(null);
255
- dirty_components.length = 0;
256
- flushidx = 0;
257
- while (binding_callbacks.length)
258
- binding_callbacks.pop()();
259
- // then, once components are updated, call
260
- // afterUpdate functions. This may cause
261
- // subsequent updates...
262
- for (let i = 0; i < render_callbacks.length; i += 1) {
263
- const callback = render_callbacks[i];
264
- if (!seen_callbacks.has(callback)) {
265
- // ...so guard against infinite loops
266
- seen_callbacks.add(callback);
267
- callback();
268
- }
269
- }
270
- render_callbacks.length = 0;
271
- } while (dirty_components.length);
272
- while (flush_callbacks.length) {
273
- flush_callbacks.pop()();
274
- }
275
- update_scheduled = false;
276
- seen_callbacks.clear();
277
- set_current_component(saved_component);
278
- }
279
- function update($$) {
280
- if ($$.fragment !== null) {
281
- $$.update();
282
- run_all($$.before_update);
283
- const dirty = $$.dirty;
284
- $$.dirty = [-1];
285
- $$.fragment && $$.fragment.p($$.ctx, dirty);
286
- $$.after_update.forEach(add_render_callback);
287
- }
288
- }
289
- const outroing = new Set();
290
- let outros;
291
- function group_outros() {
292
- outros = {
293
- r: 0,
294
- c: [],
295
- p: outros // parent group
296
- };
297
- }
298
- function check_outros() {
299
- if (!outros.r) {
300
- run_all(outros.c);
301
- }
302
- outros = outros.p;
303
- }
304
- function transition_in(block, local) {
305
- if (block && block.i) {
306
- outroing.delete(block);
307
- block.i(local);
308
- }
309
- }
310
- function transition_out(block, local, detach, callback) {
311
- if (block && block.o) {
312
- if (outroing.has(block))
313
- return;
314
- outroing.add(block);
315
- outros.c.push(() => {
316
- outroing.delete(block);
317
- if (callback) {
318
- if (detach)
319
- block.d(1);
320
- callback();
321
- }
322
- });
323
- block.o(local);
324
- }
325
- else if (callback) {
326
- callback();
327
- }
328
- }
329
- function create_component(block) {
330
- block && block.c();
331
- }
332
- function mount_component(component, target, anchor, customElement) {
333
- const { fragment, on_mount, on_destroy, after_update } = component.$$;
334
- fragment && fragment.m(target, anchor);
335
- if (!customElement) {
336
- // onMount happens before the initial afterUpdate
337
- add_render_callback(() => {
338
- const new_on_destroy = on_mount.map(run).filter(is_function);
339
- if (on_destroy) {
340
- on_destroy.push(...new_on_destroy);
341
- }
342
- else {
343
- // Edge case - component was destroyed immediately,
344
- // most likely as a result of a binding initialising
345
- run_all(new_on_destroy);
346
- }
347
- component.$$.on_mount = [];
348
- });
349
- }
350
- after_update.forEach(add_render_callback);
351
- }
352
- function destroy_component(component, detaching) {
353
- const $$ = component.$$;
354
- if ($$.fragment !== null) {
355
- run_all($$.on_destroy);
356
- $$.fragment && $$.fragment.d(detaching);
357
- // TODO null out other refs, including component.$$ (but need to
358
- // preserve final state?)
359
- $$.on_destroy = $$.fragment = null;
360
- $$.ctx = [];
361
- }
362
- }
363
- function make_dirty(component, i) {
364
- if (component.$$.dirty[0] === -1) {
365
- dirty_components.push(component);
366
- schedule_update();
367
- component.$$.dirty.fill(0);
368
- }
369
- component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
370
- }
371
- function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
372
- const parent_component = current_component;
373
- set_current_component(component);
374
- const $$ = component.$$ = {
375
- fragment: null,
376
- ctx: null,
377
- // state
378
- props,
379
- update: noop,
380
- not_equal,
381
- bound: blank_object(),
382
- // lifecycle
383
- on_mount: [],
384
- on_destroy: [],
385
- on_disconnect: [],
386
- before_update: [],
387
- after_update: [],
388
- context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
389
- // everything else
390
- callbacks: blank_object(),
391
- dirty,
392
- skip_bound: false,
393
- root: options.target || parent_component.$$.root
394
- };
395
- append_styles && append_styles($$.root);
396
- let ready = false;
397
- $$.ctx = instance
398
- ? instance(component, options.props || {}, (i, ret, ...rest) => {
399
- const value = rest.length ? rest[0] : ret;
400
- if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
401
- if (!$$.skip_bound && $$.bound[i])
402
- $$.bound[i](value);
403
- if (ready)
404
- make_dirty(component, i);
405
- }
406
- return ret;
407
- })
408
- : [];
409
- $$.update();
410
- ready = true;
411
- run_all($$.before_update);
412
- // `false` as a special case of no DOM component
413
- $$.fragment = create_fragment ? create_fragment($$.ctx) : false;
414
- if (options.target) {
415
- if (options.hydrate) {
416
- const nodes = children(options.target);
417
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
418
- $$.fragment && $$.fragment.l(nodes);
419
- nodes.forEach(detach);
420
- }
421
- else {
422
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
423
- $$.fragment && $$.fragment.c();
424
- }
425
- if (options.intro)
426
- transition_in(component.$$.fragment);
427
- mount_component(component, options.target, options.anchor, options.customElement);
428
- flush();
429
- }
430
- set_current_component(parent_component);
431
- }
432
- /**
433
- * Base class for Svelte components. Used when dev=false.
434
- */
435
- class SvelteComponent {
436
- $destroy() {
437
- destroy_component(this, 1);
438
- this.$destroy = noop;
439
- }
440
- $on(type, callback) {
441
- const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
442
- callbacks.push(callback);
443
- return () => {
444
- const index = callbacks.indexOf(callback);
445
- if (index !== -1)
446
- callbacks.splice(index, 1);
447
- };
448
- }
449
- $set($$props) {
450
- if (this.$$set && !is_empty($$props)) {
451
- this.$$.skip_bound = true;
452
- this.$$set($$props);
453
- this.$$.skip_bound = false;
454
- }
455
- }
456
- }
457
-
458
- const subscriber_queue = [];
459
- /**
460
- * Create a `Writable` store that allows both updating and reading by subscription.
461
- * @param {*=}value initial value
462
- * @param {StartStopNotifier=}start start and stop notifications for subscriptions
463
- */
464
- function writable(value, start = noop) {
465
- let stop;
466
- const subscribers = new Set();
467
- function set(new_value) {
468
- if (safe_not_equal(value, new_value)) {
469
- value = new_value;
470
- if (stop) { // store is ready
471
- const run_queue = !subscriber_queue.length;
472
- for (const subscriber of subscribers) {
473
- subscriber[1]();
474
- subscriber_queue.push(subscriber, value);
475
- }
476
- if (run_queue) {
477
- for (let i = 0; i < subscriber_queue.length; i += 2) {
478
- subscriber_queue[i][0](subscriber_queue[i + 1]);
479
- }
480
- subscriber_queue.length = 0;
481
- }
482
- }
483
- }
484
- }
485
- function update(fn) {
486
- set(fn(value));
487
- }
488
- function subscribe(run, invalidate = noop) {
489
- const subscriber = [run, invalidate];
490
- subscribers.add(subscriber);
491
- if (subscribers.size === 1) {
492
- stop = start(set) || noop;
493
- }
494
- run(value);
495
- return () => {
496
- subscribers.delete(subscriber);
497
- if (subscribers.size === 0) {
498
- stop();
499
- stop = null;
500
- }
501
- };
502
- }
503
- return { set, update, subscribe };
504
- }
505
-
506
- /* src/Axes.svelte generated by Svelte v3.50.1 */
507
-
508
- function add_css$3(target) {
509
- append_styles(target, "svelte-jxlrcp", ".plot{font-family:Arial, Helvetica, sans-serif;display:grid;grid-template-columns:min-content auto;grid-template-rows:min-content auto min-content;grid-template-areas:\". title\"\n \"ylab axes\"\n \". xlab\";box-sizing:border-box;background:#fefefe;min-width:100px;min-height:50px;width:100%;height:100%;padding:0;margin:0}.plot_small{font-size:11px}.plot_medium{font-size:13px}.plot_large{font-size:16px}.plot_error{display:flex}.plot_error > .axes-wrapper{display:none}.message_error{font-size:1.2em;color:crimson;padding:20px;text-align:center}.axes-wrapper.svelte-jxlrcp{grid-area:axes;position:relative;box-sizing:border-box;display:flex;width:100%;height:100%;padding:0;margin:0}.axes{display:block;box-sizing:border-box;position:absolute;padding:0;margin:0;height:100%;width:100%;max-height:100%;max-width:100%;min-height:100%;min-width:100%}.axes-content{padding:0;margin:0;height:100%;width:100%;max-height:100%;max-width:100%;min-height:100%;min-width:100%}.axes__xlabel{grid-area:xlab;font-size:1.0em;font-weight:600;padding:0.25em;text-align:center}.axes__ylabel{grid-area:ylab;font-size:1.0em;font-weight:600;padding:0.25em;text-align:center;vertical-align:middle;display:flex}.axes__ylabel > span{width:1.5em;line-height:1.5em;display:inline-block;writing-mode:vertical-rl;transform:rotate(180deg)}.axes__title{background:transparent;grid-area:title;font-size:1.3em;font-weight:bold;line-height:1.2em;padding:0.5em 0;text-align:center}.axis-labels{fill:#303030;font-size:0.95em}.labels{fill:#606060;font-size:0.90em}.labels{visibility:hidden;transition:visibility 0.25s linear, opacity 0.25s linear;opacity:0}");
510
- }
511
-
512
- const get_box_slot_changes = dirty => ({});
513
- const get_box_slot_context = ctx => ({});
514
- const get_yaxis_slot_changes = dirty => ({});
515
- const get_yaxis_slot_context = ctx => ({});
516
- const get_xaxis_slot_changes = dirty => ({});
517
- const get_xaxis_slot_context = ctx => ({});
518
-
519
- // (352:3) {#if title !== ""}
520
- function create_if_block_3(ctx) {
521
- let div;
522
-
523
- return {
524
- c() {
525
- div = element("div");
526
- attr(div, "class", "axes__title");
527
- },
528
- m(target, anchor) {
529
- insert(target, div, anchor);
530
- div.innerHTML = /*title*/ ctx[0];
531
- },
532
- p(ctx, dirty) {
533
- if (dirty[0] & /*title*/ 1) div.innerHTML = /*title*/ ctx[0]; },
534
- d(detaching) {
535
- if (detaching) detach(div);
536
- }
537
- };
538
- }
539
-
540
- // (353:3) {#if yLabel !== ""}
541
- function create_if_block_2(ctx) {
542
- let div;
543
- let span;
544
-
545
- return {
546
- c() {
547
- div = element("div");
548
- span = element("span");
549
- attr(div, "class", "axes__ylabel");
550
- },
551
- m(target, anchor) {
552
- insert(target, div, anchor);
553
- append(div, span);
554
- span.innerHTML = /*yLabel*/ ctx[2];
555
- },
556
- p(ctx, dirty) {
557
- if (dirty[0] & /*yLabel*/ 4) span.innerHTML = /*yLabel*/ ctx[2]; },
558
- d(detaching) {
559
- if (detaching) detach(div);
560
- }
561
- };
562
- }
563
-
564
- // (354:3) {#if xLabel !== ""}
565
- function create_if_block_1(ctx) {
566
- let div;
567
- let span;
568
-
569
- return {
570
- c() {
571
- div = element("div");
572
- span = element("span");
573
- attr(div, "class", "axes__xlabel");
574
- },
575
- m(target, anchor) {
576
- insert(target, div, anchor);
577
- append(div, span);
578
- span.innerHTML = /*xLabel*/ ctx[1];
579
- },
580
- p(ctx, dirty) {
581
- if (dirty[0] & /*xLabel*/ 2) span.innerHTML = /*xLabel*/ ctx[1]; },
582
- d(detaching) {
583
- if (detaching) detach(div);
584
- }
585
- };
586
- }
587
-
588
- // (382:3) {#if !$isOk}
589
- function create_if_block$9(ctx) {
590
- let p;
591
-
592
- return {
593
- c() {
594
- p = element("p");
595
-
596
- p.innerHTML = `Axes component was not properly initialized. <br/>
597
- Add plot series (check that coordinates are numeric) or define axes limits manually.`;
598
-
599
- attr(p, "class", "message_error");
600
- },
601
- m(target, anchor) {
602
- insert(target, p, anchor);
603
- },
604
- d(detaching) {
605
- if (detaching) detach(p);
606
- }
607
- };
608
- }
609
-
610
- function create_fragment$b(ctx) {
611
- let div1;
612
- let t0;
613
- let t1;
614
- let t2;
615
- let div0;
616
- let svg;
617
- let defs;
618
- let clipPath;
619
- let rect;
620
- let rect_x_value;
621
- let rect_y_value;
622
- let rect_width_value;
623
- let rect_height_value;
624
- let g;
625
- let t3;
626
- let div1_class_value;
627
- let current;
628
- let mounted;
629
- let dispose;
630
- let if_block0 = /*title*/ ctx[0] !== "" && create_if_block_3(ctx);
631
- let if_block1 = /*yLabel*/ ctx[2] !== "" && create_if_block_2(ctx);
632
- let if_block2 = /*xLabel*/ ctx[1] !== "" && create_if_block_1(ctx);
633
- const xaxis_slot_template = /*#slots*/ ctx[27].xaxis;
634
- const xaxis_slot = create_slot(xaxis_slot_template, ctx, /*$$scope*/ ctx[26], get_xaxis_slot_context);
635
- const yaxis_slot_template = /*#slots*/ ctx[27].yaxis;
636
- const yaxis_slot = create_slot(yaxis_slot_template, ctx, /*$$scope*/ ctx[26], get_yaxis_slot_context);
637
- const default_slot_template = /*#slots*/ ctx[27].default;
638
- const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[26], null);
639
- const box_slot_template = /*#slots*/ ctx[27].box;
640
- const box_slot = create_slot(box_slot_template, ctx, /*$$scope*/ ctx[26], get_box_slot_context);
641
- let if_block3 = !/*$isOk*/ ctx[3] && create_if_block$9();
642
-
643
- return {
644
- c() {
645
- div1 = element("div");
646
- if (if_block0) if_block0.c();
647
- t0 = space();
648
- if (if_block1) if_block1.c();
649
- t1 = space();
650
- if (if_block2) if_block2.c();
651
- t2 = space();
652
- div0 = element("div");
653
- svg = svg_element("svg");
654
- defs = svg_element("defs");
655
- clipPath = svg_element("clipPath");
656
- rect = svg_element("rect");
657
- if (xaxis_slot) xaxis_slot.c();
658
- if (yaxis_slot) yaxis_slot.c();
659
- g = svg_element("g");
660
- if (default_slot) default_slot.c();
661
- if (box_slot) box_slot.c();
662
- t3 = space();
663
- if (if_block3) if_block3.c();
664
- set_style(rect, "pointer-events", "none");
665
- attr(rect, "x", rect_x_value = /*cpx*/ ctx[8][0]);
666
- attr(rect, "y", rect_y_value = /*cpy*/ ctx[7][1]);
667
- attr(rect, "width", rect_width_value = /*cpx*/ ctx[8][1] - /*cpx*/ ctx[8][0]);
668
- attr(rect, "height", rect_height_value = /*cpy*/ ctx[7][0] - /*cpy*/ ctx[7][1]);
669
- attr(clipPath, "id", /*clipPathID*/ ctx[9]);
670
- attr(g, "class", "axes-content");
671
- attr(g, "clip-path", "url(#" + /*clipPathID*/ ctx[9] + ")");
672
- attr(svg, "preserveAspectRatio", "none");
673
- attr(svg, "class", "axes");
674
- attr(div0, "class", "axes-wrapper svelte-jxlrcp");
675
- attr(div1, "class", div1_class_value = "plot " + ('plot_' + /*$scale*/ ctx[4]) + " svelte-jxlrcp");
676
- toggle_class(div1, "plot_error", !/*$isOk*/ ctx[3]);
677
- },
678
- m(target, anchor) {
679
- insert(target, div1, anchor);
680
- if (if_block0) if_block0.m(div1, null);
681
- append(div1, t0);
682
- if (if_block1) if_block1.m(div1, null);
683
- append(div1, t1);
684
- if (if_block2) if_block2.m(div1, null);
685
- append(div1, t2);
686
- append(div1, div0);
687
- append(div0, svg);
688
- append(svg, defs);
689
- append(defs, clipPath);
690
- append(clipPath, rect);
691
-
692
- if (xaxis_slot) {
693
- xaxis_slot.m(svg, null);
694
- }
695
-
696
- if (yaxis_slot) {
697
- yaxis_slot.m(svg, null);
698
- }
699
-
700
- append(svg, g);
701
-
702
- if (default_slot) {
703
- default_slot.m(g, null);
704
- }
705
-
706
- if (box_slot) {
707
- box_slot.m(svg, null);
708
- }
709
-
710
- /*div0_binding*/ ctx[28](div0);
711
- append(div1, t3);
712
- if (if_block3) if_block3.m(div1, null);
713
- /*div1_binding*/ ctx[29](div1);
714
- current = true;
715
-
716
- if (!mounted) {
717
- dispose = listen(svg, "click", /*handleClick*/ ctx[16]);
718
- mounted = true;
719
- }
720
- },
721
- p(ctx, dirty) {
722
- if (/*title*/ ctx[0] !== "") {
723
- if (if_block0) {
724
- if_block0.p(ctx, dirty);
725
- } else {
726
- if_block0 = create_if_block_3(ctx);
727
- if_block0.c();
728
- if_block0.m(div1, t0);
729
- }
730
- } else if (if_block0) {
731
- if_block0.d(1);
732
- if_block0 = null;
733
- }
734
-
735
- if (/*yLabel*/ ctx[2] !== "") {
736
- if (if_block1) {
737
- if_block1.p(ctx, dirty);
738
- } else {
739
- if_block1 = create_if_block_2(ctx);
740
- if_block1.c();
741
- if_block1.m(div1, t1);
742
- }
743
- } else if (if_block1) {
744
- if_block1.d(1);
745
- if_block1 = null;
746
- }
747
-
748
- if (/*xLabel*/ ctx[1] !== "") {
749
- if (if_block2) {
750
- if_block2.p(ctx, dirty);
751
- } else {
752
- if_block2 = create_if_block_1(ctx);
753
- if_block2.c();
754
- if_block2.m(div1, t2);
755
- }
756
- } else if (if_block2) {
757
- if_block2.d(1);
758
- if_block2 = null;
759
- }
760
-
761
- if (!current || dirty[0] & /*cpx*/ 256 && rect_x_value !== (rect_x_value = /*cpx*/ ctx[8][0])) {
762
- attr(rect, "x", rect_x_value);
763
- }
764
-
765
- if (!current || dirty[0] & /*cpy*/ 128 && rect_y_value !== (rect_y_value = /*cpy*/ ctx[7][1])) {
766
- attr(rect, "y", rect_y_value);
767
- }
768
-
769
- if (!current || dirty[0] & /*cpx*/ 256 && rect_width_value !== (rect_width_value = /*cpx*/ ctx[8][1] - /*cpx*/ ctx[8][0])) {
770
- attr(rect, "width", rect_width_value);
771
- }
772
-
773
- if (!current || dirty[0] & /*cpy*/ 128 && rect_height_value !== (rect_height_value = /*cpy*/ ctx[7][0] - /*cpy*/ ctx[7][1])) {
774
- attr(rect, "height", rect_height_value);
775
- }
776
-
777
- if (xaxis_slot) {
778
- if (xaxis_slot.p && (!current || dirty[0] & /*$$scope*/ 67108864)) {
779
- update_slot_base(
780
- xaxis_slot,
781
- xaxis_slot_template,
782
- ctx,
783
- /*$$scope*/ ctx[26],
784
- !current
785
- ? get_all_dirty_from_scope(/*$$scope*/ ctx[26])
786
- : get_slot_changes(xaxis_slot_template, /*$$scope*/ ctx[26], dirty, get_xaxis_slot_changes),
787
- get_xaxis_slot_context
788
- );
789
- }
790
- }
791
-
792
- if (yaxis_slot) {
793
- if (yaxis_slot.p && (!current || dirty[0] & /*$$scope*/ 67108864)) {
794
- update_slot_base(
795
- yaxis_slot,
796
- yaxis_slot_template,
797
- ctx,
798
- /*$$scope*/ ctx[26],
799
- !current
800
- ? get_all_dirty_from_scope(/*$$scope*/ ctx[26])
801
- : get_slot_changes(yaxis_slot_template, /*$$scope*/ ctx[26], dirty, get_yaxis_slot_changes),
802
- get_yaxis_slot_context
803
- );
804
- }
805
- }
806
-
807
- if (default_slot) {
808
- if (default_slot.p && (!current || dirty[0] & /*$$scope*/ 67108864)) {
809
- update_slot_base(
810
- default_slot,
811
- default_slot_template,
812
- ctx,
813
- /*$$scope*/ ctx[26],
814
- !current
815
- ? get_all_dirty_from_scope(/*$$scope*/ ctx[26])
816
- : get_slot_changes(default_slot_template, /*$$scope*/ ctx[26], dirty, null),
817
- null
818
- );
819
- }
820
- }
821
-
822
- if (box_slot) {
823
- if (box_slot.p && (!current || dirty[0] & /*$$scope*/ 67108864)) {
824
- update_slot_base(
825
- box_slot,
826
- box_slot_template,
827
- ctx,
828
- /*$$scope*/ ctx[26],
829
- !current
830
- ? get_all_dirty_from_scope(/*$$scope*/ ctx[26])
831
- : get_slot_changes(box_slot_template, /*$$scope*/ ctx[26], dirty, get_box_slot_changes),
832
- get_box_slot_context
833
- );
834
- }
835
- }
836
-
837
- if (!/*$isOk*/ ctx[3]) {
838
- if (if_block3) ; else {
839
- if_block3 = create_if_block$9();
840
- if_block3.c();
841
- if_block3.m(div1, null);
842
- }
843
- } else if (if_block3) {
844
- if_block3.d(1);
845
- if_block3 = null;
846
- }
847
-
848
- if (!current || dirty[0] & /*$scale*/ 16 && div1_class_value !== (div1_class_value = "plot " + ('plot_' + /*$scale*/ ctx[4]) + " svelte-jxlrcp")) {
849
- attr(div1, "class", div1_class_value);
850
- }
851
-
852
- if (!current || dirty[0] & /*$scale, $isOk*/ 24) {
853
- toggle_class(div1, "plot_error", !/*$isOk*/ ctx[3]);
854
- }
855
- },
856
- i(local) {
857
- if (current) return;
858
- transition_in(xaxis_slot, local);
859
- transition_in(yaxis_slot, local);
860
- transition_in(default_slot, local);
861
- transition_in(box_slot, local);
862
- current = true;
863
- },
864
- o(local) {
865
- transition_out(xaxis_slot, local);
866
- transition_out(yaxis_slot, local);
867
- transition_out(default_slot, local);
868
- transition_out(box_slot, local);
869
- current = false;
870
- },
871
- d(detaching) {
872
- if (detaching) detach(div1);
873
- if (if_block0) if_block0.d();
874
- if (if_block1) if_block1.d();
875
- if (if_block2) if_block2.d();
876
- if (xaxis_slot) xaxis_slot.d(detaching);
877
- if (yaxis_slot) yaxis_slot.d(detaching);
878
- if (default_slot) default_slot.d(detaching);
879
- if (box_slot) box_slot.d(detaching);
880
- /*div0_binding*/ ctx[28](null);
881
- if (if_block3) if_block3.d();
882
- /*div1_binding*/ ctx[29](null);
883
- mounted = false;
884
- dispose();
885
- }
886
- };
887
- }
888
-
889
- function niceNum(localRange, round) {
890
- const exponent = Math.floor(Math.log10(localRange));
891
- const fraction = localRange / Math.pow(10, exponent);
892
- let niceFraction;
893
-
894
- if (round) {
895
- if (fraction < 1.5) niceFraction = 1; else if (fraction < 3) niceFraction = 2; else if (fraction < 7) niceFraction = 5; else niceFraction = 10;
896
- } else {
897
- if (fraction <= 1) niceFraction = 1; else if (fraction <= 2) niceFraction = 2; else if (fraction <= 5) niceFraction = 5; else niceFraction = 10;
898
- }
899
-
900
- return niceFraction * Math.pow(10, exponent);
901
- }
902
-
903
- /** Computes a scale level
904
- * @param {numeric} width - width of plotting area in pixels
905
- * @param {numeric} height - height of plotting area in pixels
906
- * @returns {text} the scale level ("small", "medium" or "large")
907
- */
908
- function getScale(width, height) {
909
- if (height < 300.2 || width < 300.2) return "small";
910
- if (height < 600.2 || width < 600.2) return "medium";
911
- return "large";
912
- }
913
-
914
- function instance$b($$self, $$props, $$invalidate) {
915
- let margins;
916
- let cpx;
917
- let cpy;
918
- let $height;
919
- let $yLim;
920
- let $isOk;
921
- let $width;
922
- let $xLim;
923
- let $scale;
924
- let { $$slots: slots = {}, $$scope } = $$props;
925
- let { limX = [undefined, undefined] } = $$props;
926
- let { limY = [undefined, undefined] } = $$props;
927
- let { title = "" } = $$props;
928
- let { xLabel = "" } = $$props;
929
- let { yLabel = "" } = $$props;
930
- let { multiSeries = true } = $$props;
931
-
932
- // event dispatcher
933
- const dispatch = createEventDispatcher();
934
-
935
- // how big are margins (number of pixels in unit margin value) between axis and plot area if axis are shown
936
- const AXES_MARGIN_FACTORS = { "small": 30, "medium": 40, "large": 50 };
937
-
938
- // number of ticks along each axis
939
- const TICK_NUM = { "small": 5, "medium": 8, "large": 12 };
940
-
941
- // margin between plot series elements and data labels
942
- const LABELS_MARGIN = { "small": 10, "medium": 15, "large": 20 };
943
-
944
- // line styles for different scales and types
945
- const LINE_STYLES = {
946
- small: ["0", "3,3", "1,1", "3,1"],
947
- medium: ["0", "5,5", "2,2", "5,2"],
948
- large: ["0", "7,7", "3,3", "7,3"]
949
- };
950
-
951
- // constant to make clip path ID unique
952
- const clipPathID = "plottingArea" + Math.round(Math.random() * 10000);
953
-
954
- /* parameters for internal use inside the component */
955
- let plotElement;
956
-
957
- let axesElement;
958
- let axesMargins = [0.034, 0.034, 0.034, 0.034]; // initial margins (will be multiplied to FACTORS)
959
-
960
- /* reactive parameters to be shared with children via context */
961
- const width = writable(100); // actual width of plotting area in pixels
962
-
963
- component_subscribe($$self, width, value => $$invalidate(24, $width = value));
964
- const height = writable(100); // actual height of plotting area in pixels
965
- component_subscribe($$self, height, value => $$invalidate(22, $height = value));
966
- const xLim = writable([undefined, undefined]); // actual limits for x-axis in plot units
967
- component_subscribe($$self, xLim, value => $$invalidate(25, $xLim = value));
968
- const yLim = writable([undefined, undefined]); // actual limits for y-axis in plot units
969
- component_subscribe($$self, yLim, value => $$invalidate(23, $yLim = value));
970
- const scale = writable("medium"); // scale factor (how big the shown plot is)
971
- component_subscribe($$self, scale, value => $$invalidate(4, $scale = value));
972
- const isOk = writable(false); // are axes ready for drawing
973
- component_subscribe($$self, isOk, value => $$invalidate(3, $isOk = value));
974
-
975
- /** Adds margins for x-axis (e.g. when x-axis must be shown) */
976
- const addXAxisMargins = function () {
977
- $$invalidate(20, axesMargins[0] = 1, axesMargins);
978
- $$invalidate(20, axesMargins[2] = 0.5, axesMargins);
979
- $$invalidate(20, axesMargins[1] = axesMargins[1] > 0.5 ? axesMargins[1] : 0.5, axesMargins);
980
- $$invalidate(20, axesMargins[3] = axesMargins[3] > 0.5 ? axesMargins[3] : 0.5, axesMargins);
981
- };
982
-
983
- /** Adds margins for y-axis (e.g. when y-axis must be shown) */
984
- const addYAxisMargins = function () {
985
- $$invalidate(20, axesMargins[1] = 1, axesMargins);
986
- $$invalidate(20, axesMargins[3] = 0.5, axesMargins);
987
- $$invalidate(20, axesMargins[0] = axesMargins[0] > 0.5 ? axesMargins[0] : 0.5, axesMargins);
988
- $$invalidate(20, axesMargins[2] = axesMargins[2] > 0.5 ? axesMargins[2] : 0.5, axesMargins);
989
- };
990
-
991
- /** Adjusts limits for x-axis (e.g. when new series is added)
992
- * @param {Array} newLim - vector with new limits (two values)
993
- */
994
- const adjustXAxisLimits = function (newLim) {
995
- if (!limX.some(v => v === undefined)) return;
996
- xLim.update(lim => adjustAxisLimits(lim, newLim));
997
- };
998
-
999
- /** Adjusts limits for y-axis (e.g. when new series is added)
1000
- * @param {Array} newLim - vector with new limits (two values)
1001
- */
1002
- const adjustYAxisLimits = function (newLim) {
1003
- if (!limY.some(v => v === undefined)) return;
1004
- yLim.update(lim => adjustAxisLimits(lim, newLim));
1005
- };
1006
-
1007
- /** Adjusts x- or y- axis limits (e.g. when new elements are added)
1008
- * @param {Array} lim - vector with limits for current axis (two values)
1009
- * @param {Array} newLim - vector with new limits (two values)
1010
- * @returns {Array} vector with rescaled values
1011
- *
1012
- * The new limits are set separately for min and max. Either if current value is undefined or
1013
- * if new value is outside the current limits (smaller than min or larger than max).
1014
- */
1015
- const adjustAxisLimits = function (lim, newLim) {
1016
- let adjustedLim = [
1017
- lim[0] !== undefined && multiSeries === true && lim[0] < newLim[0]
1018
- ? lim[0]
1019
- : newLim[0],
1020
- lim[1] !== undefined && multiSeries === true && lim[1] > newLim[1]
1021
- ? lim[1]
1022
- : newLim[1]
1023
- ];
1024
-
1025
- // special case when both limits are zero
1026
- if (adjustedLim[0] === 0 && adjustedLim[1] === 0) {
1027
- adjustedLim = [-0.1, 0.1];
1028
- }
1029
-
1030
- // special case when limits are equal (add ±5%)
1031
- if (adjustedLim[0] === adjustedLim[1]) {
1032
- adjustedLim = [adjustedLim[0] * 0.95, adjustedLim[0] * 1.05];
1033
- }
1034
-
1035
- return adjustedLim;
1036
- };
1037
-
1038
- /** Rescales x-values from plot coordinates to screen (SVG) coordinates
1039
- * @param {Array} x - vector with coordinates (or objects size) in original plot coordinates
1040
- * @param {Array} xLim - vector with current limits for x-axis in original plot coordinates
1041
- * @param {number} width - width of coordinate system in pixels
1042
- * @param {boolean} doSizeScreen - scale size of objects (true) or coordinates
1043
- * @returns {Array} vector with rescaled values
1044
- */
1045
- const scaleX = function (x, xLim, width, doSizeScale = false) {
1046
- if (!$isOk || x === undefined || !Array.isArray(x)) return undefined;
1047
-
1048
- if (doSizeScale) {
1049
- // scale size of objects instead of coordinates
1050
- return x.map(v => v / (xLim[1] - xLim[0]) * (width - margins[1] - margins[3]));
1051
- }
1052
-
1053
- return x.map(v => (v - xLim[0]) / (xLim[1] - xLim[0]) * (width - margins[1] - margins[3]) + margins[1]);
1054
- };
1055
-
1056
- /** Rescales x-values from plot coordinates to screen (SVG) coordinates
1057
- * @param {Array} x - vector with coordinates (or objects size) in original plot coordinates
1058
- * @param {Array} xLim - vector with current limits for x-axis in original plot coordinates
1059
- * @param {number} width - width of coordinate system in pixels
1060
- * @param {boolean} doSizeScreen - scale size of objects (true) or coordinates
1061
- * @returns {Array} vector with rescaled values
1062
- */
1063
- const scaleY = function (y, yLim, height, doSizeScale = false) {
1064
- if (!$isOk || y === undefined || !Array.isArray(y)) return undefined;
1065
-
1066
- if (doSizeScale) {
1067
- // scale size of objects instead of coordinates
1068
- return y.map(v => v / (yLim[1] - yLim[0]) * (height - margins[0] - margins[2]));
1069
- }
1070
-
1071
- // for coordinates we also need to invert (flip) the y-axis
1072
- return y.map(v => (yLim[1] - v) / (yLim[1] - yLim[0]) * (height - margins[0] - margins[2]) + margins[2]);
1073
- };
1074
-
1075
- /** Computes nice tick values for axis
1076
- * @param {Array} ticks - vector with ticks if alredy available (if not, new will be computed)
1077
- * @param {Array} lim - vector with axis limits tickets must be computed for
1078
- * @param {number} maxTickNum - maximum number of ticks to compute
1079
- * @param {boolean} round - round or not the fractions when computing nice numbers for the ticks
1080
- * @returns {Array} a vector with computed tick positions
1081
- */
1082
- const getAxisTicks = function (ticks, lim, maxTickNum, round = true) {
1083
- // if ticks are already provided do not recompute them
1084
- if (ticks !== undefined) return ticks;
1085
-
1086
- // check if limits are ok
1087
- if (!Array.isArray(lim) || lim[0] === undefined || lim[1] === undefined) return undefined;
1088
-
1089
- // get range as a nice number and compute min, max and steps for the tick sequence
1090
- const range = niceNum(lim[1] - lim[0], round);
1091
-
1092
- const tickSpacing = niceNum(range / (maxTickNum - 1), round);
1093
- const tickMin = Math.ceil(lim[0] / tickSpacing) * tickSpacing;
1094
- const tickMax = Math.floor(lim[1] / tickSpacing) * tickSpacing;
1095
-
1096
- // recompute maxTickNum
1097
- maxTickNum = Math.round((tickMax - tickMin + 1) / tickSpacing) + 1;
1098
-
1099
- // create a sequence and return
1100
- ticks = [...Array(maxTickNum)].map((x, i) => tickMin + i * tickSpacing);
1101
-
1102
- // if step is smaller than 1 round values to remove small decimals accidentiall added by JS
1103
- if (Math.abs(tickSpacing) < 1) {
1104
- const r = Math.pow(10, 1 + Math.round(-Math.log10(tickSpacing)));
1105
- ticks = ticks.map(v => Math.round((v + Number.EPSILON) * r) / r);
1106
- }
1107
-
1108
- // make sure the ticks are not aligned with axes limits
1109
- return ticks.filter(x => x >= lim[0] & x <= lim[1]);
1110
- };
1111
-
1112
- /* context with Axes constants, properties and methods to share with children */
1113
- let context = {
1114
- // methods
1115
- addXAxisMargins,
1116
- addYAxisMargins,
1117
- adjustXAxisLimits,
1118
- adjustYAxisLimits,
1119
- getAxisTicks,
1120
- scaleX,
1121
- scaleY,
1122
- // variables
1123
- isOk,
1124
- scale,
1125
- width,
1126
- height,
1127
- xLim,
1128
- yLim,
1129
- // constants
1130
- LINE_STYLES,
1131
- LABELS_MARGIN,
1132
- TICK_NUM
1133
- };
1134
-
1135
- setContext('axes', context);
1136
-
1137
- // handle click on plot elements and dispatch manual events
1138
- function dispatchClickEvent(eventName, el) {
1139
- dispatch(eventName, {
1140
- seriesTitle: el.parentNode.getAttribute('title'),
1141
- elementID: el.dataset.id
1142
- });
1143
- }
1144
-
1145
- function handleClick(e) {
1146
- // scatter plot markers
1147
- if (e.target.tagName === "text" && e.target.parentNode.classList.contains("series_scatter")) {
1148
- dispatchClickEvent("markerclick", e.target);
1149
- return;
1150
- }
1151
-
1152
- // bar plot bars
1153
- if (e.target.tagName === "rect" && e.target.parentNode.classList.contains("series_bar")) {
1154
- dispatchClickEvent("barclick", e.target);
1155
- return;
1156
- }
1157
-
1158
- // outside any plot element
1159
- dispatch("axesclick");
1160
- }
1161
-
1162
- /* observer for the axes area size - to update size of axes */
1163
- const ro2 = new ResizeObserver(entries => {
1164
- for (let entry of entries) {
1165
- const acr = axesElement.getBoundingClientRect();
1166
- width.update(x => acr.width);
1167
- height.update(x => acr.height);
1168
- }
1169
- });
1170
-
1171
- /* observer for the plot area size — to update scale */
1172
- const ro1 = new ResizeObserver(entries => {
1173
- for (let entry of entries) {
1174
- const pcr = plotElement.getBoundingClientRect();
1175
- scale.update(x => getScale(pcr.width, pcr.height));
1176
- }
1177
- });
1178
-
1179
- onMount(() => {
1180
- ro1.observe(plotElement);
1181
- ro2.observe(axesElement);
1182
- });
1183
-
1184
- onDestroy(() => {
1185
- ro1.unobserve(plotElement);
1186
- ro2.unobserve(axesElement);
1187
- });
1188
-
1189
- function div0_binding($$value) {
1190
- binding_callbacks[$$value ? 'unshift' : 'push'](() => {
1191
- axesElement = $$value;
1192
- $$invalidate(6, axesElement);
1193
- });
1194
- }
1195
-
1196
- function div1_binding($$value) {
1197
- binding_callbacks[$$value ? 'unshift' : 'push'](() => {
1198
- plotElement = $$value;
1199
- $$invalidate(5, plotElement);
1200
- });
1201
- }
1202
-
1203
- $$self.$$set = $$props => {
1204
- if ('limX' in $$props) $$invalidate(17, limX = $$props.limX);
1205
- if ('limY' in $$props) $$invalidate(18, limY = $$props.limY);
1206
- if ('title' in $$props) $$invalidate(0, title = $$props.title);
1207
- if ('xLabel' in $$props) $$invalidate(1, xLabel = $$props.xLabel);
1208
- if ('yLabel' in $$props) $$invalidate(2, yLabel = $$props.yLabel);
1209
- if ('multiSeries' in $$props) $$invalidate(19, multiSeries = $$props.multiSeries);
1210
- if ('$$scope' in $$props) $$invalidate(26, $$scope = $$props.$$scope);
1211
- };
1212
-
1213
- $$self.$$.update = () => {
1214
- if ($$self.$$.dirty[0] & /*limX*/ 131072) {
1215
- // this is reactive in case if limX and limY are interactively changed by parent script
1216
- if (!limX.some(v => v === undefined)) xLim.update(v => limX);
1217
- }
1218
-
1219
- if ($$self.$$.dirty[0] & /*limY*/ 262144) {
1220
- if (!limY.some(v => v === undefined)) yLim.update(v => limY);
1221
- }
1222
-
1223
- if ($$self.$$.dirty[0] & /*axesMargins, $scale*/ 1048592) {
1224
- // computes real margins in pixels based on current scale
1225
- $$invalidate(21, margins = axesMargins.map(v => v * AXES_MARGIN_FACTORS[$scale]));
1226
- }
1227
-
1228
- if ($$self.$$.dirty[0] & /*$yLim, $xLim, $width, margins, $height*/ 65011712) {
1229
- // computes status which tells that axes limits look fine and it is safe to draw
1230
- // the status is based on the axis limits validity
1231
- isOk.update(v => Array.isArray($yLim) && Array.isArray($xLim) && $xLim.length === 2 && $yLim.length === 2 && !$yLim.some(v => v === undefined) && !$xLim.some(v => v === undefined) && !$yLim.some(v => isNaN(v)) && !$xLim.some(v => isNaN(v)) && $xLim[1] !== $xLim[0] && $yLim[1] !== $yLim[0] && $width > margins[1] + margins[3] && $height > margins[0] + margins[2]);
1232
- }
1233
-
1234
- if ($$self.$$.dirty[0] & /*$isOk, $xLim, $width*/ 50331656) {
1235
- // computes coordinates for clip path box
1236
- $$invalidate(8, cpx = $isOk ? scaleX($xLim, $xLim, $width) : [0, 1]);
1237
- }
1238
-
1239
- if ($$self.$$.dirty[0] & /*$isOk, $yLim, $height*/ 12582920) {
1240
- $$invalidate(7, cpy = $isOk ? scaleY($yLim, $yLim, $height) : [1, 0]);
1241
- }
1242
- };
1243
-
1244
- return [
1245
- title,
1246
- xLabel,
1247
- yLabel,
1248
- $isOk,
1249
- $scale,
1250
- plotElement,
1251
- axesElement,
1252
- cpy,
1253
- cpx,
1254
- clipPathID,
1255
- width,
1256
- height,
1257
- xLim,
1258
- yLim,
1259
- scale,
1260
- isOk,
1261
- handleClick,
1262
- limX,
1263
- limY,
1264
- multiSeries,
1265
- axesMargins,
1266
- margins,
1267
- $height,
1268
- $yLim,
1269
- $width,
1270
- $xLim,
1271
- $$scope,
1272
- slots,
1273
- div0_binding,
1274
- div1_binding
1275
- ];
1276
- }
1277
-
1278
- class Axes extends SvelteComponent {
1279
- constructor(options) {
1280
- super();
1281
-
1282
- init(
1283
- this,
1284
- options,
1285
- instance$b,
1286
- create_fragment$b,
1287
- safe_not_equal,
1288
- {
1289
- limX: 17,
1290
- limY: 18,
1291
- title: 0,
1292
- xLabel: 1,
1293
- yLabel: 2,
1294
- multiSeries: 19
1295
- },
1296
- add_css$3,
1297
- [-1, -1]
1298
- );
1299
- }
1300
- }
1301
-
1302
- const Colors = {
1303
- "AXIS_LINE": "#303030",
1304
- "AXIS_TICK": "#606060",
1305
- "WHITE": "#fff",
1306
- "BLACK": "#000",
1307
- "GRAY": "#909090",
1308
- "MIDDLEGRAY": "#dadada",
1309
- "LIGHTGRAY": "#f0f0f0",
1310
- "DARKGRAY": "#606060",
1311
-
1312
- "PRIMARY": "#2266ff",
1313
- "PRIMARY_TEXT": "#333",
1314
- };
1315
-
1316
- /* src/XAxis.svelte generated by Svelte v3.50.1 */
1317
-
1318
- function get_each_context$5(ctx, list, i) {
1319
- const child_ctx = ctx.slice();
1320
- child_ctx[26] = list[i];
1321
- child_ctx[28] = i;
1322
- return child_ctx;
1323
- }
1324
-
1325
- // (57:0) {#if $isOk && x !== undefined && y !== undefined }
1326
- function create_if_block$8(ctx) {
1327
- let g;
1328
- let line;
1329
- let line_x__value;
1330
- let line_x__value_1;
1331
- let line_y__value;
1332
- let line_y__value_1;
1333
- let each_value = /*ticksX*/ ctx[4];
1334
- let each_blocks = [];
1335
-
1336
- for (let i = 0; i < each_value.length; i += 1) {
1337
- each_blocks[i] = create_each_block$5(get_each_context$5(ctx, each_value, i));
1338
- }
1339
-
1340
- return {
1341
- c() {
1342
- g = svg_element("g");
1343
-
1344
- for (let i = 0; i < each_blocks.length; i += 1) {
1345
- each_blocks[i].c();
1346
- }
1347
-
1348
- line = svg_element("line");
1349
- attr(line, "x1", line_x__value = /*x*/ ctx[5][0]);
1350
- attr(line, "x2", line_x__value_1 = /*x*/ ctx[5][1]);
1351
- attr(line, "y1", line_y__value = /*y*/ ctx[2][0]);
1352
- attr(line, "y2", line_y__value_1 = /*y*/ ctx[2][0]);
1353
- attr(line, "style", /*axisLineStyleStr*/ ctx[7]);
1354
- attr(g, "class", "mdaplot__axis mdaplot__xaxis");
1355
- },
1356
- m(target, anchor) {
1357
- insert(target, g, anchor);
1358
-
1359
- for (let i = 0; i < each_blocks.length; i += 1) {
1360
- each_blocks[i].m(g, null);
1361
- }
1362
-
1363
- append(g, line);
1364
- },
1365
- p(ctx, dirty) {
1366
- if (dirty & /*ticksX, ticksY, dy, tickLabels, axisLineStyleStr, y, gridLineStyleStr*/ 415) {
1367
- each_value = /*ticksX*/ ctx[4];
1368
- let i;
1369
-
1370
- for (i = 0; i < each_value.length; i += 1) {
1371
- const child_ctx = get_each_context$5(ctx, each_value, i);
1372
-
1373
- if (each_blocks[i]) {
1374
- each_blocks[i].p(child_ctx, dirty);
1375
- } else {
1376
- each_blocks[i] = create_each_block$5(child_ctx);
1377
- each_blocks[i].c();
1378
- each_blocks[i].m(g, line);
1379
- }
1380
- }
1381
-
1382
- for (; i < each_blocks.length; i += 1) {
1383
- each_blocks[i].d(1);
1384
- }
1385
-
1386
- each_blocks.length = each_value.length;
1387
- }
1388
-
1389
- if (dirty & /*x*/ 32 && line_x__value !== (line_x__value = /*x*/ ctx[5][0])) {
1390
- attr(line, "x1", line_x__value);
1391
- }
1392
-
1393
- if (dirty & /*x*/ 32 && line_x__value_1 !== (line_x__value_1 = /*x*/ ctx[5][1])) {
1394
- attr(line, "x2", line_x__value_1);
1395
- }
1396
-
1397
- if (dirty & /*y*/ 4 && line_y__value !== (line_y__value = /*y*/ ctx[2][0])) {
1398
- attr(line, "y1", line_y__value);
1399
- }
1400
-
1401
- if (dirty & /*y*/ 4 && line_y__value_1 !== (line_y__value_1 = /*y*/ ctx[2][0])) {
1402
- attr(line, "y2", line_y__value_1);
1403
- }
1404
- },
1405
- d(detaching) {
1406
- if (detaching) detach(g);
1407
- destroy_each(each_blocks, detaching);
1408
- }
1409
- };
1410
- }
1411
-
1412
- // (59:3) {#each ticksX as tx, i}
1413
- function create_each_block$5(ctx) {
1414
- let line0;
1415
- let line0_x__value;
1416
- let line0_x__value_1;
1417
- let line0_y__value;
1418
- let line0_y__value_1;
1419
- let line1;
1420
- let line1_x__value;
1421
- let line1_x__value_1;
1422
- let line1_y__value;
1423
- let line1_y__value_1;
1424
- let text_1;
1425
- let t_value = /*tickLabels*/ ctx[0][/*i*/ ctx[28]] + "";
1426
- let t;
1427
- let text_1_x_value;
1428
- let text_1_y_value;
1429
-
1430
- return {
1431
- c() {
1432
- line0 = svg_element("line");
1433
- line1 = svg_element("line");
1434
- text_1 = svg_element("text");
1435
- t = text(t_value);
1436
- attr(line0, "x1", line0_x__value = /*tx*/ ctx[26]);
1437
- attr(line0, "x2", line0_x__value_1 = /*tx*/ ctx[26]);
1438
- attr(line0, "y1", line0_y__value = /*y*/ ctx[2][0]);
1439
- attr(line0, "y2", line0_y__value_1 = /*y*/ ctx[2][1]);
1440
- attr(line0, "style", /*gridLineStyleStr*/ ctx[8]);
1441
- attr(line1, "x1", line1_x__value = /*tx*/ ctx[26]);
1442
- attr(line1, "x2", line1_x__value_1 = /*tx*/ ctx[26]);
1443
- attr(line1, "y1", line1_y__value = /*ticksY*/ ctx[3][0]);
1444
- attr(line1, "y2", line1_y__value_1 = /*ticksY*/ ctx[3][1]);
1445
- attr(line1, "style", /*axisLineStyleStr*/ ctx[7]);
1446
- attr(text_1, "x", text_1_x_value = /*tx*/ ctx[26]);
1447
- attr(text_1, "y", text_1_y_value = /*ticksY*/ ctx[3][1]);
1448
- attr(text_1, "dx", "0");
1449
- attr(text_1, "dy", /*dy*/ ctx[1]);
1450
- attr(text_1, "class", "mdaplot__axis-labels");
1451
- attr(text_1, "dominant-baseline", "middle");
1452
- attr(text_1, "text-anchor", "middle");
1453
- },
1454
- m(target, anchor) {
1455
- insert(target, line0, anchor);
1456
- insert(target, line1, anchor);
1457
- insert(target, text_1, anchor);
1458
- append(text_1, t);
1459
- },
1460
- p(ctx, dirty) {
1461
- if (dirty & /*ticksX*/ 16 && line0_x__value !== (line0_x__value = /*tx*/ ctx[26])) {
1462
- attr(line0, "x1", line0_x__value);
1463
- }
1464
-
1465
- if (dirty & /*ticksX*/ 16 && line0_x__value_1 !== (line0_x__value_1 = /*tx*/ ctx[26])) {
1466
- attr(line0, "x2", line0_x__value_1);
1467
- }
1468
-
1469
- if (dirty & /*y*/ 4 && line0_y__value !== (line0_y__value = /*y*/ ctx[2][0])) {
1470
- attr(line0, "y1", line0_y__value);
1471
- }
1472
-
1473
- if (dirty & /*y*/ 4 && line0_y__value_1 !== (line0_y__value_1 = /*y*/ ctx[2][1])) {
1474
- attr(line0, "y2", line0_y__value_1);
1475
- }
1476
-
1477
- if (dirty & /*ticksX*/ 16 && line1_x__value !== (line1_x__value = /*tx*/ ctx[26])) {
1478
- attr(line1, "x1", line1_x__value);
1479
- }
1480
-
1481
- if (dirty & /*ticksX*/ 16 && line1_x__value_1 !== (line1_x__value_1 = /*tx*/ ctx[26])) {
1482
- attr(line1, "x2", line1_x__value_1);
1483
- }
1484
-
1485
- if (dirty & /*ticksY*/ 8 && line1_y__value !== (line1_y__value = /*ticksY*/ ctx[3][0])) {
1486
- attr(line1, "y1", line1_y__value);
1487
- }
1488
-
1489
- if (dirty & /*ticksY*/ 8 && line1_y__value_1 !== (line1_y__value_1 = /*ticksY*/ ctx[3][1])) {
1490
- attr(line1, "y2", line1_y__value_1);
1491
- }
1492
-
1493
- if (dirty & /*tickLabels*/ 1 && t_value !== (t_value = /*tickLabels*/ ctx[0][/*i*/ ctx[28]] + "")) set_data(t, t_value);
1494
-
1495
- if (dirty & /*ticksX*/ 16 && text_1_x_value !== (text_1_x_value = /*tx*/ ctx[26])) {
1496
- attr(text_1, "x", text_1_x_value);
1497
- }
1498
-
1499
- if (dirty & /*ticksY*/ 8 && text_1_y_value !== (text_1_y_value = /*ticksY*/ ctx[3][1])) {
1500
- attr(text_1, "y", text_1_y_value);
1501
- }
1502
-
1503
- if (dirty & /*dy*/ 2) {
1504
- attr(text_1, "dy", /*dy*/ ctx[1]);
1505
- }
1506
- },
1507
- d(detaching) {
1508
- if (detaching) detach(line0);
1509
- if (detaching) detach(line1);
1510
- if (detaching) detach(text_1);
1511
- }
1512
- };
1513
- }
1514
-
1515
- function create_fragment$a(ctx) {
1516
- let if_block_anchor;
1517
- let if_block = /*$isOk*/ ctx[6] && /*x*/ ctx[5] !== undefined && /*y*/ ctx[2] !== undefined && create_if_block$8(ctx);
1518
-
1519
- return {
1520
- c() {
1521
- if (if_block) if_block.c();
1522
- if_block_anchor = empty();
1523
- },
1524
- m(target, anchor) {
1525
- if (if_block) if_block.m(target, anchor);
1526
- insert(target, if_block_anchor, anchor);
1527
- },
1528
- p(ctx, [dirty]) {
1529
- if (/*$isOk*/ ctx[6] && /*x*/ ctx[5] !== undefined && /*y*/ ctx[2] !== undefined) {
1530
- if (if_block) {
1531
- if_block.p(ctx, dirty);
1532
- } else {
1533
- if_block = create_if_block$8(ctx);
1534
- if_block.c();
1535
- if_block.m(if_block_anchor.parentNode, if_block_anchor);
1536
- }
1537
- } else if (if_block) {
1538
- if_block.d(1);
1539
- if_block = null;
1540
- }
1541
- },
1542
- i: noop,
1543
- o: noop,
1544
- d(detaching) {
1545
- if (if_block) if_block.d(detaching);
1546
- if (detaching) detach(if_block_anchor);
1547
- }
1548
- };
1549
- }
1550
-
1551
- function instance$a($$self, $$props, $$invalidate) {
1552
- let x;
1553
- let y;
1554
- let dy;
1555
- let tickNum;
1556
- let ticksX;
1557
- let ticksY;
1558
- let $axesWidth;
1559
- let $xLim;
1560
- let $scale;
1561
- let $axesHeight;
1562
- let $yLim;
1563
- let $isOk;
1564
- let { slot = "xaxis" } = $$props;
1565
- let { ticks = undefined } = $$props;
1566
- let { tickLabels = ticks } = $$props;
1567
- let { showGrid = false } = $$props;
1568
-
1569
- // set up tick mode
1570
- const tickMode = ticks === undefined ? "auto" : "manual";
1571
-
1572
- /* sanity checks of input parameters */
1573
- if (slot !== "xaxis") {
1574
- throw "Component XAxis must have \"slot='xaxis'\" attribute.";
1575
- }
1576
-
1577
- if (ticks !== undefined && !Array.isArray(ticks)) {
1578
- throw "XAxis: 'ticks' must be a vector of numbers.";
1579
- }
1580
-
1581
- if (ticks !== undefined && !(Array.isArray(tickLabels) && tickLabels.length == ticks.length)) {
1582
- throw "XAxis: 'tickLabels' must be a vector of the same size as ticks.";
1583
- }
1584
-
1585
- /* styles for axis and grid lines */
1586
- const axisLineStyleStr = `stroke:${Colors.DARKGRAY};line-width:1px;`;
1587
-
1588
- const gridLineStyleStr = `stroke:${Colors.MIDDLEGRAY};stroke-opacity:${showGrid ? 1 : 0};stroke-dasharray:2px;`;
1589
-
1590
- // get axes context and adjust x margins
1591
- const axes = getContext('axes');
1592
-
1593
- axes.addXAxisMargins();
1594
-
1595
- // get reactive variables needed to compute coordinates
1596
- const xLim = axes.xLim;
1597
-
1598
- component_subscribe($$self, xLim, value => $$invalidate(20, $xLim = value));
1599
- const yLim = axes.yLim;
1600
- component_subscribe($$self, yLim, value => $$invalidate(23, $yLim = value));
1601
- const axesWidth = axes.width;
1602
- component_subscribe($$self, axesWidth, value => $$invalidate(19, $axesWidth = value));
1603
- const axesHeight = axes.height;
1604
- component_subscribe($$self, axesHeight, value => $$invalidate(22, $axesHeight = value));
1605
- const scale = axes.scale;
1606
- component_subscribe($$self, scale, value => $$invalidate(21, $scale = value));
1607
- const isOk = axes.isOk;
1608
- component_subscribe($$self, isOk, value => $$invalidate(6, $isOk = value));
1609
-
1610
- $$self.$$set = $$props => {
1611
- if ('slot' in $$props) $$invalidate(16, slot = $$props.slot);
1612
- if ('ticks' in $$props) $$invalidate(15, ticks = $$props.ticks);
1613
- if ('tickLabels' in $$props) $$invalidate(0, tickLabels = $$props.tickLabels);
1614
- if ('showGrid' in $$props) $$invalidate(17, showGrid = $$props.showGrid);
1615
- };
1616
-
1617
- $$self.$$.update = () => {
1618
- if ($$self.$$.dirty & /*$xLim, $axesWidth*/ 1572864) {
1619
- // reactive variables for coordinates of axis lines
1620
- $$invalidate(5, x = axes.scaleX($xLim, $xLim, $axesWidth));
1621
- }
1622
-
1623
- if ($$self.$$.dirty & /*$yLim, $axesHeight*/ 12582912) {
1624
- $$invalidate(2, y = axes.scaleY($yLim, $yLim, $axesHeight));
1625
- }
1626
-
1627
- if ($$self.$$.dirty & /*$scale*/ 2097152) {
1628
- // reactive variables for ticks and their coordinates
1629
- $$invalidate(1, dy = $scale === "small" ? 7 : 10);
1630
- }
1631
-
1632
- if ($$self.$$.dirty & /*$scale*/ 2097152) {
1633
- $$invalidate(18, tickNum = axes.TICK_NUM[$scale]);
1634
- }
1635
-
1636
- if ($$self.$$.dirty & /*$xLim, tickNum, ticks*/ 1343488) {
1637
- $$invalidate(15, ticks = tickMode === "auto"
1638
- ? axes.getAxisTicks(undefined, $xLim, tickNum, true)
1639
- : ticks);
1640
- }
1641
-
1642
- if ($$self.$$.dirty & /*ticks, tickLabels*/ 32769) {
1643
- $$invalidate(0, tickLabels = tickMode === "auto" ? ticks : tickLabels);
1644
- }
1645
-
1646
- if ($$self.$$.dirty & /*ticks, $xLim, $axesWidth*/ 1605632) {
1647
- $$invalidate(4, ticksX = axes.scaleX(ticks, $xLim, $axesWidth));
1648
- }
1649
-
1650
- if ($$self.$$.dirty & /*y, dy*/ 6) {
1651
- $$invalidate(3, ticksY = y === undefined ? undefined : [y[0], y[0] + dy]);
1652
- }
1653
- };
1654
-
1655
- return [
1656
- tickLabels,
1657
- dy,
1658
- y,
1659
- ticksY,
1660
- ticksX,
1661
- x,
1662
- $isOk,
1663
- axisLineStyleStr,
1664
- gridLineStyleStr,
1665
- xLim,
1666
- yLim,
1667
- axesWidth,
1668
- axesHeight,
1669
- scale,
1670
- isOk,
1671
- ticks,
1672
- slot,
1673
- showGrid,
1674
- tickNum,
1675
- $axesWidth,
1676
- $xLim,
1677
- $scale,
1678
- $axesHeight,
1679
- $yLim
1680
- ];
1681
- }
1682
-
1683
- class XAxis extends SvelteComponent {
1684
- constructor(options) {
1685
- super();
1686
-
1687
- init(this, options, instance$a, create_fragment$a, safe_not_equal, {
1688
- slot: 16,
1689
- ticks: 15,
1690
- tickLabels: 0,
1691
- showGrid: 17
1692
- });
1693
- }
1694
- }
1695
-
1696
- /* src/YAxis.svelte generated by Svelte v3.50.1 */
1697
-
1698
- function get_each_context$4(ctx, list, i) {
1699
- const child_ctx = ctx.slice();
1700
- child_ctx[26] = list[i];
1701
- child_ctx[28] = i;
1702
- return child_ctx;
1703
- }
1704
-
1705
- // (60:0) {#if x !== undefined && y !== undefined }
1706
- function create_if_block$7(ctx) {
1707
- let g;
1708
- let line;
1709
- let line_x__value;
1710
- let line_x__value_1;
1711
- let line_y__value;
1712
- let line_y__value_1;
1713
- let each_value = /*ticksY*/ ctx[4];
1714
- let each_blocks = [];
1715
-
1716
- for (let i = 0; i < each_value.length; i += 1) {
1717
- each_blocks[i] = create_each_block$4(get_each_context$4(ctx, each_value, i));
1718
- }
1719
-
1720
- return {
1721
- c() {
1722
- g = svg_element("g");
1723
-
1724
- for (let i = 0; i < each_blocks.length; i += 1) {
1725
- each_blocks[i].c();
1726
- }
1727
-
1728
- line = svg_element("line");
1729
- attr(line, "x1", line_x__value = /*x*/ ctx[1][0]);
1730
- attr(line, "x2", line_x__value_1 = /*x*/ ctx[1][0]);
1731
- attr(line, "y1", line_y__value = /*y*/ ctx[5][0]);
1732
- attr(line, "y2", line_y__value_1 = /*y*/ ctx[5][1]);
1733
- attr(line, "style", /*axisLineStyleStr*/ ctx[7]);
1734
- attr(g, "class", "mdaplot__axis mdaplot__yaxis");
1735
- },
1736
- m(target, anchor) {
1737
- insert(target, g, anchor);
1738
-
1739
- for (let i = 0; i < each_blocks.length; i += 1) {
1740
- each_blocks[i].m(g, null);
1741
- }
1742
-
1743
- append(g, line);
1744
- },
1745
- p(ctx, dirty) {
1746
- if (dirty & /*ticksX, ticksY, dx, transform, tickLabels, axisLineStyleStr, x, gridLineStyleStr*/ 479) {
1747
- each_value = /*ticksY*/ ctx[4];
1748
- let i;
1749
-
1750
- for (i = 0; i < each_value.length; i += 1) {
1751
- const child_ctx = get_each_context$4(ctx, each_value, i);
1752
-
1753
- if (each_blocks[i]) {
1754
- each_blocks[i].p(child_ctx, dirty);
1755
- } else {
1756
- each_blocks[i] = create_each_block$4(child_ctx);
1757
- each_blocks[i].c();
1758
- each_blocks[i].m(g, line);
1759
- }
1760
- }
1761
-
1762
- for (; i < each_blocks.length; i += 1) {
1763
- each_blocks[i].d(1);
1764
- }
1765
-
1766
- each_blocks.length = each_value.length;
1767
- }
1768
-
1769
- if (dirty & /*x*/ 2 && line_x__value !== (line_x__value = /*x*/ ctx[1][0])) {
1770
- attr(line, "x1", line_x__value);
1771
- }
1772
-
1773
- if (dirty & /*x*/ 2 && line_x__value_1 !== (line_x__value_1 = /*x*/ ctx[1][0])) {
1774
- attr(line, "x2", line_x__value_1);
1775
- }
1776
-
1777
- if (dirty & /*y*/ 32 && line_y__value !== (line_y__value = /*y*/ ctx[5][0])) {
1778
- attr(line, "y1", line_y__value);
1779
- }
1780
-
1781
- if (dirty & /*y*/ 32 && line_y__value_1 !== (line_y__value_1 = /*y*/ ctx[5][1])) {
1782
- attr(line, "y2", line_y__value_1);
1783
- }
1784
- },
1785
- d(detaching) {
1786
- if (detaching) detach(g);
1787
- destroy_each(each_blocks, detaching);
1788
- }
1789
- };
1790
- }
1791
-
1792
- // (62:3) {#each ticksY as ty, i}
1793
- function create_each_block$4(ctx) {
1794
- let line0;
1795
- let line0_x__value;
1796
- let line0_x__value_1;
1797
- let line0_y__value;
1798
- let line0_y__value_1;
1799
- let line1;
1800
- let line1_x__value;
1801
- let line1_x__value_1;
1802
- let line1_y__value;
1803
- let line1_y__value_1;
1804
- let text_1;
1805
- let t_value = /*tickLabels*/ ctx[0][/*i*/ ctx[28]] + "";
1806
- let t;
1807
- let text_1_x_value;
1808
- let text_1_y_value;
1809
-
1810
- return {
1811
- c() {
1812
- line0 = svg_element("line");
1813
- line1 = svg_element("line");
1814
- text_1 = svg_element("text");
1815
- t = text(t_value);
1816
- attr(line0, "x1", line0_x__value = /*x*/ ctx[1][0]);
1817
- attr(line0, "x2", line0_x__value_1 = /*x*/ ctx[1][1]);
1818
- attr(line0, "y1", line0_y__value = /*ty*/ ctx[26]);
1819
- attr(line0, "y2", line0_y__value_1 = /*ty*/ ctx[26]);
1820
- attr(line0, "style", /*gridLineStyleStr*/ ctx[8]);
1821
- attr(line1, "x1", line1_x__value = /*ticksX*/ ctx[3][0]);
1822
- attr(line1, "x2", line1_x__value_1 = /*ticksX*/ ctx[3][1]);
1823
- attr(line1, "y1", line1_y__value = /*ty*/ ctx[26]);
1824
- attr(line1, "y2", line1_y__value_1 = /*ty*/ ctx[26]);
1825
- attr(line1, "style", /*axisLineStyleStr*/ ctx[7]);
1826
- attr(text_1, "x", text_1_x_value = /*ticksX*/ ctx[3][0]);
1827
- attr(text_1, "y", text_1_y_value = /*ty*/ ctx[26]);
1828
- attr(text_1, "dx", /*dx*/ ctx[2]);
1829
- attr(text_1, "dy", 0);
1830
- attr(text_1, "transform", /*transform*/ ctx[6]);
1831
- set_style(text_1, "background", "red");
1832
- attr(text_1, "class", "mdaplot__axis-labels");
1833
- attr(text_1, "dominant-baseline", "middle");
1834
- attr(text_1, "text-anchor", "end");
1835
- },
1836
- m(target, anchor) {
1837
- insert(target, line0, anchor);
1838
- insert(target, line1, anchor);
1839
- insert(target, text_1, anchor);
1840
- append(text_1, t);
1841
- },
1842
- p(ctx, dirty) {
1843
- if (dirty & /*x*/ 2 && line0_x__value !== (line0_x__value = /*x*/ ctx[1][0])) {
1844
- attr(line0, "x1", line0_x__value);
1845
- }
1846
-
1847
- if (dirty & /*x*/ 2 && line0_x__value_1 !== (line0_x__value_1 = /*x*/ ctx[1][1])) {
1848
- attr(line0, "x2", line0_x__value_1);
1849
- }
1850
-
1851
- if (dirty & /*ticksY*/ 16 && line0_y__value !== (line0_y__value = /*ty*/ ctx[26])) {
1852
- attr(line0, "y1", line0_y__value);
1853
- }
1854
-
1855
- if (dirty & /*ticksY*/ 16 && line0_y__value_1 !== (line0_y__value_1 = /*ty*/ ctx[26])) {
1856
- attr(line0, "y2", line0_y__value_1);
1857
- }
1858
-
1859
- if (dirty & /*ticksX*/ 8 && line1_x__value !== (line1_x__value = /*ticksX*/ ctx[3][0])) {
1860
- attr(line1, "x1", line1_x__value);
1861
- }
1862
-
1863
- if (dirty & /*ticksX*/ 8 && line1_x__value_1 !== (line1_x__value_1 = /*ticksX*/ ctx[3][1])) {
1864
- attr(line1, "x2", line1_x__value_1);
1865
- }
1866
-
1867
- if (dirty & /*ticksY*/ 16 && line1_y__value !== (line1_y__value = /*ty*/ ctx[26])) {
1868
- attr(line1, "y1", line1_y__value);
1869
- }
1870
-
1871
- if (dirty & /*ticksY*/ 16 && line1_y__value_1 !== (line1_y__value_1 = /*ty*/ ctx[26])) {
1872
- attr(line1, "y2", line1_y__value_1);
1873
- }
1874
-
1875
- if (dirty & /*tickLabels*/ 1 && t_value !== (t_value = /*tickLabels*/ ctx[0][/*i*/ ctx[28]] + "")) set_data(t, t_value);
1876
-
1877
- if (dirty & /*ticksX*/ 8 && text_1_x_value !== (text_1_x_value = /*ticksX*/ ctx[3][0])) {
1878
- attr(text_1, "x", text_1_x_value);
1879
- }
1880
-
1881
- if (dirty & /*ticksY*/ 16 && text_1_y_value !== (text_1_y_value = /*ty*/ ctx[26])) {
1882
- attr(text_1, "y", text_1_y_value);
1883
- }
1884
-
1885
- if (dirty & /*dx*/ 4) {
1886
- attr(text_1, "dx", /*dx*/ ctx[2]);
1887
- }
1888
- },
1889
- d(detaching) {
1890
- if (detaching) detach(line0);
1891
- if (detaching) detach(line1);
1892
- if (detaching) detach(text_1);
1893
- }
1894
- };
1895
- }
1896
-
1897
- function create_fragment$9(ctx) {
1898
- let if_block_anchor;
1899
- let if_block = /*x*/ ctx[1] !== undefined && /*y*/ ctx[5] !== undefined && create_if_block$7(ctx);
1900
-
1901
- return {
1902
- c() {
1903
- if (if_block) if_block.c();
1904
- if_block_anchor = empty();
1905
- },
1906
- m(target, anchor) {
1907
- if (if_block) if_block.m(target, anchor);
1908
- insert(target, if_block_anchor, anchor);
1909
- },
1910
- p(ctx, [dirty]) {
1911
- if (/*x*/ ctx[1] !== undefined && /*y*/ ctx[5] !== undefined) {
1912
- if (if_block) {
1913
- if_block.p(ctx, dirty);
1914
- } else {
1915
- if_block = create_if_block$7(ctx);
1916
- if_block.c();
1917
- if_block.m(if_block_anchor.parentNode, if_block_anchor);
1918
- }
1919
- } else if (if_block) {
1920
- if_block.d(1);
1921
- if_block = null;
1922
- }
1923
- },
1924
- i: noop,
1925
- o: noop,
1926
- d(detaching) {
1927
- if (if_block) if_block.d(detaching);
1928
- if (detaching) detach(if_block_anchor);
1929
- }
1930
- };
1931
- }
1932
-
1933
- function instance$9($$self, $$props, $$invalidate) {
1934
- let x;
1935
- let y;
1936
- let dx;
1937
- let tickNum;
1938
- let ticksY;
1939
- let ticksX;
1940
- let $axesHeight;
1941
- let $yLim;
1942
- let $scale;
1943
- let $axesWidth;
1944
- let $xLim;
1945
- let { slot = "yaxis" } = $$props;
1946
- let { ticks = undefined } = $$props;
1947
- let { tickLabels = ticks } = $$props;
1948
- let { showGrid = false } = $$props;
1949
- let { las = 1 } = $$props;
1950
-
1951
- // set up tick mode
1952
- const tickMode = ticks === undefined ? "auto" : "manual";
1953
-
1954
- // TODO: set up tick text translation
1955
- const transform = las > 1 ? "" : "";
1956
-
1957
- /* sanity checks of input parameters */
1958
- if (slot !== "yaxis") {
1959
- throw "Component YAxis must have \"slot='yaxis'\" attribute.";
1960
- }
1961
-
1962
- if (ticks !== undefined && !Array.isArray(ticks)) {
1963
- throw "YAxis: 'ticks' must be a vector of numbers.";
1964
- }
1965
-
1966
- if (ticks !== undefined && !(Array.isArray(tickLabels) && tickLabels.length == ticks.length)) {
1967
- throw "YAxis: 'tickLabels' must be a vector of the same size as ticks.";
1968
- }
1969
-
1970
- /* styles for axis and grid lines */
1971
- const axisLineStyleStr = `stroke:${Colors.DARKGRAY};line-width:1px;`;
1972
-
1973
- const gridLineStyleStr = `stroke:${Colors.MIDDLEGRAY};stroke-opacity:${showGrid ? 1 : 0};stroke-dasharray:2px;`;
1974
-
1975
- // get axes context and adjust x margins
1976
- const axes = getContext('axes');
1977
-
1978
- axes.addYAxisMargins();
1979
-
1980
- // get reactive variables needed to compute coordinates
1981
- const xLim = axes.xLim;
1982
-
1983
- component_subscribe($$self, xLim, value => $$invalidate(23, $xLim = value));
1984
- const yLim = axes.yLim;
1985
- component_subscribe($$self, yLim, value => $$invalidate(20, $yLim = value));
1986
- const axesWidth = axes.width;
1987
- component_subscribe($$self, axesWidth, value => $$invalidate(22, $axesWidth = value));
1988
- const axesHeight = axes.height;
1989
- component_subscribe($$self, axesHeight, value => $$invalidate(19, $axesHeight = value));
1990
- const scale = axes.scale;
1991
- component_subscribe($$self, scale, value => $$invalidate(21, $scale = value));
1992
-
1993
- $$self.$$set = $$props => {
1994
- if ('slot' in $$props) $$invalidate(15, slot = $$props.slot);
1995
- if ('ticks' in $$props) $$invalidate(14, ticks = $$props.ticks);
1996
- if ('tickLabels' in $$props) $$invalidate(0, tickLabels = $$props.tickLabels);
1997
- if ('showGrid' in $$props) $$invalidate(16, showGrid = $$props.showGrid);
1998
- if ('las' in $$props) $$invalidate(17, las = $$props.las);
1999
- };
2000
-
2001
- $$self.$$.update = () => {
2002
- if ($$self.$$.dirty & /*$xLim, $axesWidth*/ 12582912) {
2003
- // reactive variables for coordinates of axis lines
2004
- $$invalidate(1, x = axes.scaleX($xLim, $xLim, $axesWidth));
2005
- }
2006
-
2007
- if ($$self.$$.dirty & /*$yLim, $axesHeight*/ 1572864) {
2008
- $$invalidate(5, y = axes.scaleY($yLim, $yLim, $axesHeight));
2009
- }
2010
-
2011
- if ($$self.$$.dirty & /*$scale*/ 2097152) {
2012
- // reactive variables for ticks and their coordinates
2013
- $$invalidate(2, dx = $scale === "small" ? -4 : -6);
2014
- }
2015
-
2016
- if ($$self.$$.dirty & /*$scale*/ 2097152) {
2017
- $$invalidate(18, tickNum = axes.TICK_NUM[$scale]);
2018
- }
2019
-
2020
- if ($$self.$$.dirty & /*$yLim, tickNum, ticks*/ 1327104) {
2021
- $$invalidate(14, ticks = tickMode === "auto"
2022
- ? axes.getAxisTicks(undefined, $yLim, tickNum, true)
2023
- : ticks);
2024
- }
2025
-
2026
- if ($$self.$$.dirty & /*ticks, tickLabels*/ 16385) {
2027
- $$invalidate(0, tickLabels = tickMode === "auto" ? ticks : tickLabels);
2028
- }
2029
-
2030
- if ($$self.$$.dirty & /*ticks, $yLim, $axesHeight*/ 1589248) {
2031
- $$invalidate(4, ticksY = axes.scaleY(ticks, $yLim, $axesHeight));
2032
- }
2033
-
2034
- if ($$self.$$.dirty & /*x, dx*/ 6) {
2035
- $$invalidate(3, ticksX = x === undefined ? undefined : [x[0] + dx, x[0]]);
2036
- }
2037
- };
2038
-
2039
- return [
2040
- tickLabels,
2041
- x,
2042
- dx,
2043
- ticksX,
2044
- ticksY,
2045
- y,
2046
- transform,
2047
- axisLineStyleStr,
2048
- gridLineStyleStr,
2049
- xLim,
2050
- yLim,
2051
- axesWidth,
2052
- axesHeight,
2053
- scale,
2054
- ticks,
2055
- slot,
2056
- showGrid,
2057
- las,
2058
- tickNum,
2059
- $axesHeight,
2060
- $yLim,
2061
- $scale,
2062
- $axesWidth,
2063
- $xLim
2064
- ];
2065
- }
2066
-
2067
- class YAxis extends SvelteComponent {
2068
- constructor(options) {
2069
- super();
2070
-
2071
- init(this, options, instance$9, create_fragment$9, safe_not_equal, {
2072
- slot: 15,
2073
- ticks: 14,
2074
- tickLabels: 0,
2075
- showGrid: 16,
2076
- las: 17
2077
- });
2078
- }
2079
- }
2080
-
2081
- /* src/Rectangles.svelte generated by Svelte v3.50.1 */
2082
-
2083
- function get_each_context$3(ctx, list, i) {
2084
- const child_ctx = ctx.slice();
2085
- child_ctx[25] = list[i];
2086
- child_ctx[27] = i;
2087
- return child_ctx;
2088
- }
2089
-
2090
- // (55:0) {#if rx !== undefined && ry !== undefined}
2091
- function create_if_block$6(ctx) {
2092
- let g;
2093
- let g_class_value;
2094
- let each_value = /*left*/ ctx[0];
2095
- let each_blocks = [];
2096
-
2097
- for (let i = 0; i < each_value.length; i += 1) {
2098
- each_blocks[i] = create_each_block$3(get_each_context$3(ctx, each_value, i));
2099
- }
2100
-
2101
- return {
2102
- c() {
2103
- g = svg_element("g");
2104
-
2105
- for (let i = 0; i < each_blocks.length; i += 1) {
2106
- each_blocks[i].c();
2107
- }
2108
-
2109
- attr(g, "class", g_class_value = "series " + /*style*/ ctx[2]);
2110
- attr(g, "title", /*title*/ ctx[1]);
2111
- attr(g, "style", /*barsStyleStr*/ ctx[3]);
2112
- },
2113
- m(target, anchor) {
2114
- insert(target, g, anchor);
2115
-
2116
- for (let i = 0; i < each_blocks.length; i += 1) {
2117
- each_blocks[i].m(g, null);
2118
- }
2119
- },
2120
- p(ctx, dirty) {
2121
- if (dirty & /*rx, ry, rw, rh, left*/ 241) {
2122
- each_value = /*left*/ ctx[0];
2123
- let i;
2124
-
2125
- for (i = 0; i < each_value.length; i += 1) {
2126
- const child_ctx = get_each_context$3(ctx, each_value, i);
2127
-
2128
- if (each_blocks[i]) {
2129
- each_blocks[i].p(child_ctx, dirty);
2130
- } else {
2131
- each_blocks[i] = create_each_block$3(child_ctx);
2132
- each_blocks[i].c();
2133
- each_blocks[i].m(g, null);
2134
- }
2135
- }
2136
-
2137
- for (; i < each_blocks.length; i += 1) {
2138
- each_blocks[i].d(1);
2139
- }
2140
-
2141
- each_blocks.length = each_value.length;
2142
- }
2143
-
2144
- if (dirty & /*style*/ 4 && g_class_value !== (g_class_value = "series " + /*style*/ ctx[2])) {
2145
- attr(g, "class", g_class_value);
2146
- }
2147
-
2148
- if (dirty & /*title*/ 2) {
2149
- attr(g, "title", /*title*/ ctx[1]);
2150
- }
2151
-
2152
- if (dirty & /*barsStyleStr*/ 8) {
2153
- attr(g, "style", /*barsStyleStr*/ ctx[3]);
2154
- }
2155
- },
2156
- d(detaching) {
2157
- if (detaching) detach(g);
2158
- destroy_each(each_blocks, detaching);
2159
- }
2160
- };
2161
- }
2162
-
2163
- // (57:3) {#each left as v, i}
2164
- function create_each_block$3(ctx) {
2165
- let rect;
2166
- let rect_x_value;
2167
- let rect_y_value;
2168
- let rect_width_value;
2169
- let rect_height_value;
2170
-
2171
- return {
2172
- c() {
2173
- rect = svg_element("rect");
2174
- attr(rect, "x", rect_x_value = /*rx*/ ctx[7][/*i*/ ctx[27]]);
2175
- attr(rect, "y", rect_y_value = /*ry*/ ctx[6][/*i*/ ctx[27]]);
2176
- attr(rect, "width", rect_width_value = /*rw*/ ctx[5][/*i*/ ctx[27]]);
2177
- attr(rect, "height", rect_height_value = /*rh*/ ctx[4][/*i*/ ctx[27]]);
2178
- },
2179
- m(target, anchor) {
2180
- insert(target, rect, anchor);
2181
- },
2182
- p(ctx, dirty) {
2183
- if (dirty & /*rx*/ 128 && rect_x_value !== (rect_x_value = /*rx*/ ctx[7][/*i*/ ctx[27]])) {
2184
- attr(rect, "x", rect_x_value);
2185
- }
2186
-
2187
- if (dirty & /*ry*/ 64 && rect_y_value !== (rect_y_value = /*ry*/ ctx[6][/*i*/ ctx[27]])) {
2188
- attr(rect, "y", rect_y_value);
2189
- }
2190
-
2191
- if (dirty & /*rw*/ 32 && rect_width_value !== (rect_width_value = /*rw*/ ctx[5][/*i*/ ctx[27]])) {
2192
- attr(rect, "width", rect_width_value);
2193
- }
2194
-
2195
- if (dirty & /*rh*/ 16 && rect_height_value !== (rect_height_value = /*rh*/ ctx[4][/*i*/ ctx[27]])) {
2196
- attr(rect, "height", rect_height_value);
2197
- }
2198
- },
2199
- d(detaching) {
2200
- if (detaching) detach(rect);
2201
- }
2202
- };
2203
- }
2204
-
2205
- function create_fragment$8(ctx) {
2206
- let if_block_anchor;
2207
- let if_block = /*rx*/ ctx[7] !== undefined && /*ry*/ ctx[6] !== undefined && create_if_block$6(ctx);
2208
-
2209
- return {
2210
- c() {
2211
- if (if_block) if_block.c();
2212
- if_block_anchor = empty();
2213
- },
2214
- m(target, anchor) {
2215
- if (if_block) if_block.m(target, anchor);
2216
- insert(target, if_block_anchor, anchor);
2217
- },
2218
- p(ctx, [dirty]) {
2219
- if (/*rx*/ ctx[7] !== undefined && /*ry*/ ctx[6] !== undefined) {
2220
- if (if_block) {
2221
- if_block.p(ctx, dirty);
2222
- } else {
2223
- if_block = create_if_block$6(ctx);
2224
- if_block.c();
2225
- if_block.m(if_block_anchor.parentNode, if_block_anchor);
2226
- }
2227
- } else if (if_block) {
2228
- if_block.d(1);
2229
- if_block = null;
2230
- }
2231
- },
2232
- i: noop,
2233
- o: noop,
2234
- d(detaching) {
2235
- if (if_block) if_block.d(detaching);
2236
- if (detaching) detach(if_block_anchor);
2237
- }
2238
- };
2239
- }
2240
-
2241
- function instance$8($$self, $$props, $$invalidate) {
2242
- let rx;
2243
- let ry;
2244
- let rw;
2245
- let rh;
2246
- let barsStyleStr;
2247
- let $axesHeight;
2248
- let $yLim;
2249
- let $axesWidth;
2250
- let $xLim;
2251
- let { left } = $$props;
2252
- let { top } = $$props;
2253
- let { width } = $$props;
2254
- let { height } = $$props;
2255
- let { labels = undefined } = $$props;
2256
- let { faceColor = Colors.PRIMARY } = $$props;
2257
- let { borderColor = faceColor } = $$props;
2258
- let { lineWidth = 1 } = $$props;
2259
- let { title = "" } = $$props;
2260
- let { style = "series_rect" } = $$props;
2261
-
2262
- // multiply width and height values if needed
2263
- if (!Array.isArray(left) || !Array.isArray(top) || left.length < 1 || left.length != top.length) {
2264
- throw "Rectangles: parameters 'left' and 'top' must be vectors of the same size.";
2265
- }
2266
-
2267
- // we make this reactive in case if left and right has been changed but not width
2268
- const n = left.length;
2269
-
2270
- if (!Array.isArray(height)) height = Array(n).fill(height);
2271
- if (!Array.isArray(width)) width = Array(n).fill(width);
2272
-
2273
- /* sanity check for input parameters */
2274
- if (top.length !== n || width.length !== n || height.length !== n) {
2275
- throw "Rectangles: x, y, w and h should have the same length (w and h can be single values).";
2276
- }
2277
-
2278
- if (labels !== undefined && (!Array.isArray(labels) || labels.length !== n)) {
2279
- throw "Rectangles: vector with labels should have the same length as vectors with x and y coordinates.";
2280
- }
2281
-
2282
- // get axes context and reactive variables needed to compute coordinates
2283
- const axes = getContext('axes');
2284
-
2285
- const xLim = axes.xLim;
2286
- component_subscribe($$self, xLim, value => $$invalidate(22, $xLim = value));
2287
- const yLim = axes.yLim;
2288
- component_subscribe($$self, yLim, value => $$invalidate(20, $yLim = value));
2289
- const axesWidth = axes.width;
2290
- component_subscribe($$self, axesWidth, value => $$invalidate(21, $axesWidth = value));
2291
- const axesHeight = axes.height;
2292
- component_subscribe($$self, axesHeight, value => $$invalidate(19, $axesHeight = value));
2293
-
2294
- $$self.$$set = $$props => {
2295
- if ('left' in $$props) $$invalidate(0, left = $$props.left);
2296
- if ('top' in $$props) $$invalidate(14, top = $$props.top);
2297
- if ('width' in $$props) $$invalidate(12, width = $$props.width);
2298
- if ('height' in $$props) $$invalidate(13, height = $$props.height);
2299
- if ('labels' in $$props) $$invalidate(15, labels = $$props.labels);
2300
- if ('faceColor' in $$props) $$invalidate(16, faceColor = $$props.faceColor);
2301
- if ('borderColor' in $$props) $$invalidate(17, borderColor = $$props.borderColor);
2302
- if ('lineWidth' in $$props) $$invalidate(18, lineWidth = $$props.lineWidth);
2303
- if ('title' in $$props) $$invalidate(1, title = $$props.title);
2304
- if ('style' in $$props) $$invalidate(2, style = $$props.style);
2305
- };
2306
-
2307
- $$self.$$.update = () => {
2308
- if ($$self.$$.dirty & /*left, $xLim, $axesWidth*/ 6291457) {
2309
- // reactive variables for coordinates of data points in pixels
2310
- $$invalidate(7, rx = axes.scaleX(left, $xLim, $axesWidth));
2311
- }
2312
-
2313
- if ($$self.$$.dirty & /*top, $yLim, $axesHeight*/ 1589248) {
2314
- $$invalidate(6, ry = axes.scaleY(top, $yLim, $axesHeight));
2315
- }
2316
-
2317
- if ($$self.$$.dirty & /*width, $xLim, $axesWidth*/ 6295552) {
2318
- $$invalidate(5, rw = axes.scaleX(width, $xLim, $axesWidth, true));
2319
- }
2320
-
2321
- if ($$self.$$.dirty & /*height, $yLim, $axesHeight*/ 1581056) {
2322
- $$invalidate(4, rh = axes.scaleY(height, $yLim, $axesHeight, true));
2323
- }
2324
-
2325
- if ($$self.$$.dirty & /*faceColor, borderColor, lineWidth*/ 458752) {
2326
- // styles for bars and labels
2327
- $$invalidate(3, barsStyleStr = `fill:${faceColor};stroke:${borderColor};stroke-width: ${lineWidth}px;`);
2328
- }
2329
- };
2330
-
2331
- return [
2332
- left,
2333
- title,
2334
- style,
2335
- barsStyleStr,
2336
- rh,
2337
- rw,
2338
- ry,
2339
- rx,
2340
- xLim,
2341
- yLim,
2342
- axesWidth,
2343
- axesHeight,
2344
- width,
2345
- height,
2346
- top,
2347
- labels,
2348
- faceColor,
2349
- borderColor,
2350
- lineWidth,
2351
- $axesHeight,
2352
- $yLim,
2353
- $axesWidth,
2354
- $xLim
2355
- ];
2356
- }
2357
-
2358
- class Rectangles extends SvelteComponent {
2359
- constructor(options) {
2360
- super();
2361
-
2362
- init(this, options, instance$8, create_fragment$8, safe_not_equal, {
2363
- left: 0,
2364
- top: 14,
2365
- width: 12,
2366
- height: 13,
2367
- labels: 15,
2368
- faceColor: 16,
2369
- borderColor: 17,
2370
- lineWidth: 18,
2371
- title: 1,
2372
- style: 2
2373
- });
2374
- }
2375
- }
2376
-
2377
- /* src/Box.svelte generated by Svelte v3.50.1 */
2378
-
2379
- function create_if_block$5(ctx) {
2380
- let g;
2381
- let rectangles;
2382
- let current;
2383
-
2384
- rectangles = new Rectangles({
2385
- props: {
2386
- left: /*left*/ ctx[3],
2387
- top: /*top*/ ctx[2],
2388
- width: /*width*/ ctx[1],
2389
- height: /*height*/ ctx[0],
2390
- borderColor: Colors.DARKGRAY,
2391
- faceColor: "transparent"
2392
- }
2393
- });
2394
-
2395
- return {
2396
- c() {
2397
- g = svg_element("g");
2398
- create_component(rectangles.$$.fragment);
2399
- set_style(g, "pointer-events", "none");
2400
- attr(g, "class", "mdaplot__axes-box");
2401
- },
2402
- m(target, anchor) {
2403
- insert(target, g, anchor);
2404
- mount_component(rectangles, g, null);
2405
- current = true;
2406
- },
2407
- p(ctx, dirty) {
2408
- const rectangles_changes = {};
2409
- if (dirty & /*left*/ 8) rectangles_changes.left = /*left*/ ctx[3];
2410
- if (dirty & /*top*/ 4) rectangles_changes.top = /*top*/ ctx[2];
2411
- if (dirty & /*width*/ 2) rectangles_changes.width = /*width*/ ctx[1];
2412
- if (dirty & /*height*/ 1) rectangles_changes.height = /*height*/ ctx[0];
2413
- rectangles.$set(rectangles_changes);
2414
- },
2415
- i(local) {
2416
- if (current) return;
2417
- transition_in(rectangles.$$.fragment, local);
2418
- current = true;
2419
- },
2420
- o(local) {
2421
- transition_out(rectangles.$$.fragment, local);
2422
- current = false;
2423
- },
2424
- d(detaching) {
2425
- if (detaching) detach(g);
2426
- destroy_component(rectangles);
2427
- }
2428
- };
2429
- }
2430
-
2431
- function create_fragment$7(ctx) {
2432
- let if_block_anchor;
2433
- let current;
2434
- let if_block = /*$isOk*/ ctx[4] && create_if_block$5(ctx);
2435
-
2436
- return {
2437
- c() {
2438
- if (if_block) if_block.c();
2439
- if_block_anchor = empty();
2440
- },
2441
- m(target, anchor) {
2442
- if (if_block) if_block.m(target, anchor);
2443
- insert(target, if_block_anchor, anchor);
2444
- current = true;
2445
- },
2446
- p(ctx, [dirty]) {
2447
- if (/*$isOk*/ ctx[4]) {
2448
- if (if_block) {
2449
- if_block.p(ctx, dirty);
2450
-
2451
- if (dirty & /*$isOk*/ 16) {
2452
- transition_in(if_block, 1);
2453
- }
2454
- } else {
2455
- if_block = create_if_block$5(ctx);
2456
- if_block.c();
2457
- transition_in(if_block, 1);
2458
- if_block.m(if_block_anchor.parentNode, if_block_anchor);
2459
- }
2460
- } else if (if_block) {
2461
- group_outros();
2462
-
2463
- transition_out(if_block, 1, 1, () => {
2464
- if_block = null;
2465
- });
2466
-
2467
- check_outros();
2468
- }
2469
- },
2470
- i(local) {
2471
- if (current) return;
2472
- transition_in(if_block);
2473
- current = true;
2474
- },
2475
- o(local) {
2476
- transition_out(if_block);
2477
- current = false;
2478
- },
2479
- d(detaching) {
2480
- if (if_block) if_block.d(detaching);
2481
- if (detaching) detach(if_block_anchor);
2482
- }
2483
- };
2484
- }
2485
-
2486
- function instance$7($$self, $$props, $$invalidate) {
2487
- let left;
2488
- let top;
2489
- let width;
2490
- let height;
2491
- let $yLim;
2492
- let $xLim;
2493
- let $isOk;
2494
- let { slot } = $$props;
2495
-
2496
- // check that the box is located in a correct slot
2497
- if (slot !== "box") {
2498
- throw "Component Box must have \"slot='box'\" attribute.";
2499
- }
2500
-
2501
- // get axes context and reactive variables needed to compute coordinates
2502
- const axes = getContext('axes');
2503
-
2504
- const xLim = axes.xLim;
2505
- component_subscribe($$self, xLim, value => $$invalidate(10, $xLim = value));
2506
- const yLim = axes.yLim;
2507
- component_subscribe($$self, yLim, value => $$invalidate(9, $yLim = value));
2508
- const isOk = axes.isOk;
2509
- component_subscribe($$self, isOk, value => $$invalidate(4, $isOk = value));
2510
-
2511
- $$self.$$set = $$props => {
2512
- if ('slot' in $$props) $$invalidate(8, slot = $$props.slot);
2513
- };
2514
-
2515
- $$self.$$.update = () => {
2516
- if ($$self.$$.dirty & /*$xLim*/ 1024) {
2517
- // reactive variables for coordinates of box points in pixels
2518
- $$invalidate(3, left = [$xLim[0]]);
2519
- }
2520
-
2521
- if ($$self.$$.dirty & /*$yLim*/ 512) {
2522
- $$invalidate(2, top = [$yLim[1]]);
2523
- }
2524
-
2525
- if ($$self.$$.dirty & /*$xLim*/ 1024) {
2526
- $$invalidate(1, width = [$xLim[1] - $xLim[0]]);
2527
- }
2528
-
2529
- if ($$self.$$.dirty & /*$yLim*/ 512) {
2530
- $$invalidate(0, height = [$yLim[1] - $yLim[0]]);
2531
- }
2532
- };
2533
-
2534
- return [height, width, top, left, $isOk, xLim, yLim, isOk, slot, $yLim, $xLim];
2535
- }
2536
-
2537
- class Box extends SvelteComponent {
2538
- constructor(options) {
2539
- super();
2540
- init(this, options, instance$7, create_fragment$7, safe_not_equal, { slot: 8 });
2541
- }
2542
- }
2543
-
2544
- /* src/Segments.svelte generated by Svelte v3.50.1 */
2545
-
2546
- function get_each_context$2(ctx, list, i) {
2547
- const child_ctx = ctx.slice();
2548
- child_ctx[24] = list[i];
2549
- child_ctx[26] = i;
2550
- return child_ctx;
2551
- }
2552
-
2553
- // (41:0) {#if x1 !== undefined && y1 !== undefined}
2554
- function create_if_block$4(ctx) {
2555
- let each_1_anchor;
2556
- let each_value = /*x1*/ ctx[4];
2557
- let each_blocks = [];
2558
-
2559
- for (let i = 0; i < each_value.length; i += 1) {
2560
- each_blocks[i] = create_each_block$2(get_each_context$2(ctx, each_value, i));
2561
- }
2562
-
2563
- return {
2564
- c() {
2565
- for (let i = 0; i < each_blocks.length; i += 1) {
2566
- each_blocks[i].c();
2567
- }
2568
-
2569
- each_1_anchor = empty();
2570
- },
2571
- m(target, anchor) {
2572
- for (let i = 0; i < each_blocks.length; i += 1) {
2573
- each_blocks[i].m(target, anchor);
2574
- }
2575
-
2576
- insert(target, each_1_anchor, anchor);
2577
- },
2578
- p(ctx, dirty) {
2579
- if (dirty & /*x1, x2, y1, y2, lineStyleStr*/ 31) {
2580
- each_value = /*x1*/ ctx[4];
2581
- let i;
2582
-
2583
- for (i = 0; i < each_value.length; i += 1) {
2584
- const child_ctx = get_each_context$2(ctx, each_value, i);
2585
-
2586
- if (each_blocks[i]) {
2587
- each_blocks[i].p(child_ctx, dirty);
2588
- } else {
2589
- each_blocks[i] = create_each_block$2(child_ctx);
2590
- each_blocks[i].c();
2591
- each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor);
2592
- }
2593
- }
2594
-
2595
- for (; i < each_blocks.length; i += 1) {
2596
- each_blocks[i].d(1);
2597
- }
2598
-
2599
- each_blocks.length = each_value.length;
2600
- }
2601
- },
2602
- d(detaching) {
2603
- destroy_each(each_blocks, detaching);
2604
- if (detaching) detach(each_1_anchor);
2605
- }
2606
- };
2607
- }
2608
-
2609
- // (42:3) {#each x1 as v, i}
2610
- function create_each_block$2(ctx) {
2611
- let line;
2612
- let line_x__value;
2613
- let line_x__value_1;
2614
- let line_y__value;
2615
- let line_y__value_1;
2616
-
2617
- return {
2618
- c() {
2619
- line = svg_element("line");
2620
- attr(line, "x1", line_x__value = /*x1*/ ctx[4][/*i*/ ctx[26]]);
2621
- attr(line, "x2", line_x__value_1 = /*x2*/ ctx[3][/*i*/ ctx[26]]);
2622
- attr(line, "y1", line_y__value = /*y1*/ ctx[2][/*i*/ ctx[26]]);
2623
- attr(line, "y2", line_y__value_1 = /*y2*/ ctx[1][/*i*/ ctx[26]]);
2624
- attr(line, "style", /*lineStyleStr*/ ctx[0]);
2625
- },
2626
- m(target, anchor) {
2627
- insert(target, line, anchor);
2628
- },
2629
- p(ctx, dirty) {
2630
- if (dirty & /*x1*/ 16 && line_x__value !== (line_x__value = /*x1*/ ctx[4][/*i*/ ctx[26]])) {
2631
- attr(line, "x1", line_x__value);
2632
- }
2633
-
2634
- if (dirty & /*x2*/ 8 && line_x__value_1 !== (line_x__value_1 = /*x2*/ ctx[3][/*i*/ ctx[26]])) {
2635
- attr(line, "x2", line_x__value_1);
2636
- }
2637
-
2638
- if (dirty & /*y1*/ 4 && line_y__value !== (line_y__value = /*y1*/ ctx[2][/*i*/ ctx[26]])) {
2639
- attr(line, "y1", line_y__value);
2640
- }
2641
-
2642
- if (dirty & /*y2*/ 2 && line_y__value_1 !== (line_y__value_1 = /*y2*/ ctx[1][/*i*/ ctx[26]])) {
2643
- attr(line, "y2", line_y__value_1);
2644
- }
2645
-
2646
- if (dirty & /*lineStyleStr*/ 1) {
2647
- attr(line, "style", /*lineStyleStr*/ ctx[0]);
2648
- }
2649
- },
2650
- d(detaching) {
2651
- if (detaching) detach(line);
2652
- }
2653
- };
2654
- }
2655
-
2656
- function create_fragment$6(ctx) {
2657
- let if_block_anchor;
2658
- let if_block = /*x1*/ ctx[4] !== undefined && /*y1*/ ctx[2] !== undefined && create_if_block$4(ctx);
2659
-
2660
- return {
2661
- c() {
2662
- if (if_block) if_block.c();
2663
- if_block_anchor = empty();
2664
- },
2665
- m(target, anchor) {
2666
- if (if_block) if_block.m(target, anchor);
2667
- insert(target, if_block_anchor, anchor);
2668
- },
2669
- p(ctx, [dirty]) {
2670
- if (/*x1*/ ctx[4] !== undefined && /*y1*/ ctx[2] !== undefined) {
2671
- if (if_block) {
2672
- if_block.p(ctx, dirty);
2673
- } else {
2674
- if_block = create_if_block$4(ctx);
2675
- if_block.c();
2676
- if_block.m(if_block_anchor.parentNode, if_block_anchor);
2677
- }
2678
- } else if (if_block) {
2679
- if_block.d(1);
2680
- if_block = null;
2681
- }
2682
- },
2683
- i: noop,
2684
- o: noop,
2685
- d(detaching) {
2686
- if (if_block) if_block.d(detaching);
2687
- if (detaching) detach(if_block_anchor);
2688
- }
2689
- };
2690
- }
2691
-
2692
- function instance$6($$self, $$props, $$invalidate) {
2693
- let x1;
2694
- let x2;
2695
- let y1;
2696
- let y2;
2697
- let lineStyleStr;
2698
- let $scale;
2699
- let $axesHeight;
2700
- let $yLim;
2701
- let $axesWidth;
2702
- let $xLim;
2703
- let { xStart } = $$props;
2704
- let { xEnd } = $$props;
2705
- let { yStart } = $$props;
2706
- let { yEnd } = $$props;
2707
- let { lineColor = Colors.PRIMARY } = $$props;
2708
- let { lineType = 1 } = $$props;
2709
- let { lineWidth = 1 } = $$props;
2710
-
2711
- /* sanity check for input parameters */
2712
- if (!Array.isArray(xStart) || !Array.isArray(xEnd) || !Array.isArray(yStart) || !Array.isArray(yEnd)) {
2713
- throw "Segments: parameters 'xStart', 'yStart', 'xEnd' and 'yEnd' must be vectors.";
2714
- }
2715
-
2716
- const n = xStart.length;
2717
-
2718
- if (xEnd.length !== n || yStart.length !== n || yEnd.length !== n) {
2719
- throw "Segments: parameters 'xStart', 'yStart', 'xEnd' and 'yEnd' should have the same length.";
2720
- }
2721
-
2722
- // get axes context and reactive variables needed to compute coordinates
2723
- const axes = getContext('axes');
2724
-
2725
- const xLim = axes.xLim;
2726
- component_subscribe($$self, xLim, value => $$invalidate(21, $xLim = value));
2727
- const yLim = axes.yLim;
2728
- component_subscribe($$self, yLim, value => $$invalidate(19, $yLim = value));
2729
- const axesWidth = axes.width;
2730
- component_subscribe($$self, axesWidth, value => $$invalidate(20, $axesWidth = value));
2731
- const axesHeight = axes.height;
2732
- component_subscribe($$self, axesHeight, value => $$invalidate(18, $axesHeight = value));
2733
- const scale = axes.scale;
2734
- component_subscribe($$self, scale, value => $$invalidate(17, $scale = value));
2735
-
2736
- $$self.$$set = $$props => {
2737
- if ('xStart' in $$props) $$invalidate(10, xStart = $$props.xStart);
2738
- if ('xEnd' in $$props) $$invalidate(11, xEnd = $$props.xEnd);
2739
- if ('yStart' in $$props) $$invalidate(12, yStart = $$props.yStart);
2740
- if ('yEnd' in $$props) $$invalidate(13, yEnd = $$props.yEnd);
2741
- if ('lineColor' in $$props) $$invalidate(14, lineColor = $$props.lineColor);
2742
- if ('lineType' in $$props) $$invalidate(15, lineType = $$props.lineType);
2743
- if ('lineWidth' in $$props) $$invalidate(16, lineWidth = $$props.lineWidth);
2744
- };
2745
-
2746
- $$self.$$.update = () => {
2747
- if ($$self.$$.dirty & /*xStart, $xLim, $axesWidth*/ 3146752) {
2748
- // reactive variables for coordinates of data points in pixels (and line style)
2749
- $$invalidate(4, x1 = axes.scaleX(xStart, $xLim, $axesWidth));
2750
- }
2751
-
2752
- if ($$self.$$.dirty & /*xEnd, $xLim, $axesWidth*/ 3147776) {
2753
- $$invalidate(3, x2 = axes.scaleX(xEnd, $xLim, $axesWidth));
2754
- }
2755
-
2756
- if ($$self.$$.dirty & /*yStart, $yLim, $axesHeight*/ 790528) {
2757
- $$invalidate(2, y1 = axes.scaleY(yStart, $yLim, $axesHeight));
2758
- }
2759
-
2760
- if ($$self.$$.dirty & /*yEnd, $yLim, $axesHeight*/ 794624) {
2761
- $$invalidate(1, y2 = axes.scaleY(yEnd, $yLim, $axesHeight));
2762
- }
2763
-
2764
- if ($$self.$$.dirty & /*lineColor, lineWidth, $scale, lineType*/ 245760) {
2765
- $$invalidate(0, lineStyleStr = `stroke:${lineColor};stroke-width: ${lineWidth}px;stroke-dasharray:${axes.LINE_STYLES[$scale][lineType - 1]}`);
2766
- }
2767
- };
2768
-
2769
- return [
2770
- lineStyleStr,
2771
- y2,
2772
- y1,
2773
- x2,
2774
- x1,
2775
- xLim,
2776
- yLim,
2777
- axesWidth,
2778
- axesHeight,
2779
- scale,
2780
- xStart,
2781
- xEnd,
2782
- yStart,
2783
- yEnd,
2784
- lineColor,
2785
- lineType,
2786
- lineWidth,
2787
- $scale,
2788
- $axesHeight,
2789
- $yLim,
2790
- $axesWidth,
2791
- $xLim
2792
- ];
2793
- }
2794
-
2795
- class Segments extends SvelteComponent {
2796
- constructor(options) {
2797
- super();
2798
-
2799
- init(this, options, instance$6, create_fragment$6, safe_not_equal, {
2800
- xStart: 10,
2801
- xEnd: 11,
2802
- yStart: 12,
2803
- yEnd: 13,
2804
- lineColor: 14,
2805
- lineType: 15,
2806
- lineWidth: 16
2807
- });
2808
- }
2809
- }
2810
-
2811
- /* src/TextLabels.svelte generated by Svelte v3.50.1 */
2812
-
2813
- function add_css$2(target) {
2814
- append_styles(target, "svelte-1xvrp9d", "text.svelte-1xvrp9d,text.svelte-1xvrp9d>tspan{dominant-baseline:middle}");
2815
- }
2816
-
2817
- function get_each_context$1(ctx, list, i) {
2818
- const child_ctx = ctx.slice();
2819
- child_ctx[27] = list[i];
2820
- child_ctx[29] = i;
2821
- return child_ctx;
2822
- }
2823
-
2824
- // (66:0) {#if x !== undefined && y !== undefined}
2825
- function create_if_block$3(ctx) {
2826
- let g;
2827
- let g_class_value;
2828
- let each_value = /*x*/ ctx[7];
2829
- let each_blocks = [];
2830
-
2831
- for (let i = 0; i < each_value.length; i += 1) {
2832
- each_blocks[i] = create_each_block$1(get_each_context$1(ctx, each_value, i));
2833
- }
2834
-
2835
- return {
2836
- c() {
2837
- g = svg_element("g");
2838
-
2839
- for (let i = 0; i < each_blocks.length; i += 1) {
2840
- each_blocks[i].c();
2841
- }
2842
-
2843
- attr(g, "class", g_class_value = "series " + /*style*/ ctx[1]);
2844
- attr(g, "title", /*title*/ ctx[2]);
2845
- attr(g, "style", /*textStyleStr*/ ctx[3]);
2846
- },
2847
- m(target, anchor) {
2848
- insert(target, g, anchor);
2849
-
2850
- for (let i = 0; i < each_blocks.length; i += 1) {
2851
- each_blocks[i].m(g, null);
2852
- }
2853
- },
2854
- p(ctx, dirty) {
2855
- if (dirty & /*x, y, dx, dy, labels*/ 241) {
2856
- each_value = /*x*/ ctx[7];
2857
- let i;
2858
-
2859
- for (i = 0; i < each_value.length; i += 1) {
2860
- const child_ctx = get_each_context$1(ctx, each_value, i);
2861
-
2862
- if (each_blocks[i]) {
2863
- each_blocks[i].p(child_ctx, dirty);
2864
- } else {
2865
- each_blocks[i] = create_each_block$1(child_ctx);
2866
- each_blocks[i].c();
2867
- each_blocks[i].m(g, null);
2868
- }
2869
- }
2870
-
2871
- for (; i < each_blocks.length; i += 1) {
2872
- each_blocks[i].d(1);
2873
- }
2874
-
2875
- each_blocks.length = each_value.length;
2876
- }
2877
-
2878
- if (dirty & /*style*/ 2 && g_class_value !== (g_class_value = "series " + /*style*/ ctx[1])) {
2879
- attr(g, "class", g_class_value);
2880
- }
2881
-
2882
- if (dirty & /*title*/ 4) {
2883
- attr(g, "title", /*title*/ ctx[2]);
2884
- }
2885
-
2886
- if (dirty & /*textStyleStr*/ 8) {
2887
- attr(g, "style", /*textStyleStr*/ ctx[3]);
2888
- }
2889
- },
2890
- d(detaching) {
2891
- if (detaching) detach(g);
2892
- destroy_each(each_blocks, detaching);
2893
- }
2894
- };
2895
- }
2896
-
2897
- // (68:3) {#each x as v, i}
2898
- function create_each_block$1(ctx) {
2899
- let text_1;
2900
- let raw_value = /*labels*/ ctx[0][/*i*/ ctx[29]] + "";
2901
- let text_1_x_value;
2902
- let text_1_y_value;
2903
-
2904
- return {
2905
- c() {
2906
- text_1 = svg_element("text");
2907
- attr(text_1, "data-id", /*i*/ ctx[29]);
2908
- attr(text_1, "x", text_1_x_value = /*x*/ ctx[7][/*i*/ ctx[29]]);
2909
- attr(text_1, "y", text_1_y_value = /*y*/ ctx[6][/*i*/ ctx[29]]);
2910
- attr(text_1, "dx", /*dx*/ ctx[5]);
2911
- attr(text_1, "dy", /*dy*/ ctx[4]);
2912
- attr(text_1, "class", "svelte-1xvrp9d");
2913
- },
2914
- m(target, anchor) {
2915
- insert(target, text_1, anchor);
2916
- text_1.innerHTML = raw_value;
2917
- },
2918
- p(ctx, dirty) {
2919
- if (dirty & /*labels*/ 1 && raw_value !== (raw_value = /*labels*/ ctx[0][/*i*/ ctx[29]] + "")) text_1.innerHTML = raw_value;
2920
- if (dirty & /*x*/ 128 && text_1_x_value !== (text_1_x_value = /*x*/ ctx[7][/*i*/ ctx[29]])) {
2921
- attr(text_1, "x", text_1_x_value);
2922
- }
2923
-
2924
- if (dirty & /*y*/ 64 && text_1_y_value !== (text_1_y_value = /*y*/ ctx[6][/*i*/ ctx[29]])) {
2925
- attr(text_1, "y", text_1_y_value);
2926
- }
2927
-
2928
- if (dirty & /*dx*/ 32) {
2929
- attr(text_1, "dx", /*dx*/ ctx[5]);
2930
- }
2931
-
2932
- if (dirty & /*dy*/ 16) {
2933
- attr(text_1, "dy", /*dy*/ ctx[4]);
2934
- }
2935
- },
2936
- d(detaching) {
2937
- if (detaching) detach(text_1);
2938
- }
2939
- };
2940
- }
2941
-
2942
- function create_fragment$5(ctx) {
2943
- let if_block_anchor;
2944
- let if_block = /*x*/ ctx[7] !== undefined && /*y*/ ctx[6] !== undefined && create_if_block$3(ctx);
2945
-
2946
- return {
2947
- c() {
2948
- if (if_block) if_block.c();
2949
- if_block_anchor = empty();
2950
- },
2951
- m(target, anchor) {
2952
- if (if_block) if_block.m(target, anchor);
2953
- insert(target, if_block_anchor, anchor);
2954
- },
2955
- p(ctx, [dirty]) {
2956
- if (/*x*/ ctx[7] !== undefined && /*y*/ ctx[6] !== undefined) {
2957
- if (if_block) {
2958
- if_block.p(ctx, dirty);
2959
- } else {
2960
- if_block = create_if_block$3(ctx);
2961
- if_block.c();
2962
- if_block.m(if_block_anchor.parentNode, if_block_anchor);
2963
- }
2964
- } else if (if_block) {
2965
- if_block.d(1);
2966
- if_block = null;
2967
- }
2968
- },
2969
- i: noop,
2970
- o: noop,
2971
- d(detaching) {
2972
- if (if_block) if_block.d(detaching);
2973
- if (detaching) detach(if_block_anchor);
2974
- }
2975
- };
2976
- }
2977
-
2978
- function instance$5($$self, $$props, $$invalidate) {
2979
- let x;
2980
- let y;
2981
- let dx;
2982
- let dy;
2983
- let textStyleStr;
2984
- let $scale;
2985
- let $axesHeight;
2986
- let $yLim;
2987
- let $axesWidth;
2988
- let $xLim;
2989
- let { xValues } = $$props;
2990
- let { yValues } = $$props;
2991
- let { labels } = $$props;
2992
- let { pos = 0 } = $$props;
2993
- let { faceColor = Colors.PRIMARY_TEXT } = $$props;
2994
- let { borderColor = "transparent" } = $$props;
2995
- let { borderWidth = 0 } = $$props;
2996
- let { textSize = 1 } = $$props;
2997
- let { style = "" } = $$props;
2998
- let { title = "series_text" } = $$props;
2999
-
3000
- // text-anchor values depending on position
3001
- const textAnchors = ["middle", "middle", "start", "middle", "end"];
3002
-
3003
- // sanity check for input parameters
3004
- if (!Array.isArray(xValues) || !Array.isArray(yValues) || xValues.length !== yValues.length) {
3005
- throw "TextLabels: parameters 'xValues' and 'yValues' must be vectors of the same length.";
3006
- }
3007
-
3008
- // get axes context and reactive variables needed to compute coordinates
3009
- const axes = getContext('axes');
3010
-
3011
- const xLim = axes.xLim;
3012
- component_subscribe($$self, xLim, value => $$invalidate(24, $xLim = value));
3013
- const yLim = axes.yLim;
3014
- component_subscribe($$self, yLim, value => $$invalidate(22, $yLim = value));
3015
- const axesWidth = axes.width;
3016
- component_subscribe($$self, axesWidth, value => $$invalidate(23, $axesWidth = value));
3017
- const axesHeight = axes.height;
3018
- component_subscribe($$self, axesHeight, value => $$invalidate(21, $axesHeight = value));
3019
- const scale = axes.scale;
3020
- component_subscribe($$self, scale, value => $$invalidate(20, $scale = value));
3021
-
3022
- $$self.$$set = $$props => {
3023
- if ('xValues' in $$props) $$invalidate(13, xValues = $$props.xValues);
3024
- if ('yValues' in $$props) $$invalidate(14, yValues = $$props.yValues);
3025
- if ('labels' in $$props) $$invalidate(0, labels = $$props.labels);
3026
- if ('pos' in $$props) $$invalidate(15, pos = $$props.pos);
3027
- if ('faceColor' in $$props) $$invalidate(16, faceColor = $$props.faceColor);
3028
- if ('borderColor' in $$props) $$invalidate(17, borderColor = $$props.borderColor);
3029
- if ('borderWidth' in $$props) $$invalidate(18, borderWidth = $$props.borderWidth);
3030
- if ('textSize' in $$props) $$invalidate(19, textSize = $$props.textSize);
3031
- if ('style' in $$props) $$invalidate(1, style = $$props.style);
3032
- if ('title' in $$props) $$invalidate(2, title = $$props.title);
3033
- };
3034
-
3035
- $$self.$$.update = () => {
3036
- if ($$self.$$.dirty & /*xValues, labels*/ 8193) {
3037
- // multiply label values if needed
3038
- {
3039
- const n = xValues.length;
3040
- if (!Array.isArray(labels)) $$invalidate(0, labels = Array(n).fill(labels));
3041
-
3042
- // workaround for an issue when xValues and yValues are changed in parent app
3043
- // but array of labels is still the same as in the
3044
- if (labels.length != n) $$invalidate(0, labels = Array(n).fill(labels[0]));
3045
-
3046
- // check that the length of labels vector is correct
3047
- if (labels.length !== n) {
3048
- throw "TextLabels: parameter 'labels' must be a single text value or a vector of the same size as 'x' and 'y'.";
3049
- }
3050
- }
3051
- }
3052
-
3053
- if ($$self.$$.dirty & /*xValues, $xLim, $axesWidth*/ 25174016) {
3054
- // reactive variables for coordinates of data points in pixels
3055
- $$invalidate(7, x = axes.scaleX(xValues, $xLim, $axesWidth));
3056
- }
3057
-
3058
- if ($$self.$$.dirty & /*yValues, $yLim, $axesHeight*/ 6307840) {
3059
- $$invalidate(6, y = axes.scaleY(yValues, $yLim, $axesHeight));
3060
- }
3061
-
3062
- if ($$self.$$.dirty & /*pos, $scale*/ 1081344) {
3063
- $$invalidate(5, dx = [0, 0, 1, 0, -1][pos] * axes.LABELS_MARGIN[$scale]);
3064
- }
3065
-
3066
- if ($$self.$$.dirty & /*pos, $scale*/ 1081344) {
3067
- $$invalidate(4, dy = [0, 1, 0, -1, 0][pos] * axes.LABELS_MARGIN[$scale]);
3068
- }
3069
-
3070
- if ($$self.$$.dirty & /*faceColor, borderWidth, borderColor, textSize, pos*/ 1015808) {
3071
- // styles for the elements
3072
- $$invalidate(3, textStyleStr = `fill:${faceColor};stroke-width:${borderWidth}px;stroke:${borderColor};
3073
- font-size:${textSize}em; text-anchor:${textAnchors[pos]};`);
3074
- }
3075
- };
3076
-
3077
- return [
3078
- labels,
3079
- style,
3080
- title,
3081
- textStyleStr,
3082
- dy,
3083
- dx,
3084
- y,
3085
- x,
3086
- xLim,
3087
- yLim,
3088
- axesWidth,
3089
- axesHeight,
3090
- scale,
3091
- xValues,
3092
- yValues,
3093
- pos,
3094
- faceColor,
3095
- borderColor,
3096
- borderWidth,
3097
- textSize,
3098
- $scale,
3099
- $axesHeight,
3100
- $yLim,
3101
- $axesWidth,
3102
- $xLim
3103
- ];
3104
- }
3105
-
3106
- class TextLabels extends SvelteComponent {
3107
- constructor(options) {
3108
- super();
3109
-
3110
- init(
3111
- this,
3112
- options,
3113
- instance$5,
3114
- create_fragment$5,
3115
- safe_not_equal,
3116
- {
3117
- xValues: 13,
3118
- yValues: 14,
3119
- labels: 0,
3120
- pos: 15,
3121
- faceColor: 16,
3122
- borderColor: 17,
3123
- borderWidth: 18,
3124
- textSize: 19,
3125
- style: 1,
3126
- title: 2
3127
- },
3128
- add_css$2
3129
- );
3130
- }
3131
- }
3132
-
3133
- /* src/TextLegend.svelte generated by Svelte v3.50.1 */
3134
-
3135
- function get_each_context(ctx, list, i) {
3136
- const child_ctx = ctx.slice();
3137
- child_ctx[22] = list[i];
3138
- child_ctx[24] = i;
3139
- return child_ctx;
3140
- }
3141
-
3142
- // (32:0) {#if x !== undefined && y !== undefined && elements.length > 0}
3143
- function create_if_block$2(ctx) {
3144
- let text_1;
3145
- let each_value = /*elements*/ ctx[2];
3146
- let each_blocks = [];
3147
-
3148
- for (let i = 0; i < each_value.length; i += 1) {
3149
- each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
3150
- }
3151
-
3152
- return {
3153
- c() {
3154
- text_1 = svg_element("text");
3155
-
3156
- for (let i = 0; i < each_blocks.length; i += 1) {
3157
- each_blocks[i].c();
3158
- }
3159
-
3160
- attr(text_1, "style", /*textStyleStr*/ ctx[3]);
3161
- attr(text_1, "x", /*x*/ ctx[5]);
3162
- attr(text_1, "y", /*y*/ ctx[4]);
3163
- attr(text_1, "dx", /*dx*/ ctx[0]);
3164
- attr(text_1, "dy", /*dy*/ ctx[1]);
3165
- attr(text_1, "dominant-baseline", "middle");
3166
- attr(text_1, "text-anchor", "start");
3167
- },
3168
- m(target, anchor) {
3169
- insert(target, text_1, anchor);
3170
-
3171
- for (let i = 0; i < each_blocks.length; i += 1) {
3172
- each_blocks[i].m(text_1, null);
3173
- }
3174
- },
3175
- p(ctx, dirty) {
3176
- if (dirty & /*x, dx, dy, elements*/ 39) {
3177
- each_value = /*elements*/ ctx[2];
3178
- let i;
3179
-
3180
- for (i = 0; i < each_value.length; i += 1) {
3181
- const child_ctx = get_each_context(ctx, each_value, i);
3182
-
3183
- if (each_blocks[i]) {
3184
- each_blocks[i].p(child_ctx, dirty);
3185
- } else {
3186
- each_blocks[i] = create_each_block(child_ctx);
3187
- each_blocks[i].c();
3188
- each_blocks[i].m(text_1, null);
3189
- }
3190
- }
3191
-
3192
- for (; i < each_blocks.length; i += 1) {
3193
- each_blocks[i].d(1);
3194
- }
3195
-
3196
- each_blocks.length = each_value.length;
3197
- }
3198
-
3199
- if (dirty & /*textStyleStr*/ 8) {
3200
- attr(text_1, "style", /*textStyleStr*/ ctx[3]);
3201
- }
3202
-
3203
- if (dirty & /*x*/ 32) {
3204
- attr(text_1, "x", /*x*/ ctx[5]);
3205
- }
3206
-
3207
- if (dirty & /*y*/ 16) {
3208
- attr(text_1, "y", /*y*/ ctx[4]);
3209
- }
3210
-
3211
- if (dirty & /*dx*/ 1) {
3212
- attr(text_1, "dx", /*dx*/ ctx[0]);
3213
- }
3214
-
3215
- if (dirty & /*dy*/ 2) {
3216
- attr(text_1, "dy", /*dy*/ ctx[1]);
3217
- }
3218
- },
3219
- d(detaching) {
3220
- if (detaching) detach(text_1);
3221
- destroy_each(each_blocks, detaching);
3222
- }
3223
- };
3224
- }
3225
-
3226
- // (34:6) {#each elements as el, i}
3227
- function create_each_block(ctx) {
3228
- let tspan;
3229
- let raw_value = /*el*/ ctx[22] + "";
3230
- let tspan_dy_value;
3231
-
3232
- return {
3233
- c() {
3234
- tspan = svg_element("tspan");
3235
- attr(tspan, "x", /*x*/ ctx[5]);
3236
- attr(tspan, "dx", /*dx*/ ctx[0]);
3237
- attr(tspan, "dy", tspan_dy_value = /*i*/ ctx[24] === 0 ? 0 : /*dy*/ ctx[1]);
3238
- },
3239
- m(target, anchor) {
3240
- insert(target, tspan, anchor);
3241
- tspan.innerHTML = raw_value;
3242
- },
3243
- p(ctx, dirty) {
3244
- if (dirty & /*elements*/ 4 && raw_value !== (raw_value = /*el*/ ctx[22] + "")) tspan.innerHTML = raw_value;
3245
- if (dirty & /*x*/ 32) {
3246
- attr(tspan, "x", /*x*/ ctx[5]);
3247
- }
3248
-
3249
- if (dirty & /*dx*/ 1) {
3250
- attr(tspan, "dx", /*dx*/ ctx[0]);
3251
- }
3252
-
3253
- if (dirty & /*dy*/ 2 && tspan_dy_value !== (tspan_dy_value = /*i*/ ctx[24] === 0 ? 0 : /*dy*/ ctx[1])) {
3254
- attr(tspan, "dy", tspan_dy_value);
3255
- }
3256
- },
3257
- d(detaching) {
3258
- if (detaching) detach(tspan);
3259
- }
3260
- };
3261
- }
3262
-
3263
- function create_fragment$4(ctx) {
3264
- let if_block_anchor;
3265
- let if_block = /*x*/ ctx[5] !== undefined && /*y*/ ctx[4] !== undefined && /*elements*/ ctx[2].length > 0 && create_if_block$2(ctx);
3266
-
3267
- return {
3268
- c() {
3269
- if (if_block) if_block.c();
3270
- if_block_anchor = empty();
3271
- },
3272
- m(target, anchor) {
3273
- if (if_block) if_block.m(target, anchor);
3274
- insert(target, if_block_anchor, anchor);
3275
- },
3276
- p(ctx, [dirty]) {
3277
- if (/*x*/ ctx[5] !== undefined && /*y*/ ctx[4] !== undefined && /*elements*/ ctx[2].length > 0) {
3278
- if (if_block) {
3279
- if_block.p(ctx, dirty);
3280
- } else {
3281
- if_block = create_if_block$2(ctx);
3282
- if_block.c();
3283
- if_block.m(if_block_anchor.parentNode, if_block_anchor);
3284
- }
3285
- } else if (if_block) {
3286
- if_block.d(1);
3287
- if_block = null;
3288
- }
3289
- },
3290
- i: noop,
3291
- o: noop,
3292
- d(detaching) {
3293
- if (if_block) if_block.d(detaching);
3294
- if (detaching) detach(if_block_anchor);
3295
- }
3296
- };
3297
- }
3298
-
3299
- function instance$4($$self, $$props, $$invalidate) {
3300
- let x;
3301
- let y;
3302
- let textStyleStr;
3303
- let $axesHeight;
3304
- let $yLim;
3305
- let $axesWidth;
3306
- let $xLim;
3307
- let { left } = $$props;
3308
- let { top } = $$props;
3309
- let { dx = "0" } = $$props;
3310
- let { dy = "1.25em" } = $$props;
3311
- let { elements } = $$props;
3312
- let { faceColor = Colors.PRIMARY_TEXT } = $$props;
3313
- let { borderColor = "transparent" } = $$props;
3314
- let { borderWidth = 0 } = $$props;
3315
- let { textSize = 1 } = $$props;
3316
-
3317
- // get axes context and reactive variables needed to compute coordinates
3318
- const axes = getContext('axes');
3319
-
3320
- const xLim = axes.xLim;
3321
- component_subscribe($$self, xLim, value => $$invalidate(19, $xLim = value));
3322
- const yLim = axes.yLim;
3323
- component_subscribe($$self, yLim, value => $$invalidate(17, $yLim = value));
3324
- const axesWidth = axes.width;
3325
- component_subscribe($$self, axesWidth, value => $$invalidate(18, $axesWidth = value));
3326
- const axesHeight = axes.height;
3327
- component_subscribe($$self, axesHeight, value => $$invalidate(16, $axesHeight = value));
3328
- axes.scale;
3329
-
3330
- $$self.$$set = $$props => {
3331
- if ('left' in $$props) $$invalidate(10, left = $$props.left);
3332
- if ('top' in $$props) $$invalidate(11, top = $$props.top);
3333
- if ('dx' in $$props) $$invalidate(0, dx = $$props.dx);
3334
- if ('dy' in $$props) $$invalidate(1, dy = $$props.dy);
3335
- if ('elements' in $$props) $$invalidate(2, elements = $$props.elements);
3336
- if ('faceColor' in $$props) $$invalidate(12, faceColor = $$props.faceColor);
3337
- if ('borderColor' in $$props) $$invalidate(13, borderColor = $$props.borderColor);
3338
- if ('borderWidth' in $$props) $$invalidate(14, borderWidth = $$props.borderWidth);
3339
- if ('textSize' in $$props) $$invalidate(15, textSize = $$props.textSize);
3340
- };
3341
-
3342
- $$self.$$.update = () => {
3343
- if ($$self.$$.dirty & /*left, $xLim, $axesWidth*/ 787456) {
3344
- // reactive variables for coordinates of data points in pixels
3345
- $$invalidate(5, x = axes.scaleX([left], $xLim, $axesWidth));
3346
- }
3347
-
3348
- if ($$self.$$.dirty & /*top, $yLim, $axesHeight*/ 198656) {
3349
- $$invalidate(4, y = axes.scaleY([top], $yLim, $axesHeight));
3350
- }
3351
-
3352
- if ($$self.$$.dirty & /*faceColor, borderWidth, borderColor, textSize*/ 61440) {
3353
- // styles for bars and labels
3354
- $$invalidate(3, textStyleStr = `fill:${faceColor};stroke-width:${borderWidth}px;stroke:${borderColor};font-size:${textSize}em;`);
3355
- }
3356
- };
3357
-
3358
- return [
3359
- dx,
3360
- dy,
3361
- elements,
3362
- textStyleStr,
3363
- y,
3364
- x,
3365
- xLim,
3366
- yLim,
3367
- axesWidth,
3368
- axesHeight,
3369
- left,
3370
- top,
3371
- faceColor,
3372
- borderColor,
3373
- borderWidth,
3374
- textSize,
3375
- $axesHeight,
3376
- $yLim,
3377
- $axesWidth,
3378
- $xLim
3379
- ];
3380
- }
3381
-
3382
- class TextLegend extends SvelteComponent {
3383
- constructor(options) {
3384
- super();
3385
-
3386
- init(this, options, instance$4, create_fragment$4, safe_not_equal, {
3387
- left: 10,
3388
- top: 11,
3389
- dx: 0,
3390
- dy: 1,
3391
- elements: 2,
3392
- faceColor: 12,
3393
- borderColor: 13,
3394
- borderWidth: 14,
3395
- textSize: 15
3396
- });
3397
- }
3398
- }
3399
-
3400
- /**********************************************
3401
- * Functions for statistical tests and models *
3402
- **********************************************/
3403
-
3404
-
3405
- /**
3406
- * Finds smallest value in a vector
3407
- * @param {number[]} x - vector with values
3408
- * @returns {number}
3409
- */
3410
- function min(x) {
3411
- let n = x.length;
3412
- let min = Number.POSITIVE_INFINITY;
3413
-
3414
- while (n--) min = x[n] < min ? x[n] : min;
3415
- return min;
3416
- }
3417
-
3418
-
3419
- /**
3420
- * Finds largest value in a vector
3421
- * @param {number[]} x - vector with values
3422
- * @returns {number}
3423
- */
3424
- function max(x) {
3425
- let n = x.length;
3426
- let max = Number.NEGATIVE_INFINITY;
3427
-
3428
- while (n--) max = x[n] > max ? x[n] : max;
3429
- return max;
3430
- }
3431
-
3432
-
3433
- /**
3434
- * Computes a range of values in a vector with a margin
3435
- * @param {number[]} x - vector with values
3436
- * @param {number} margin - margin in parts of one (e.g. 0.1 for 10% or 2 for 200%)
3437
- * @returns{number[]} array with marginal range boundaries
3438
- */
3439
- function mrange(x, margin = 0.05) {
3440
- const mn = min(x);
3441
- const mx = max(x);
3442
- const d = mx - mn;
3443
-
3444
- return [mn - d * margin, max(x) + d * margin];
3445
- }
3446
-
3447
-
3448
- /**
3449
- * Computes difference between all adjacent values in a vector
3450
- * @param {number[]} x - vector with values
3451
- * @returns {number[]} vector with the differences
3452
- */
3453
- function diff(x) {
3454
- return x.slice(1).map( (y, i) => (y - x[i]));
3455
- }
3456
-
3457
- /* src/BarSeries.svelte generated by Svelte v3.50.1 */
3458
-
3459
- function add_css$1(target) {
3460
- append_styles(target, "svelte-kw726w", ".series_bar > rect{stroke-width:1px}.series_bar > rect:hover{opacity:90%}");
3461
- }
3462
-
3463
- function create_fragment$3(ctx) {
3464
- let rectangles;
3465
- let current;
3466
-
3467
- rectangles = new Rectangles({
3468
- props: {
3469
- style: "series_bar",
3470
- left: /*left*/ ctx[4],
3471
- top: /*top*/ ctx[5],
3472
- width: /*width*/ ctx[3],
3473
- height: /*height*/ ctx[6],
3474
- borderColor: /*borderColor*/ ctx[2],
3475
- faceColor: /*faceColor*/ ctx[1],
3476
- title: /*title*/ ctx[0]
3477
- }
3478
- });
3479
-
3480
- return {
3481
- c() {
3482
- create_component(rectangles.$$.fragment);
3483
- },
3484
- m(target, anchor) {
3485
- mount_component(rectangles, target, anchor);
3486
- current = true;
3487
- },
3488
- p(ctx, [dirty]) {
3489
- const rectangles_changes = {};
3490
- if (dirty & /*left*/ 16) rectangles_changes.left = /*left*/ ctx[4];
3491
- if (dirty & /*top*/ 32) rectangles_changes.top = /*top*/ ctx[5];
3492
- if (dirty & /*width*/ 8) rectangles_changes.width = /*width*/ ctx[3];
3493
- if (dirty & /*height*/ 64) rectangles_changes.height = /*height*/ ctx[6];
3494
- if (dirty & /*borderColor*/ 4) rectangles_changes.borderColor = /*borderColor*/ ctx[2];
3495
- if (dirty & /*faceColor*/ 2) rectangles_changes.faceColor = /*faceColor*/ ctx[1];
3496
- if (dirty & /*title*/ 1) rectangles_changes.title = /*title*/ ctx[0];
3497
- rectangles.$set(rectangles_changes);
3498
- },
3499
- i(local) {
3500
- if (current) return;
3501
- transition_in(rectangles.$$.fragment, local);
3502
- current = true;
3503
- },
3504
- o(local) {
3505
- transition_out(rectangles.$$.fragment, local);
3506
- current = false;
3507
- },
3508
- d(detaching) {
3509
- destroy_component(rectangles, detaching);
3510
- }
3511
- };
3512
- }
3513
-
3514
- function instance$3($$self, $$props, $$invalidate) {
3515
- let { xValues } = $$props;
3516
- let { yValues } = $$props;
3517
- let { barWidth = 0.8 } = $$props;
3518
- let { title = "" } = $$props;
3519
- let { faceColor = Colors.PRIMARY } = $$props;
3520
- let { borderColor = Colors.PRIMARY } = $$props;
3521
- let { showLabels = "no" } = $$props;
3522
-
3523
- // TODO: implemented later
3524
- //export let labels = yValues;
3525
- /* internal parameters */
3526
- let width;
3527
-
3528
- let left;
3529
- let top;
3530
- let height;
3531
-
3532
- // to access shared parameters and methods from Axes
3533
- const axes = getContext('axes');
3534
-
3535
- $$self.$$set = $$props => {
3536
- if ('xValues' in $$props) $$invalidate(7, xValues = $$props.xValues);
3537
- if ('yValues' in $$props) $$invalidate(8, yValues = $$props.yValues);
3538
- if ('barWidth' in $$props) $$invalidate(9, barWidth = $$props.barWidth);
3539
- if ('title' in $$props) $$invalidate(0, title = $$props.title);
3540
- if ('faceColor' in $$props) $$invalidate(1, faceColor = $$props.faceColor);
3541
- if ('borderColor' in $$props) $$invalidate(2, borderColor = $$props.borderColor);
3542
- if ('showLabels' in $$props) $$invalidate(10, showLabels = $$props.showLabels);
3543
- };
3544
-
3545
- $$self.$$.update = () => {
3546
- if ($$self.$$.dirty & /*xValues, barWidth, width*/ 648) {
3547
- /* reactive actions related to x-values, fires when there are changes in:
3548
- * - xValues
3549
- * - barWidth
3550
- */
3551
- {
3552
- if (!Array.isArray(xValues)) {
3553
- throw "BarSeries: parameter 'xValues' must be a numeric vector.";
3554
- }
3555
-
3556
- if (barWidth <= 0 || barWidth > 1) {
3557
- throw "BarSeries: parameters 'barWidth' should be between 0 and 1.";
3558
- }
3559
-
3560
- const xValuesRange = mrange(xValues, 0.1);
3561
- xValuesRange[0] = xValuesRange[0] - barWidth * diff(xValuesRange) / xValues.length * 0.5;
3562
- xValuesRange[1] = xValuesRange[1] + barWidth * diff(xValuesRange) / xValues.length * 0.5;
3563
- axes.adjustXAxisLimits(xValuesRange);
3564
- $$invalidate(3, width = Array(xValues.length).fill(max(diff(xValues)) * barWidth));
3565
- $$invalidate(4, left = xValues.map((v, i) => v - width[i] / 2));
3566
- }
3567
- }
3568
-
3569
- if ($$self.$$.dirty & /*yValues, xValues, showLabels*/ 1408) {
3570
- /* reactive actions related to y-values, fires when there are changes in:
3571
- * - yValues
3572
- */
3573
- {
3574
- if (!Array.isArray(yValues) || xValues.length != yValues.length) {
3575
- throw "BarSeries: parameter 'yValues' must be a numeric vector of the same length as 'xValues'.";
3576
- }
3577
-
3578
- const yValuesRange = mrange(yValues, showLabels === "no" ? 0.05 : 0.20);
3579
- axes.adjustYAxisLimits(yValuesRange);
3580
- $$invalidate(5, top = yValues.map(v => v > 0 ? v : 0));
3581
- $$invalidate(6, height = yValues.map(v => Math.abs(v)));
3582
- }
3583
- }
3584
- };
3585
-
3586
- return [
3587
- title,
3588
- faceColor,
3589
- borderColor,
3590
- width,
3591
- left,
3592
- top,
3593
- height,
3594
- xValues,
3595
- yValues,
3596
- barWidth,
3597
- showLabels
3598
- ];
3599
- }
3600
-
3601
- class BarSeries extends SvelteComponent {
3602
- constructor(options) {
3603
- super();
3604
-
3605
- init(
3606
- this,
3607
- options,
3608
- instance$3,
3609
- create_fragment$3,
3610
- safe_not_equal,
3611
- {
3612
- xValues: 7,
3613
- yValues: 8,
3614
- barWidth: 9,
3615
- title: 0,
3616
- faceColor: 1,
3617
- borderColor: 2,
3618
- showLabels: 10
3619
- },
3620
- add_css$1
3621
- );
3622
- }
3623
- }
3624
-
3625
- /* src/ScatterSeries.svelte generated by Svelte v3.50.1 */
3626
-
3627
- function add_css(target) {
3628
- append_styles(target, "svelte-byxua3", ".series_scatter > text{font-size:1em;cursor:default}.series_scatter > text:hover{opacity:90%}.series_scatter > *:hover + .labels_hover{visibility:visible;opacity:1}");
3629
- }
3630
-
3631
- function create_fragment$2(ctx) {
3632
- let textlabels;
3633
- let current;
3634
-
3635
- textlabels = new TextLabels({
3636
- props: {
3637
- xValues: /*xValues*/ ctx[0],
3638
- yValues: /*yValues*/ ctx[1],
3639
- faceColor: /*faceColor*/ ctx[3],
3640
- borderColor: /*borderColor*/ ctx[4],
3641
- borderWidth: /*borderWidth*/ ctx[5],
3642
- title: /*title*/ ctx[2],
3643
- style: "series_scatter",
3644
- labels: /*markerSymbol*/ ctx[7],
3645
- textSize: /*markerSize*/ ctx[6]
3646
- }
3647
- });
3648
-
3649
- return {
3650
- c() {
3651
- create_component(textlabels.$$.fragment);
3652
- },
3653
- m(target, anchor) {
3654
- mount_component(textlabels, target, anchor);
3655
- current = true;
3656
- },
3657
- p(ctx, [dirty]) {
3658
- const textlabels_changes = {};
3659
- if (dirty & /*xValues*/ 1) textlabels_changes.xValues = /*xValues*/ ctx[0];
3660
- if (dirty & /*yValues*/ 2) textlabels_changes.yValues = /*yValues*/ ctx[1];
3661
- if (dirty & /*faceColor*/ 8) textlabels_changes.faceColor = /*faceColor*/ ctx[3];
3662
- if (dirty & /*borderColor*/ 16) textlabels_changes.borderColor = /*borderColor*/ ctx[4];
3663
- if (dirty & /*borderWidth*/ 32) textlabels_changes.borderWidth = /*borderWidth*/ ctx[5];
3664
- if (dirty & /*title*/ 4) textlabels_changes.title = /*title*/ ctx[2];
3665
- if (dirty & /*markerSymbol*/ 128) textlabels_changes.labels = /*markerSymbol*/ ctx[7];
3666
- if (dirty & /*markerSize*/ 64) textlabels_changes.textSize = /*markerSize*/ ctx[6];
3667
- textlabels.$set(textlabels_changes);
3668
- },
3669
- i(local) {
3670
- if (current) return;
3671
- transition_in(textlabels.$$.fragment, local);
3672
- current = true;
3673
- },
3674
- o(local) {
3675
- transition_out(textlabels.$$.fragment, local);
3676
- current = false;
3677
- },
3678
- d(detaching) {
3679
- destroy_component(textlabels, detaching);
3680
- }
3681
- };
3682
- }
3683
-
3684
- function instance$2($$self, $$props, $$invalidate) {
3685
- let { xValues } = $$props;
3686
- let { yValues } = $$props;
3687
- let { marker = 1 } = $$props;
3688
- let { title = "" } = $$props;
3689
- let { faceColor = "transparent" } = $$props;
3690
- let { borderColor = Colors.PRIMARY } = $$props;
3691
- let { borderWidth = 1 } = $$props;
3692
- let { markerSize = 1 } = $$props;
3693
-
3694
- // TODO: implement later
3695
- //export let labels = yValues;
3696
- //export let showLabels = "no"; // can be "no", "hover", "always"
3697
- /* constants for internal use */
3698
- const markers = ["●", "◼", "▲", "▼", "⬥", "+", "*", "⨯"];
3699
-
3700
- let markerSymbol;
3701
-
3702
- /* sanity check of input parameters */
3703
- if (typeof marker !== "number" || marker < 1 || marker > markers.length) {
3704
- throw `ScatterSeries: parameter 'marker' must be a number from 1 to ${markers.length}."`;
3705
- }
3706
-
3707
- // to access shared parameters and methods from Axes
3708
- const axes = getContext('axes');
3709
-
3710
- $$self.$$set = $$props => {
3711
- if ('xValues' in $$props) $$invalidate(0, xValues = $$props.xValues);
3712
- if ('yValues' in $$props) $$invalidate(1, yValues = $$props.yValues);
3713
- if ('marker' in $$props) $$invalidate(8, marker = $$props.marker);
3714
- if ('title' in $$props) $$invalidate(2, title = $$props.title);
3715
- if ('faceColor' in $$props) $$invalidate(3, faceColor = $$props.faceColor);
3716
- if ('borderColor' in $$props) $$invalidate(4, borderColor = $$props.borderColor);
3717
- if ('borderWidth' in $$props) $$invalidate(5, borderWidth = $$props.borderWidth);
3718
- if ('markerSize' in $$props) $$invalidate(6, markerSize = $$props.markerSize);
3719
- };
3720
-
3721
- $$self.$$.update = () => {
3722
- if ($$self.$$.dirty & /*xValues, marker*/ 257) {
3723
- /* reactive actions related to x-values, fires when there are changes in:
3724
- * - xValues
3725
- * - marker
3726
- */
3727
- {
3728
- if (!Array.isArray(xValues)) {
3729
- throw "ScatterSeries: parameter 'xValues' must be a numeric vector.";
3730
- }
3731
-
3732
- const xValuesRange = mrange(xValues, 0.05);
3733
- axes.adjustXAxisLimits(xValuesRange);
3734
- $$invalidate(7, markerSymbol = "");
3735
- $$invalidate(7, markerSymbol = markers[marker - 1]);
3736
- }
3737
- }
3738
-
3739
- if ($$self.$$.dirty & /*yValues, xValues*/ 3) {
3740
- /* reactive actions related to y-values, fires when there are changes in:
3741
- * - yValues
3742
- */
3743
- {
3744
- if (!Array.isArray(yValues) || xValues.length != yValues.length) {
3745
- throw "BarSeries: parameter 'yValues' must be a numeric vector of the same length as 'xValues'.";
3746
- }
3747
-
3748
- const yValuesRange = mrange(yValues, 0.05);
3749
- axes.adjustYAxisLimits(yValuesRange);
3750
- }
3751
- }
3752
- };
3753
-
3754
- return [
3755
- xValues,
3756
- yValues,
3757
- title,
3758
- faceColor,
3759
- borderColor,
3760
- borderWidth,
3761
- markerSize,
3762
- markerSymbol,
3763
- marker
3764
- ];
3765
- }
3766
-
3767
- class ScatterSeries extends SvelteComponent {
3768
- constructor(options) {
3769
- super();
3770
-
3771
- init(
3772
- this,
3773
- options,
3774
- instance$2,
3775
- create_fragment$2,
3776
- safe_not_equal,
3777
- {
3778
- xValues: 0,
3779
- yValues: 1,
3780
- marker: 8,
3781
- title: 2,
3782
- faceColor: 3,
3783
- borderColor: 4,
3784
- borderWidth: 5,
3785
- markerSize: 6
3786
- },
3787
- add_css
3788
- );
3789
- }
3790
- }
3791
-
3792
- /* src/LineSeries.svelte generated by Svelte v3.50.1 */
3793
-
3794
- function create_if_block$1(ctx) {
3795
- let g;
3796
- let polyline;
3797
-
3798
- return {
3799
- c() {
3800
- g = svg_element("g");
3801
- polyline = svg_element("polyline");
3802
- attr(polyline, "class", "line");
3803
- attr(polyline, "points", /*p*/ ctx[2]);
3804
- attr(g, "class", "series series_line");
3805
- attr(g, "style", /*lineStyleStr*/ ctx[1]);
3806
- attr(g, "title", /*title*/ ctx[0]);
3807
- },
3808
- m(target, anchor) {
3809
- insert(target, g, anchor);
3810
- append(g, polyline);
3811
- },
3812
- p(ctx, dirty) {
3813
- if (dirty & /*p*/ 4) {
3814
- attr(polyline, "points", /*p*/ ctx[2]);
3815
- }
3816
-
3817
- if (dirty & /*lineStyleStr*/ 2) {
3818
- attr(g, "style", /*lineStyleStr*/ ctx[1]);
3819
- }
3820
-
3821
- if (dirty & /*title*/ 1) {
3822
- attr(g, "title", /*title*/ ctx[0]);
3823
- }
3824
- },
3825
- d(detaching) {
3826
- if (detaching) detach(g);
3827
- }
3828
- };
3829
- }
3830
-
3831
- function create_fragment$1(ctx) {
3832
- let if_block_anchor;
3833
- let if_block = /*p*/ ctx[2] !== undefined && create_if_block$1(ctx);
3834
-
3835
- return {
3836
- c() {
3837
- if (if_block) if_block.c();
3838
- if_block_anchor = empty();
3839
- },
3840
- m(target, anchor) {
3841
- if (if_block) if_block.m(target, anchor);
3842
- insert(target, if_block_anchor, anchor);
3843
- },
3844
- p(ctx, [dirty]) {
3845
- if (/*p*/ ctx[2] !== undefined) {
3846
- if (if_block) {
3847
- if_block.p(ctx, dirty);
3848
- } else {
3849
- if_block = create_if_block$1(ctx);
3850
- if_block.c();
3851
- if_block.m(if_block_anchor.parentNode, if_block_anchor);
3852
- }
3853
- } else if (if_block) {
3854
- if_block.d(1);
3855
- if_block = null;
3856
- }
3857
- },
3858
- i: noop,
3859
- o: noop,
3860
- d(detaching) {
3861
- if (if_block) if_block.d(detaching);
3862
- if (detaching) detach(if_block_anchor);
3863
- }
3864
- };
3865
- }
3866
-
3867
- function instance$1($$self, $$props, $$invalidate) {
3868
- let x;
3869
- let y;
3870
- let p;
3871
- let lineStyleStr;
3872
- let $scale;
3873
- let $axesHeight;
3874
- let $yLim;
3875
- let $axesWidth;
3876
- let $xLim;
3877
- let { xValues } = $$props;
3878
- let { yValues } = $$props;
3879
- let { title = "" } = $$props;
3880
- let { lineWidth = 1 } = $$props;
3881
- let { lineColor = Colors.PRIMARY } = $$props;
3882
- let { lineType = 1 } = $$props;
3883
-
3884
- /* sanity check of input parameters */
3885
- if (!Array.isArray(xValues) || !Array.isArray(yValues) || xValues.length != yValues.length) {
3886
- throw "LineSeries: parameters 'xValues' and 'yValues' must be numeric vectors of the same length.";
3887
- }
3888
-
3889
- // compute ranges for x and y values
3890
- const xValuesRange = mrange(xValues, 0.05);
3891
-
3892
- const yValuesRange = mrange(yValues, 0.05);
3893
-
3894
- // get axes context and adjust axes limits
3895
- const axes = getContext('axes');
3896
-
3897
- axes.adjustXAxisLimits(xValuesRange);
3898
- axes.adjustYAxisLimits(yValuesRange);
3899
-
3900
- // get reactive variables needed to compute coordinates
3901
- const xLim = axes.xLim;
3902
-
3903
- component_subscribe($$self, xLim, value => $$invalidate(19, $xLim = value));
3904
- const yLim = axes.yLim;
3905
- component_subscribe($$self, yLim, value => $$invalidate(17, $yLim = value));
3906
- const axesWidth = axes.width;
3907
- component_subscribe($$self, axesWidth, value => $$invalidate(18, $axesWidth = value));
3908
- const axesHeight = axes.height;
3909
- component_subscribe($$self, axesHeight, value => $$invalidate(16, $axesHeight = value));
3910
- const scale = axes.scale;
3911
- component_subscribe($$self, scale, value => $$invalidate(15, $scale = value));
3912
-
3913
- $$self.$$set = $$props => {
3914
- if ('xValues' in $$props) $$invalidate(8, xValues = $$props.xValues);
3915
- if ('yValues' in $$props) $$invalidate(9, yValues = $$props.yValues);
3916
- if ('title' in $$props) $$invalidate(0, title = $$props.title);
3917
- if ('lineWidth' in $$props) $$invalidate(10, lineWidth = $$props.lineWidth);
3918
- if ('lineColor' in $$props) $$invalidate(11, lineColor = $$props.lineColor);
3919
- if ('lineType' in $$props) $$invalidate(12, lineType = $$props.lineType);
3920
- };
3921
-
3922
- $$self.$$.update = () => {
3923
- if ($$self.$$.dirty & /*xValues, $xLim, $axesWidth*/ 786688) {
3924
- // reactive variables for coordinates of data points in pixels
3925
- $$invalidate(14, x = axes.scaleX(xValues, $xLim, $axesWidth));
3926
- }
3927
-
3928
- if ($$self.$$.dirty & /*yValues, $yLim, $axesHeight*/ 197120) {
3929
- $$invalidate(13, y = axes.scaleY(yValues, $yLim, $axesHeight));
3930
- }
3931
-
3932
- if ($$self.$$.dirty & /*x, y*/ 24576) {
3933
- $$invalidate(2, p = x !== undefined && y !== undefined
3934
- ? x.map((v, i) => `${v},${y[i]}`).join(' ')
3935
- : undefined);
3936
- }
3937
-
3938
- if ($$self.$$.dirty & /*lineColor, lineWidth, $scale, lineType*/ 39936) {
3939
- $$invalidate(1, lineStyleStr = `fill:transparent;stroke:${lineColor};stroke-width: ${lineWidth}px;
3940
- stroke-dasharray:${axes.LINE_STYLES[$scale][lineType - 1]}`);
3941
- }
3942
- };
3943
-
3944
- return [
3945
- title,
3946
- lineStyleStr,
3947
- p,
3948
- xLim,
3949
- yLim,
3950
- axesWidth,
3951
- axesHeight,
3952
- scale,
3953
- xValues,
3954
- yValues,
3955
- lineWidth,
3956
- lineColor,
3957
- lineType,
3958
- y,
3959
- x,
3960
- $scale,
3961
- $axesHeight,
3962
- $yLim,
3963
- $axesWidth,
3964
- $xLim
3965
- ];
3966
- }
3967
-
3968
- class LineSeries extends SvelteComponent {
3969
- constructor(options) {
3970
- super();
3971
-
3972
- init(this, options, instance$1, create_fragment$1, safe_not_equal, {
3973
- xValues: 8,
3974
- yValues: 9,
3975
- title: 0,
3976
- lineWidth: 10,
3977
- lineColor: 11,
3978
- lineType: 12
3979
- });
3980
- }
3981
- }
3982
-
3983
- /* src/AreaSeries.svelte generated by Svelte v3.50.1 */
3984
-
3985
- function create_if_block(ctx) {
3986
- let g;
3987
- let polygon;
3988
- let polygon_points_value;
3989
-
3990
- return {
3991
- c() {
3992
- g = svg_element("g");
3993
- polygon = svg_element("polygon");
3994
- attr(polygon, "points", polygon_points_value = /*x*/ ctx[1][0] + "," + /*y0*/ ctx[4] + " " + /*p*/ ctx[3] + " " + /*x*/ ctx[1][/*x*/ ctx[1].length - 1] + "," + /*y0*/ ctx[4][0]);
3995
- attr(g, "class", "series lineseries");
3996
- attr(g, "style", /*areaStyleStr*/ ctx[2]);
3997
- attr(g, "title", /*title*/ ctx[0]);
3998
- },
3999
- m(target, anchor) {
4000
- insert(target, g, anchor);
4001
- append(g, polygon);
4002
- },
4003
- p(ctx, dirty) {
4004
- if (dirty & /*x, y0, p*/ 26 && polygon_points_value !== (polygon_points_value = /*x*/ ctx[1][0] + "," + /*y0*/ ctx[4] + " " + /*p*/ ctx[3] + " " + /*x*/ ctx[1][/*x*/ ctx[1].length - 1] + "," + /*y0*/ ctx[4][0])) {
4005
- attr(polygon, "points", polygon_points_value);
4006
- }
4007
-
4008
- if (dirty & /*areaStyleStr*/ 4) {
4009
- attr(g, "style", /*areaStyleStr*/ ctx[2]);
4010
- }
4011
-
4012
- if (dirty & /*title*/ 1) {
4013
- attr(g, "title", /*title*/ ctx[0]);
4014
- }
4015
- },
4016
- d(detaching) {
4017
- if (detaching) detach(g);
4018
- }
4019
- };
4020
- }
4021
-
4022
- function create_fragment(ctx) {
4023
- let if_block_anchor;
4024
- let if_block = /*p*/ ctx[3] !== undefined && create_if_block(ctx);
4025
-
4026
- return {
4027
- c() {
4028
- if (if_block) if_block.c();
4029
- if_block_anchor = empty();
4030
- },
4031
- m(target, anchor) {
4032
- if (if_block) if_block.m(target, anchor);
4033
- insert(target, if_block_anchor, anchor);
4034
- },
4035
- p(ctx, [dirty]) {
4036
- if (/*p*/ ctx[3] !== undefined) {
4037
- if (if_block) {
4038
- if_block.p(ctx, dirty);
4039
- } else {
4040
- if_block = create_if_block(ctx);
4041
- if_block.c();
4042
- if_block.m(if_block_anchor.parentNode, if_block_anchor);
4043
- }
4044
- } else if (if_block) {
4045
- if_block.d(1);
4046
- if_block = null;
4047
- }
4048
- },
4049
- i: noop,
4050
- o: noop,
4051
- d(detaching) {
4052
- if (if_block) if_block.d(detaching);
4053
- if (detaching) detach(if_block_anchor);
4054
- }
4055
- };
4056
- }
4057
-
4058
- function instance($$self, $$props, $$invalidate) {
4059
- let y0;
4060
- let x;
4061
- let y;
4062
- let p;
4063
- let areaStyleStr;
4064
- let $scale;
4065
- let $axesHeight;
4066
- let $yLim;
4067
- let $axesWidth;
4068
- let $xLim;
4069
- let { xValues } = $$props;
4070
- let { yValues } = $$props;
4071
- let { title = "" } = $$props;
4072
- let { lineWidth = 1 } = $$props;
4073
- let { lineColor = Colors.PRIMARY } = $$props;
4074
- let { fillColor = Colors.PRIMARY } = $$props;
4075
- let { opacity = 1 } = $$props;
4076
- let { lineType = 1 } = $$props;
4077
-
4078
- /* sanity check of input parameters */
4079
- if (!Array.isArray(xValues) || !Array.isArray(yValues) || xValues.length != yValues.length) {
4080
- throw "AreaSeries: parameters 'xValues' and 'yValues' must be numeric vectors of the same length.";
4081
- }
4082
-
4083
- // compute ranges for x and y values
4084
- const xValuesRange = mrange(xValues, 0.05);
4085
-
4086
- const yValuesRange = mrange(yValues, 0.05);
4087
-
4088
- // get axes context and adjust axes limits
4089
- const axes = getContext('axes');
4090
-
4091
- axes.adjustXAxisLimits(xValuesRange);
4092
- axes.adjustYAxisLimits(yValuesRange);
4093
-
4094
- // get reactive variables needed to compute coordinates
4095
- const xLim = axes.xLim;
4096
-
4097
- component_subscribe($$self, xLim, value => $$invalidate(22, $xLim = value));
4098
- const yLim = axes.yLim;
4099
- component_subscribe($$self, yLim, value => $$invalidate(20, $yLim = value));
4100
- const axesWidth = axes.width;
4101
- component_subscribe($$self, axesWidth, value => $$invalidate(21, $axesWidth = value));
4102
- const axesHeight = axes.height;
4103
- component_subscribe($$self, axesHeight, value => $$invalidate(19, $axesHeight = value));
4104
- const scale = axes.scale;
4105
- component_subscribe($$self, scale, value => $$invalidate(18, $scale = value));
4106
-
4107
- $$self.$$set = $$props => {
4108
- if ('xValues' in $$props) $$invalidate(10, xValues = $$props.xValues);
4109
- if ('yValues' in $$props) $$invalidate(11, yValues = $$props.yValues);
4110
- if ('title' in $$props) $$invalidate(0, title = $$props.title);
4111
- if ('lineWidth' in $$props) $$invalidate(12, lineWidth = $$props.lineWidth);
4112
- if ('lineColor' in $$props) $$invalidate(13, lineColor = $$props.lineColor);
4113
- if ('fillColor' in $$props) $$invalidate(14, fillColor = $$props.fillColor);
4114
- if ('opacity' in $$props) $$invalidate(15, opacity = $$props.opacity);
4115
- if ('lineType' in $$props) $$invalidate(16, lineType = $$props.lineType);
4116
- };
4117
-
4118
- $$self.$$.update = () => {
4119
- if ($$self.$$.dirty & /*$yLim, $axesHeight*/ 1572864) {
4120
- // reactive variables for coordinates of data points in pixels
4121
- $$invalidate(4, y0 = axes.scaleY([0], $yLim, $axesHeight));
4122
- }
4123
-
4124
- if ($$self.$$.dirty & /*xValues, $xLim, $axesWidth*/ 6292480) {
4125
- $$invalidate(1, x = axes.scaleX(xValues, $xLim, $axesWidth));
4126
- }
4127
-
4128
- if ($$self.$$.dirty & /*yValues, $yLim, $axesHeight*/ 1574912) {
4129
- $$invalidate(17, y = axes.scaleY(yValues, $yLim, $axesHeight));
4130
- }
4131
-
4132
- if ($$self.$$.dirty & /*x, y*/ 131074) {
4133
- $$invalidate(3, p = x !== undefined && y !== undefined
4134
- ? x.map((v, i) => `${v},${y[i]}`).join(' ')
4135
- : undefined);
4136
- }
4137
-
4138
- if ($$self.$$.dirty & /*opacity, fillColor, lineColor, lineWidth, $scale, lineType*/ 389120) {
4139
- $$invalidate(2, areaStyleStr = `opacity:${opacity};fill:${fillColor};stroke:${lineColor};stroke-width: ${lineWidth}px;stroke-dasharray:${axes.LINE_STYLES[$scale][lineType - 1]}`);
4140
- }
4141
- };
4142
-
4143
- return [
4144
- title,
4145
- x,
4146
- areaStyleStr,
4147
- p,
4148
- y0,
4149
- xLim,
4150
- yLim,
4151
- axesWidth,
4152
- axesHeight,
4153
- scale,
4154
- xValues,
4155
- yValues,
4156
- lineWidth,
4157
- lineColor,
4158
- fillColor,
4159
- opacity,
4160
- lineType,
4161
- y,
4162
- $scale,
4163
- $axesHeight,
4164
- $yLim,
4165
- $axesWidth,
4166
- $xLim
4167
- ];
4168
- }
4169
-
4170
- class AreaSeries extends SvelteComponent {
4171
- constructor(options) {
4172
- super();
4173
-
4174
- init(this, options, instance, create_fragment, safe_not_equal, {
4175
- xValues: 10,
4176
- yValues: 11,
4177
- title: 0,
4178
- lineWidth: 12,
4179
- lineColor: 13,
4180
- fillColor: 14,
4181
- opacity: 15,
4182
- lineType: 16
4183
- });
4184
- }
4185
- }
4186
-
4187
- export { AreaSeries, Axes, BarSeries, Box, Colors, LineSeries, Rectangles, ScatterSeries, Segments, TextLabels, TextLegend, XAxis, YAxis };