svelte-plots-basic 1.1.0 → 1.1.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.
- package/README.md +1 -1
- package/dist/index.js +90 -134
- package/dist/index.mjs +90 -134
- package/package.json +1 -1
- package/src/Axes.svelte +22 -9
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Description
|
|
4
4
|
|
|
5
|
-
`svelte-plots-basic` is a [Svelte](https://svelte.dev) component library for creating very simple 2D plots/charts. It is currently under active development and breaking changes may occur. In its current state (v.
|
|
5
|
+
`svelte-plots-basic` is a [Svelte](https://svelte.dev) component library for creating very simple 2D plots/charts. It is currently under active development and breaking changes may occur. In its current state (v. 1.1.1) it allows to create bar, scatter, area and line charts as well as any combination of the four. The charts are created using [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) and are re-scalable.
|
|
6
6
|
|
|
7
7
|
The description is not complete yet and will be updated during February-March of 2022.
|
|
8
8
|
|
package/dist/index.js
CHANGED
|
@@ -162,59 +162,6 @@
|
|
|
162
162
|
node.style.setProperty(key, value, important ? 'important' : '');
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
// unfortunately this can't be a constant as that wouldn't be tree-shakeable
|
|
166
|
-
// so we cache the result instead
|
|
167
|
-
let crossorigin;
|
|
168
|
-
function is_crossorigin() {
|
|
169
|
-
if (crossorigin === undefined) {
|
|
170
|
-
crossorigin = false;
|
|
171
|
-
try {
|
|
172
|
-
if (typeof window !== 'undefined' && window.parent) {
|
|
173
|
-
void window.parent.document;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
177
|
-
crossorigin = true;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return crossorigin;
|
|
181
|
-
}
|
|
182
|
-
function add_resize_listener(node, fn) {
|
|
183
|
-
const computed_style = getComputedStyle(node);
|
|
184
|
-
if (computed_style.position === 'static') {
|
|
185
|
-
node.style.position = 'relative';
|
|
186
|
-
}
|
|
187
|
-
const iframe = element('iframe');
|
|
188
|
-
iframe.setAttribute('style', 'display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; ' +
|
|
189
|
-
'overflow: hidden; border: 0; opacity: 0; pointer-events: none; z-index: -1;');
|
|
190
|
-
iframe.setAttribute('aria-hidden', 'true');
|
|
191
|
-
iframe.tabIndex = -1;
|
|
192
|
-
const crossorigin = is_crossorigin();
|
|
193
|
-
let unsubscribe;
|
|
194
|
-
if (crossorigin) {
|
|
195
|
-
iframe.src = "data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}</script>";
|
|
196
|
-
unsubscribe = listen(window, 'message', (event) => {
|
|
197
|
-
if (event.source === iframe.contentWindow)
|
|
198
|
-
fn();
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
iframe.src = 'about:blank';
|
|
203
|
-
iframe.onload = () => {
|
|
204
|
-
unsubscribe = listen(iframe.contentWindow, 'resize', fn);
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
append(node, iframe);
|
|
208
|
-
return () => {
|
|
209
|
-
if (crossorigin) {
|
|
210
|
-
unsubscribe();
|
|
211
|
-
}
|
|
212
|
-
else if (unsubscribe && iframe.contentWindow) {
|
|
213
|
-
unsubscribe();
|
|
214
|
-
}
|
|
215
|
-
detach(iframe);
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
165
|
function toggle_class(element, name, toggle) {
|
|
219
166
|
element.classList[toggle ? 'add' : 'remove'](name);
|
|
220
167
|
}
|
|
@@ -233,6 +180,9 @@
|
|
|
233
180
|
throw new Error('Function called outside component initialization');
|
|
234
181
|
return current_component;
|
|
235
182
|
}
|
|
183
|
+
function onMount(fn) {
|
|
184
|
+
get_current_component().$$.on_mount.push(fn);
|
|
185
|
+
}
|
|
236
186
|
function createEventDispatcher() {
|
|
237
187
|
const component = get_current_component();
|
|
238
188
|
return (type, detail, { cancelable = false } = {}) => {
|
|
@@ -565,7 +515,7 @@
|
|
|
565
515
|
const get_xaxis_slot_changes = dirty => ({});
|
|
566
516
|
const get_xaxis_slot_context = ctx => ({});
|
|
567
517
|
|
|
568
|
-
// (
|
|
518
|
+
// (342:3) {#if title !== ""}
|
|
569
519
|
function create_if_block_3(ctx) {
|
|
570
520
|
let div;
|
|
571
521
|
|
|
@@ -586,7 +536,7 @@
|
|
|
586
536
|
};
|
|
587
537
|
}
|
|
588
538
|
|
|
589
|
-
// (
|
|
539
|
+
// (343:3) {#if yLabel !== ""}
|
|
590
540
|
function create_if_block_2(ctx) {
|
|
591
541
|
let div;
|
|
592
542
|
let span;
|
|
@@ -610,7 +560,7 @@
|
|
|
610
560
|
};
|
|
611
561
|
}
|
|
612
562
|
|
|
613
|
-
// (
|
|
563
|
+
// (344:3) {#if xLabel !== ""}
|
|
614
564
|
function create_if_block_1(ctx) {
|
|
615
565
|
let div;
|
|
616
566
|
let span;
|
|
@@ -634,7 +584,7 @@
|
|
|
634
584
|
};
|
|
635
585
|
}
|
|
636
586
|
|
|
637
|
-
// (
|
|
587
|
+
// (372:3) {#if !$isOk}
|
|
638
588
|
function create_if_block$9(ctx) {
|
|
639
589
|
let p;
|
|
640
590
|
|
|
@@ -671,10 +621,8 @@
|
|
|
671
621
|
let rect_width_value;
|
|
672
622
|
let rect_height_value;
|
|
673
623
|
let g;
|
|
674
|
-
let div0_resize_listener;
|
|
675
624
|
let t3;
|
|
676
625
|
let div1_class_value;
|
|
677
|
-
let div1_resize_listener;
|
|
678
626
|
let current;
|
|
679
627
|
let mounted;
|
|
680
628
|
let dispose;
|
|
@@ -689,7 +637,7 @@
|
|
|
689
637
|
const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[26], null);
|
|
690
638
|
const box_slot_template = /*#slots*/ ctx[27].box;
|
|
691
639
|
const box_slot = create_slot(box_slot_template, ctx, /*$$scope*/ ctx[26], get_box_slot_context);
|
|
692
|
-
let if_block3 = !/*$isOk*/ ctx[
|
|
640
|
+
let if_block3 = !/*$isOk*/ ctx[3] && create_if_block$9();
|
|
693
641
|
|
|
694
642
|
return {
|
|
695
643
|
c() {
|
|
@@ -713,19 +661,17 @@
|
|
|
713
661
|
t3 = space();
|
|
714
662
|
if (if_block3) if_block3.c();
|
|
715
663
|
set_style(rect, "pointer-events", "none");
|
|
716
|
-
attr(rect, "x", rect_x_value = /*cpx*/ ctx[
|
|
717
|
-
attr(rect, "y", rect_y_value = /*cpy*/ ctx[
|
|
718
|
-
attr(rect, "width", rect_width_value = /*cpx*/ ctx[
|
|
719
|
-
attr(rect, "height", rect_height_value = /*cpy*/ ctx[
|
|
720
|
-
attr(clipPath, "id", /*clipPathID*/ ctx[
|
|
721
|
-
attr(g, "clip-path", "url(#" + /*clipPathID*/ ctx[
|
|
664
|
+
attr(rect, "x", rect_x_value = /*cpx*/ ctx[8][0]);
|
|
665
|
+
attr(rect, "y", rect_y_value = /*cpy*/ ctx[7][1]);
|
|
666
|
+
attr(rect, "width", rect_width_value = /*cpx*/ ctx[8][1] - /*cpx*/ ctx[8][0]);
|
|
667
|
+
attr(rect, "height", rect_height_value = /*cpy*/ ctx[7][0] - /*cpy*/ ctx[7][1]);
|
|
668
|
+
attr(clipPath, "id", /*clipPathID*/ ctx[9]);
|
|
669
|
+
attr(g, "clip-path", "url(#" + /*clipPathID*/ ctx[9] + ")");
|
|
722
670
|
attr(svg, "preserveAspectRatio", "none");
|
|
723
671
|
attr(svg, "class", "axes");
|
|
724
672
|
attr(div0, "class", "axes-wrapper svelte-n80kcc");
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
add_render_callback(() => /*div1_elementresize_handler*/ ctx[29].call(div1));
|
|
728
|
-
toggle_class(div1, "plot_error", !/*$isOk*/ ctx[6]);
|
|
673
|
+
attr(div1, "class", div1_class_value = "plot " + ('plot_' + /*$scale*/ ctx[4]) + " svelte-n80kcc");
|
|
674
|
+
toggle_class(div1, "plot_error", !/*$isOk*/ ctx[3]);
|
|
729
675
|
},
|
|
730
676
|
m(target, anchor) {
|
|
731
677
|
insert(target, div1, anchor);
|
|
@@ -759,14 +705,14 @@
|
|
|
759
705
|
box_slot.m(svg, null);
|
|
760
706
|
}
|
|
761
707
|
|
|
762
|
-
|
|
708
|
+
/*div0_binding*/ ctx[28](div0);
|
|
763
709
|
append(div1, t3);
|
|
764
710
|
if (if_block3) if_block3.m(div1, null);
|
|
765
|
-
|
|
711
|
+
/*div1_binding*/ ctx[29](div1);
|
|
766
712
|
current = true;
|
|
767
713
|
|
|
768
714
|
if (!mounted) {
|
|
769
|
-
dispose = listen(svg, "click", /*handleClick*/ ctx[
|
|
715
|
+
dispose = listen(svg, "click", /*handleClick*/ ctx[16]);
|
|
770
716
|
mounted = true;
|
|
771
717
|
}
|
|
772
718
|
},
|
|
@@ -810,19 +756,19 @@
|
|
|
810
756
|
if_block2 = null;
|
|
811
757
|
}
|
|
812
758
|
|
|
813
|
-
if (!current || dirty[0] & /*cpx*/
|
|
759
|
+
if (!current || dirty[0] & /*cpx*/ 256 && rect_x_value !== (rect_x_value = /*cpx*/ ctx[8][0])) {
|
|
814
760
|
attr(rect, "x", rect_x_value);
|
|
815
761
|
}
|
|
816
762
|
|
|
817
|
-
if (!current || dirty[0] & /*cpy*/
|
|
763
|
+
if (!current || dirty[0] & /*cpy*/ 128 && rect_y_value !== (rect_y_value = /*cpy*/ ctx[7][1])) {
|
|
818
764
|
attr(rect, "y", rect_y_value);
|
|
819
765
|
}
|
|
820
766
|
|
|
821
|
-
if (!current || dirty[0] & /*cpx*/
|
|
767
|
+
if (!current || dirty[0] & /*cpx*/ 256 && rect_width_value !== (rect_width_value = /*cpx*/ ctx[8][1] - /*cpx*/ ctx[8][0])) {
|
|
822
768
|
attr(rect, "width", rect_width_value);
|
|
823
769
|
}
|
|
824
770
|
|
|
825
|
-
if (!current || dirty[0] & /*cpy*/
|
|
771
|
+
if (!current || dirty[0] & /*cpy*/ 128 && rect_height_value !== (rect_height_value = /*cpy*/ ctx[7][0] - /*cpy*/ ctx[7][1])) {
|
|
826
772
|
attr(rect, "height", rect_height_value);
|
|
827
773
|
}
|
|
828
774
|
|
|
@@ -886,7 +832,7 @@
|
|
|
886
832
|
}
|
|
887
833
|
}
|
|
888
834
|
|
|
889
|
-
if (!/*$isOk*/ ctx[
|
|
835
|
+
if (!/*$isOk*/ ctx[3]) {
|
|
890
836
|
if (if_block3) ; else {
|
|
891
837
|
if_block3 = create_if_block$9();
|
|
892
838
|
if_block3.c();
|
|
@@ -897,12 +843,12 @@
|
|
|
897
843
|
if_block3 = null;
|
|
898
844
|
}
|
|
899
845
|
|
|
900
|
-
if (!current || dirty[0] & /*$scale*/
|
|
846
|
+
if (!current || dirty[0] & /*$scale*/ 16 && div1_class_value !== (div1_class_value = "plot " + ('plot_' + /*$scale*/ ctx[4]) + " svelte-n80kcc")) {
|
|
901
847
|
attr(div1, "class", div1_class_value);
|
|
902
848
|
}
|
|
903
849
|
|
|
904
|
-
if (dirty[0] & /*$scale, $isOk*/
|
|
905
|
-
toggle_class(div1, "plot_error", !/*$isOk*/ ctx[
|
|
850
|
+
if (dirty[0] & /*$scale, $isOk*/ 24) {
|
|
851
|
+
toggle_class(div1, "plot_error", !/*$isOk*/ ctx[3]);
|
|
906
852
|
}
|
|
907
853
|
},
|
|
908
854
|
i(local) {
|
|
@@ -929,9 +875,9 @@
|
|
|
929
875
|
if (yaxis_slot) yaxis_slot.d(detaching);
|
|
930
876
|
if (default_slot) default_slot.d(detaching);
|
|
931
877
|
if (box_slot) box_slot.d(detaching);
|
|
932
|
-
|
|
878
|
+
/*div0_binding*/ ctx[28](null);
|
|
933
879
|
if (if_block3) if_block3.d();
|
|
934
|
-
|
|
880
|
+
/*div1_binding*/ ctx[29](null);
|
|
935
881
|
mounted = false;
|
|
936
882
|
dispose();
|
|
937
883
|
}
|
|
@@ -1004,40 +950,40 @@
|
|
|
1004
950
|
const clipPathID = "plottingArea" + Math.round(Math.random() * 10000);
|
|
1005
951
|
|
|
1006
952
|
/* parameters for internal use inside the component */
|
|
1007
|
-
let
|
|
953
|
+
let plotElement;
|
|
1008
954
|
|
|
1009
|
-
let
|
|
955
|
+
let axesElement;
|
|
1010
956
|
let axesMargins = [0.034, 0.034, 0.034, 0.034]; // initial margins (will be multiplied to FACTORS)
|
|
1011
957
|
|
|
1012
958
|
/* reactive parameters to be shared with children via context */
|
|
1013
959
|
const width = writable(100); // actual width of plotting area in pixels
|
|
1014
960
|
|
|
1015
|
-
component_subscribe($$self, width, value => $$invalidate(
|
|
961
|
+
component_subscribe($$self, width, value => $$invalidate(24, $width = value));
|
|
1016
962
|
const height = writable(100); // actual height of plotting area in pixels
|
|
1017
|
-
component_subscribe($$self, height, value => $$invalidate(
|
|
963
|
+
component_subscribe($$self, height, value => $$invalidate(22, $height = value));
|
|
1018
964
|
const xLim = writable([undefined, undefined]); // actual limits for x-axis in plot units
|
|
1019
965
|
component_subscribe($$self, xLim, value => $$invalidate(25, $xLim = value));
|
|
1020
966
|
const yLim = writable([undefined, undefined]); // actual limits for y-axis in plot units
|
|
1021
|
-
component_subscribe($$self, yLim, value => $$invalidate(
|
|
967
|
+
component_subscribe($$self, yLim, value => $$invalidate(23, $yLim = value));
|
|
1022
968
|
const scale = writable("medium"); // scale factor (how big the shown plot is)
|
|
1023
|
-
component_subscribe($$self, scale, value => $$invalidate(
|
|
969
|
+
component_subscribe($$self, scale, value => $$invalidate(4, $scale = value));
|
|
1024
970
|
const isOk = writable(false); // are axes ready for drawing
|
|
1025
|
-
component_subscribe($$self, isOk, value => $$invalidate(
|
|
971
|
+
component_subscribe($$self, isOk, value => $$invalidate(3, $isOk = value));
|
|
1026
972
|
|
|
1027
973
|
/** Adds margins for x-axis (e.g. when x-axis must be shown) */
|
|
1028
974
|
const addXAxisMargins = function () {
|
|
1029
|
-
$$invalidate(
|
|
1030
|
-
$$invalidate(
|
|
1031
|
-
$$invalidate(
|
|
1032
|
-
$$invalidate(
|
|
975
|
+
$$invalidate(20, axesMargins[0] = 1, axesMargins);
|
|
976
|
+
$$invalidate(20, axesMargins[2] = 0.5, axesMargins);
|
|
977
|
+
$$invalidate(20, axesMargins[1] = axesMargins[1] > 0.5 ? axesMargins[1] : 0.5, axesMargins);
|
|
978
|
+
$$invalidate(20, axesMargins[3] = axesMargins[3] > 0.5 ? axesMargins[3] : 0.5, axesMargins);
|
|
1033
979
|
};
|
|
1034
980
|
|
|
1035
981
|
/** Adds margins for y-axis (e.g. when y-axis must be shown) */
|
|
1036
982
|
const addYAxisMargins = function () {
|
|
1037
|
-
$$invalidate(
|
|
1038
|
-
$$invalidate(
|
|
1039
|
-
$$invalidate(
|
|
1040
|
-
$$invalidate(
|
|
983
|
+
$$invalidate(20, axesMargins[1] = 1, axesMargins);
|
|
984
|
+
$$invalidate(20, axesMargins[3] = 0.5, axesMargins);
|
|
985
|
+
$$invalidate(20, axesMargins[0] = axesMargins[0] > 0.5 ? axesMargins[0] : 0.5, axesMargins);
|
|
986
|
+
$$invalidate(20, axesMargins[2] = axesMargins[2] > 0.5 ? axesMargins[2] : 0.5, axesMargins);
|
|
1041
987
|
};
|
|
1042
988
|
|
|
1043
989
|
/** Adjusts limits for x-axis (e.g. when new series is added)
|
|
@@ -1211,63 +1157,73 @@
|
|
|
1211
1157
|
dispatch("axesclick");
|
|
1212
1158
|
}
|
|
1213
1159
|
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1160
|
+
/* observer for the plotting area size */
|
|
1161
|
+
var ro = new ResizeObserver(entries => {
|
|
1162
|
+
for (let entry of entries) {
|
|
1163
|
+
const pcr = plotElement.getBoundingClientRect();
|
|
1164
|
+
const acr = axesElement.getBoundingClientRect();
|
|
1165
|
+
width.update(x => acr.width);
|
|
1166
|
+
height.update(x => acr.height);
|
|
1167
|
+
scale.update(x => getScale(pcr.width, pcr.height));
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
onMount(() => {
|
|
1172
|
+
ro.observe(plotElement);
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
function div0_binding($$value) {
|
|
1176
|
+
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
1177
|
+
axesElement = $$value;
|
|
1178
|
+
$$invalidate(6, axesElement);
|
|
1179
|
+
});
|
|
1219
1180
|
}
|
|
1220
1181
|
|
|
1221
|
-
function
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1182
|
+
function div1_binding($$value) {
|
|
1183
|
+
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
1184
|
+
plotElement = $$value;
|
|
1185
|
+
$$invalidate(5, plotElement);
|
|
1186
|
+
});
|
|
1226
1187
|
}
|
|
1227
1188
|
|
|
1228
1189
|
$$self.$$set = $$props => {
|
|
1229
|
-
if ('limX' in $$props) $$invalidate(
|
|
1230
|
-
if ('limY' in $$props) $$invalidate(
|
|
1190
|
+
if ('limX' in $$props) $$invalidate(17, limX = $$props.limX);
|
|
1191
|
+
if ('limY' in $$props) $$invalidate(18, limY = $$props.limY);
|
|
1231
1192
|
if ('title' in $$props) $$invalidate(0, title = $$props.title);
|
|
1232
1193
|
if ('xLabel' in $$props) $$invalidate(1, xLabel = $$props.xLabel);
|
|
1233
1194
|
if ('yLabel' in $$props) $$invalidate(2, yLabel = $$props.yLabel);
|
|
1234
|
-
if ('multiSeries' in $$props) $$invalidate(
|
|
1195
|
+
if ('multiSeries' in $$props) $$invalidate(19, multiSeries = $$props.multiSeries);
|
|
1235
1196
|
if ('$$scope' in $$props) $$invalidate(26, $$scope = $$props.$$scope);
|
|
1236
1197
|
};
|
|
1237
1198
|
|
|
1238
1199
|
$$self.$$.update = () => {
|
|
1239
|
-
if ($$self.$$.dirty[0] & /*
|
|
1240
|
-
// update plot scale based on its size
|
|
1241
|
-
scale.update(x => getScale(plotWidth, plotHeight));
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
if ($$self.$$.dirty[0] & /*limX*/ 524288) {
|
|
1200
|
+
if ($$self.$$.dirty[0] & /*limX*/ 131072) {
|
|
1245
1201
|
// this is reactive in case if limX and limY are interactively changed by parent script
|
|
1246
1202
|
if (!limX.some(v => v === undefined)) xLim.update(v => limX);
|
|
1247
1203
|
}
|
|
1248
1204
|
|
|
1249
|
-
if ($$self.$$.dirty[0] & /*limY*/
|
|
1205
|
+
if ($$self.$$.dirty[0] & /*limY*/ 262144) {
|
|
1250
1206
|
if (!limY.some(v => v === undefined)) yLim.update(v => limY);
|
|
1251
1207
|
}
|
|
1252
1208
|
|
|
1253
|
-
if ($$self.$$.dirty[0] & /*axesMargins, $scale*/
|
|
1209
|
+
if ($$self.$$.dirty[0] & /*axesMargins, $scale*/ 1048592) {
|
|
1254
1210
|
// computes real margins in pixels based on current scale
|
|
1255
|
-
$$invalidate(
|
|
1211
|
+
$$invalidate(21, margins = axesMargins.map(v => v * AXES_MARGIN_FACTORS[$scale]));
|
|
1256
1212
|
}
|
|
1257
1213
|
|
|
1258
|
-
if ($$self.$$.dirty[0] & /*$yLim, $xLim, $width, margins, $height*/
|
|
1214
|
+
if ($$self.$$.dirty[0] & /*$yLim, $xLim, $width, margins, $height*/ 65011712) {
|
|
1259
1215
|
// computes status which tells that axes limits look fine and it is safe to draw
|
|
1260
1216
|
// the status is based on the axis limits validity
|
|
1261
1217
|
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]);
|
|
1262
1218
|
}
|
|
1263
1219
|
|
|
1264
|
-
if ($$self.$$.dirty[0] & /*$isOk, $xLim, $width*/
|
|
1220
|
+
if ($$self.$$.dirty[0] & /*$isOk, $xLim, $width*/ 50331656) {
|
|
1265
1221
|
// computes coordinates for clip path box
|
|
1266
|
-
$$invalidate(
|
|
1222
|
+
$$invalidate(8, cpx = $isOk ? scaleX($xLim, $xLim, $width) : [0, 1]);
|
|
1267
1223
|
}
|
|
1268
1224
|
|
|
1269
|
-
if ($$self.$$.dirty[0] & /*$isOk, $yLim, $height*/
|
|
1270
|
-
$$invalidate(
|
|
1225
|
+
if ($$self.$$.dirty[0] & /*$isOk, $yLim, $height*/ 12582920) {
|
|
1226
|
+
$$invalidate(7, cpy = $isOk ? scaleY($yLim, $yLim, $height) : [1, 0]);
|
|
1271
1227
|
}
|
|
1272
1228
|
};
|
|
1273
1229
|
|
|
@@ -1275,12 +1231,10 @@
|
|
|
1275
1231
|
title,
|
|
1276
1232
|
xLabel,
|
|
1277
1233
|
yLabel,
|
|
1278
|
-
plotWidth,
|
|
1279
|
-
plotHeight,
|
|
1280
|
-
$height,
|
|
1281
1234
|
$isOk,
|
|
1282
|
-
$width,
|
|
1283
1235
|
$scale,
|
|
1236
|
+
plotElement,
|
|
1237
|
+
axesElement,
|
|
1284
1238
|
cpy,
|
|
1285
1239
|
cpx,
|
|
1286
1240
|
clipPathID,
|
|
@@ -1296,12 +1250,14 @@
|
|
|
1296
1250
|
multiSeries,
|
|
1297
1251
|
axesMargins,
|
|
1298
1252
|
margins,
|
|
1253
|
+
$height,
|
|
1299
1254
|
$yLim,
|
|
1255
|
+
$width,
|
|
1300
1256
|
$xLim,
|
|
1301
1257
|
$$scope,
|
|
1302
1258
|
slots,
|
|
1303
|
-
|
|
1304
|
-
|
|
1259
|
+
div0_binding,
|
|
1260
|
+
div1_binding
|
|
1305
1261
|
];
|
|
1306
1262
|
}
|
|
1307
1263
|
|
|
@@ -1316,12 +1272,12 @@
|
|
|
1316
1272
|
create_fragment$b,
|
|
1317
1273
|
safe_not_equal,
|
|
1318
1274
|
{
|
|
1319
|
-
limX:
|
|
1320
|
-
limY:
|
|
1275
|
+
limX: 17,
|
|
1276
|
+
limY: 18,
|
|
1321
1277
|
title: 0,
|
|
1322
1278
|
xLabel: 1,
|
|
1323
1279
|
yLabel: 2,
|
|
1324
|
-
multiSeries:
|
|
1280
|
+
multiSeries: 19
|
|
1325
1281
|
},
|
|
1326
1282
|
add_css$3,
|
|
1327
1283
|
[-1, -1]
|
package/dist/index.mjs
CHANGED
|
@@ -156,59 +156,6 @@ function set_style(node, key, value, important) {
|
|
|
156
156
|
node.style.setProperty(key, value, important ? 'important' : '');
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
// unfortunately this can't be a constant as that wouldn't be tree-shakeable
|
|
160
|
-
// so we cache the result instead
|
|
161
|
-
let crossorigin;
|
|
162
|
-
function is_crossorigin() {
|
|
163
|
-
if (crossorigin === undefined) {
|
|
164
|
-
crossorigin = false;
|
|
165
|
-
try {
|
|
166
|
-
if (typeof window !== 'undefined' && window.parent) {
|
|
167
|
-
void window.parent.document;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
catch (error) {
|
|
171
|
-
crossorigin = true;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return crossorigin;
|
|
175
|
-
}
|
|
176
|
-
function add_resize_listener(node, fn) {
|
|
177
|
-
const computed_style = getComputedStyle(node);
|
|
178
|
-
if (computed_style.position === 'static') {
|
|
179
|
-
node.style.position = 'relative';
|
|
180
|
-
}
|
|
181
|
-
const iframe = element('iframe');
|
|
182
|
-
iframe.setAttribute('style', 'display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; ' +
|
|
183
|
-
'overflow: hidden; border: 0; opacity: 0; pointer-events: none; z-index: -1;');
|
|
184
|
-
iframe.setAttribute('aria-hidden', 'true');
|
|
185
|
-
iframe.tabIndex = -1;
|
|
186
|
-
const crossorigin = is_crossorigin();
|
|
187
|
-
let unsubscribe;
|
|
188
|
-
if (crossorigin) {
|
|
189
|
-
iframe.src = "data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}</script>";
|
|
190
|
-
unsubscribe = listen(window, 'message', (event) => {
|
|
191
|
-
if (event.source === iframe.contentWindow)
|
|
192
|
-
fn();
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
iframe.src = 'about:blank';
|
|
197
|
-
iframe.onload = () => {
|
|
198
|
-
unsubscribe = listen(iframe.contentWindow, 'resize', fn);
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
append(node, iframe);
|
|
202
|
-
return () => {
|
|
203
|
-
if (crossorigin) {
|
|
204
|
-
unsubscribe();
|
|
205
|
-
}
|
|
206
|
-
else if (unsubscribe && iframe.contentWindow) {
|
|
207
|
-
unsubscribe();
|
|
208
|
-
}
|
|
209
|
-
detach(iframe);
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
159
|
function toggle_class(element, name, toggle) {
|
|
213
160
|
element.classList[toggle ? 'add' : 'remove'](name);
|
|
214
161
|
}
|
|
@@ -227,6 +174,9 @@ function get_current_component() {
|
|
|
227
174
|
throw new Error('Function called outside component initialization');
|
|
228
175
|
return current_component;
|
|
229
176
|
}
|
|
177
|
+
function onMount(fn) {
|
|
178
|
+
get_current_component().$$.on_mount.push(fn);
|
|
179
|
+
}
|
|
230
180
|
function createEventDispatcher() {
|
|
231
181
|
const component = get_current_component();
|
|
232
182
|
return (type, detail, { cancelable = false } = {}) => {
|
|
@@ -559,7 +509,7 @@ const get_yaxis_slot_context = ctx => ({});
|
|
|
559
509
|
const get_xaxis_slot_changes = dirty => ({});
|
|
560
510
|
const get_xaxis_slot_context = ctx => ({});
|
|
561
511
|
|
|
562
|
-
// (
|
|
512
|
+
// (342:3) {#if title !== ""}
|
|
563
513
|
function create_if_block_3(ctx) {
|
|
564
514
|
let div;
|
|
565
515
|
|
|
@@ -580,7 +530,7 @@ function create_if_block_3(ctx) {
|
|
|
580
530
|
};
|
|
581
531
|
}
|
|
582
532
|
|
|
583
|
-
// (
|
|
533
|
+
// (343:3) {#if yLabel !== ""}
|
|
584
534
|
function create_if_block_2(ctx) {
|
|
585
535
|
let div;
|
|
586
536
|
let span;
|
|
@@ -604,7 +554,7 @@ function create_if_block_2(ctx) {
|
|
|
604
554
|
};
|
|
605
555
|
}
|
|
606
556
|
|
|
607
|
-
// (
|
|
557
|
+
// (344:3) {#if xLabel !== ""}
|
|
608
558
|
function create_if_block_1(ctx) {
|
|
609
559
|
let div;
|
|
610
560
|
let span;
|
|
@@ -628,7 +578,7 @@ function create_if_block_1(ctx) {
|
|
|
628
578
|
};
|
|
629
579
|
}
|
|
630
580
|
|
|
631
|
-
// (
|
|
581
|
+
// (372:3) {#if !$isOk}
|
|
632
582
|
function create_if_block$9(ctx) {
|
|
633
583
|
let p;
|
|
634
584
|
|
|
@@ -665,10 +615,8 @@ function create_fragment$b(ctx) {
|
|
|
665
615
|
let rect_width_value;
|
|
666
616
|
let rect_height_value;
|
|
667
617
|
let g;
|
|
668
|
-
let div0_resize_listener;
|
|
669
618
|
let t3;
|
|
670
619
|
let div1_class_value;
|
|
671
|
-
let div1_resize_listener;
|
|
672
620
|
let current;
|
|
673
621
|
let mounted;
|
|
674
622
|
let dispose;
|
|
@@ -683,7 +631,7 @@ function create_fragment$b(ctx) {
|
|
|
683
631
|
const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[26], null);
|
|
684
632
|
const box_slot_template = /*#slots*/ ctx[27].box;
|
|
685
633
|
const box_slot = create_slot(box_slot_template, ctx, /*$$scope*/ ctx[26], get_box_slot_context);
|
|
686
|
-
let if_block3 = !/*$isOk*/ ctx[
|
|
634
|
+
let if_block3 = !/*$isOk*/ ctx[3] && create_if_block$9();
|
|
687
635
|
|
|
688
636
|
return {
|
|
689
637
|
c() {
|
|
@@ -707,19 +655,17 @@ function create_fragment$b(ctx) {
|
|
|
707
655
|
t3 = space();
|
|
708
656
|
if (if_block3) if_block3.c();
|
|
709
657
|
set_style(rect, "pointer-events", "none");
|
|
710
|
-
attr(rect, "x", rect_x_value = /*cpx*/ ctx[
|
|
711
|
-
attr(rect, "y", rect_y_value = /*cpy*/ ctx[
|
|
712
|
-
attr(rect, "width", rect_width_value = /*cpx*/ ctx[
|
|
713
|
-
attr(rect, "height", rect_height_value = /*cpy*/ ctx[
|
|
714
|
-
attr(clipPath, "id", /*clipPathID*/ ctx[
|
|
715
|
-
attr(g, "clip-path", "url(#" + /*clipPathID*/ ctx[
|
|
658
|
+
attr(rect, "x", rect_x_value = /*cpx*/ ctx[8][0]);
|
|
659
|
+
attr(rect, "y", rect_y_value = /*cpy*/ ctx[7][1]);
|
|
660
|
+
attr(rect, "width", rect_width_value = /*cpx*/ ctx[8][1] - /*cpx*/ ctx[8][0]);
|
|
661
|
+
attr(rect, "height", rect_height_value = /*cpy*/ ctx[7][0] - /*cpy*/ ctx[7][1]);
|
|
662
|
+
attr(clipPath, "id", /*clipPathID*/ ctx[9]);
|
|
663
|
+
attr(g, "clip-path", "url(#" + /*clipPathID*/ ctx[9] + ")");
|
|
716
664
|
attr(svg, "preserveAspectRatio", "none");
|
|
717
665
|
attr(svg, "class", "axes");
|
|
718
666
|
attr(div0, "class", "axes-wrapper svelte-n80kcc");
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
add_render_callback(() => /*div1_elementresize_handler*/ ctx[29].call(div1));
|
|
722
|
-
toggle_class(div1, "plot_error", !/*$isOk*/ ctx[6]);
|
|
667
|
+
attr(div1, "class", div1_class_value = "plot " + ('plot_' + /*$scale*/ ctx[4]) + " svelte-n80kcc");
|
|
668
|
+
toggle_class(div1, "plot_error", !/*$isOk*/ ctx[3]);
|
|
723
669
|
},
|
|
724
670
|
m(target, anchor) {
|
|
725
671
|
insert(target, div1, anchor);
|
|
@@ -753,14 +699,14 @@ function create_fragment$b(ctx) {
|
|
|
753
699
|
box_slot.m(svg, null);
|
|
754
700
|
}
|
|
755
701
|
|
|
756
|
-
|
|
702
|
+
/*div0_binding*/ ctx[28](div0);
|
|
757
703
|
append(div1, t3);
|
|
758
704
|
if (if_block3) if_block3.m(div1, null);
|
|
759
|
-
|
|
705
|
+
/*div1_binding*/ ctx[29](div1);
|
|
760
706
|
current = true;
|
|
761
707
|
|
|
762
708
|
if (!mounted) {
|
|
763
|
-
dispose = listen(svg, "click", /*handleClick*/ ctx[
|
|
709
|
+
dispose = listen(svg, "click", /*handleClick*/ ctx[16]);
|
|
764
710
|
mounted = true;
|
|
765
711
|
}
|
|
766
712
|
},
|
|
@@ -804,19 +750,19 @@ function create_fragment$b(ctx) {
|
|
|
804
750
|
if_block2 = null;
|
|
805
751
|
}
|
|
806
752
|
|
|
807
|
-
if (!current || dirty[0] & /*cpx*/
|
|
753
|
+
if (!current || dirty[0] & /*cpx*/ 256 && rect_x_value !== (rect_x_value = /*cpx*/ ctx[8][0])) {
|
|
808
754
|
attr(rect, "x", rect_x_value);
|
|
809
755
|
}
|
|
810
756
|
|
|
811
|
-
if (!current || dirty[0] & /*cpy*/
|
|
757
|
+
if (!current || dirty[0] & /*cpy*/ 128 && rect_y_value !== (rect_y_value = /*cpy*/ ctx[7][1])) {
|
|
812
758
|
attr(rect, "y", rect_y_value);
|
|
813
759
|
}
|
|
814
760
|
|
|
815
|
-
if (!current || dirty[0] & /*cpx*/
|
|
761
|
+
if (!current || dirty[0] & /*cpx*/ 256 && rect_width_value !== (rect_width_value = /*cpx*/ ctx[8][1] - /*cpx*/ ctx[8][0])) {
|
|
816
762
|
attr(rect, "width", rect_width_value);
|
|
817
763
|
}
|
|
818
764
|
|
|
819
|
-
if (!current || dirty[0] & /*cpy*/
|
|
765
|
+
if (!current || dirty[0] & /*cpy*/ 128 && rect_height_value !== (rect_height_value = /*cpy*/ ctx[7][0] - /*cpy*/ ctx[7][1])) {
|
|
820
766
|
attr(rect, "height", rect_height_value);
|
|
821
767
|
}
|
|
822
768
|
|
|
@@ -880,7 +826,7 @@ function create_fragment$b(ctx) {
|
|
|
880
826
|
}
|
|
881
827
|
}
|
|
882
828
|
|
|
883
|
-
if (!/*$isOk*/ ctx[
|
|
829
|
+
if (!/*$isOk*/ ctx[3]) {
|
|
884
830
|
if (if_block3) ; else {
|
|
885
831
|
if_block3 = create_if_block$9();
|
|
886
832
|
if_block3.c();
|
|
@@ -891,12 +837,12 @@ function create_fragment$b(ctx) {
|
|
|
891
837
|
if_block3 = null;
|
|
892
838
|
}
|
|
893
839
|
|
|
894
|
-
if (!current || dirty[0] & /*$scale*/
|
|
840
|
+
if (!current || dirty[0] & /*$scale*/ 16 && div1_class_value !== (div1_class_value = "plot " + ('plot_' + /*$scale*/ ctx[4]) + " svelte-n80kcc")) {
|
|
895
841
|
attr(div1, "class", div1_class_value);
|
|
896
842
|
}
|
|
897
843
|
|
|
898
|
-
if (dirty[0] & /*$scale, $isOk*/
|
|
899
|
-
toggle_class(div1, "plot_error", !/*$isOk*/ ctx[
|
|
844
|
+
if (dirty[0] & /*$scale, $isOk*/ 24) {
|
|
845
|
+
toggle_class(div1, "plot_error", !/*$isOk*/ ctx[3]);
|
|
900
846
|
}
|
|
901
847
|
},
|
|
902
848
|
i(local) {
|
|
@@ -923,9 +869,9 @@ function create_fragment$b(ctx) {
|
|
|
923
869
|
if (yaxis_slot) yaxis_slot.d(detaching);
|
|
924
870
|
if (default_slot) default_slot.d(detaching);
|
|
925
871
|
if (box_slot) box_slot.d(detaching);
|
|
926
|
-
|
|
872
|
+
/*div0_binding*/ ctx[28](null);
|
|
927
873
|
if (if_block3) if_block3.d();
|
|
928
|
-
|
|
874
|
+
/*div1_binding*/ ctx[29](null);
|
|
929
875
|
mounted = false;
|
|
930
876
|
dispose();
|
|
931
877
|
}
|
|
@@ -998,40 +944,40 @@ function instance$b($$self, $$props, $$invalidate) {
|
|
|
998
944
|
const clipPathID = "plottingArea" + Math.round(Math.random() * 10000);
|
|
999
945
|
|
|
1000
946
|
/* parameters for internal use inside the component */
|
|
1001
|
-
let
|
|
947
|
+
let plotElement;
|
|
1002
948
|
|
|
1003
|
-
let
|
|
949
|
+
let axesElement;
|
|
1004
950
|
let axesMargins = [0.034, 0.034, 0.034, 0.034]; // initial margins (will be multiplied to FACTORS)
|
|
1005
951
|
|
|
1006
952
|
/* reactive parameters to be shared with children via context */
|
|
1007
953
|
const width = writable(100); // actual width of plotting area in pixels
|
|
1008
954
|
|
|
1009
|
-
component_subscribe($$self, width, value => $$invalidate(
|
|
955
|
+
component_subscribe($$self, width, value => $$invalidate(24, $width = value));
|
|
1010
956
|
const height = writable(100); // actual height of plotting area in pixels
|
|
1011
|
-
component_subscribe($$self, height, value => $$invalidate(
|
|
957
|
+
component_subscribe($$self, height, value => $$invalidate(22, $height = value));
|
|
1012
958
|
const xLim = writable([undefined, undefined]); // actual limits for x-axis in plot units
|
|
1013
959
|
component_subscribe($$self, xLim, value => $$invalidate(25, $xLim = value));
|
|
1014
960
|
const yLim = writable([undefined, undefined]); // actual limits for y-axis in plot units
|
|
1015
|
-
component_subscribe($$self, yLim, value => $$invalidate(
|
|
961
|
+
component_subscribe($$self, yLim, value => $$invalidate(23, $yLim = value));
|
|
1016
962
|
const scale = writable("medium"); // scale factor (how big the shown plot is)
|
|
1017
|
-
component_subscribe($$self, scale, value => $$invalidate(
|
|
963
|
+
component_subscribe($$self, scale, value => $$invalidate(4, $scale = value));
|
|
1018
964
|
const isOk = writable(false); // are axes ready for drawing
|
|
1019
|
-
component_subscribe($$self, isOk, value => $$invalidate(
|
|
965
|
+
component_subscribe($$self, isOk, value => $$invalidate(3, $isOk = value));
|
|
1020
966
|
|
|
1021
967
|
/** Adds margins for x-axis (e.g. when x-axis must be shown) */
|
|
1022
968
|
const addXAxisMargins = function () {
|
|
1023
|
-
$$invalidate(
|
|
1024
|
-
$$invalidate(
|
|
1025
|
-
$$invalidate(
|
|
1026
|
-
$$invalidate(
|
|
969
|
+
$$invalidate(20, axesMargins[0] = 1, axesMargins);
|
|
970
|
+
$$invalidate(20, axesMargins[2] = 0.5, axesMargins);
|
|
971
|
+
$$invalidate(20, axesMargins[1] = axesMargins[1] > 0.5 ? axesMargins[1] : 0.5, axesMargins);
|
|
972
|
+
$$invalidate(20, axesMargins[3] = axesMargins[3] > 0.5 ? axesMargins[3] : 0.5, axesMargins);
|
|
1027
973
|
};
|
|
1028
974
|
|
|
1029
975
|
/** Adds margins for y-axis (e.g. when y-axis must be shown) */
|
|
1030
976
|
const addYAxisMargins = function () {
|
|
1031
|
-
$$invalidate(
|
|
1032
|
-
$$invalidate(
|
|
1033
|
-
$$invalidate(
|
|
1034
|
-
$$invalidate(
|
|
977
|
+
$$invalidate(20, axesMargins[1] = 1, axesMargins);
|
|
978
|
+
$$invalidate(20, axesMargins[3] = 0.5, axesMargins);
|
|
979
|
+
$$invalidate(20, axesMargins[0] = axesMargins[0] > 0.5 ? axesMargins[0] : 0.5, axesMargins);
|
|
980
|
+
$$invalidate(20, axesMargins[2] = axesMargins[2] > 0.5 ? axesMargins[2] : 0.5, axesMargins);
|
|
1035
981
|
};
|
|
1036
982
|
|
|
1037
983
|
/** Adjusts limits for x-axis (e.g. when new series is added)
|
|
@@ -1205,63 +1151,73 @@ function instance$b($$self, $$props, $$invalidate) {
|
|
|
1205
1151
|
dispatch("axesclick");
|
|
1206
1152
|
}
|
|
1207
1153
|
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1154
|
+
/* observer for the plotting area size */
|
|
1155
|
+
var ro = new ResizeObserver(entries => {
|
|
1156
|
+
for (let entry of entries) {
|
|
1157
|
+
const pcr = plotElement.getBoundingClientRect();
|
|
1158
|
+
const acr = axesElement.getBoundingClientRect();
|
|
1159
|
+
width.update(x => acr.width);
|
|
1160
|
+
height.update(x => acr.height);
|
|
1161
|
+
scale.update(x => getScale(pcr.width, pcr.height));
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
onMount(() => {
|
|
1166
|
+
ro.observe(plotElement);
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
function div0_binding($$value) {
|
|
1170
|
+
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
1171
|
+
axesElement = $$value;
|
|
1172
|
+
$$invalidate(6, axesElement);
|
|
1173
|
+
});
|
|
1213
1174
|
}
|
|
1214
1175
|
|
|
1215
|
-
function
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1176
|
+
function div1_binding($$value) {
|
|
1177
|
+
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
1178
|
+
plotElement = $$value;
|
|
1179
|
+
$$invalidate(5, plotElement);
|
|
1180
|
+
});
|
|
1220
1181
|
}
|
|
1221
1182
|
|
|
1222
1183
|
$$self.$$set = $$props => {
|
|
1223
|
-
if ('limX' in $$props) $$invalidate(
|
|
1224
|
-
if ('limY' in $$props) $$invalidate(
|
|
1184
|
+
if ('limX' in $$props) $$invalidate(17, limX = $$props.limX);
|
|
1185
|
+
if ('limY' in $$props) $$invalidate(18, limY = $$props.limY);
|
|
1225
1186
|
if ('title' in $$props) $$invalidate(0, title = $$props.title);
|
|
1226
1187
|
if ('xLabel' in $$props) $$invalidate(1, xLabel = $$props.xLabel);
|
|
1227
1188
|
if ('yLabel' in $$props) $$invalidate(2, yLabel = $$props.yLabel);
|
|
1228
|
-
if ('multiSeries' in $$props) $$invalidate(
|
|
1189
|
+
if ('multiSeries' in $$props) $$invalidate(19, multiSeries = $$props.multiSeries);
|
|
1229
1190
|
if ('$$scope' in $$props) $$invalidate(26, $$scope = $$props.$$scope);
|
|
1230
1191
|
};
|
|
1231
1192
|
|
|
1232
1193
|
$$self.$$.update = () => {
|
|
1233
|
-
if ($$self.$$.dirty[0] & /*
|
|
1234
|
-
// update plot scale based on its size
|
|
1235
|
-
scale.update(x => getScale(plotWidth, plotHeight));
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
if ($$self.$$.dirty[0] & /*limX*/ 524288) {
|
|
1194
|
+
if ($$self.$$.dirty[0] & /*limX*/ 131072) {
|
|
1239
1195
|
// this is reactive in case if limX and limY are interactively changed by parent script
|
|
1240
1196
|
if (!limX.some(v => v === undefined)) xLim.update(v => limX);
|
|
1241
1197
|
}
|
|
1242
1198
|
|
|
1243
|
-
if ($$self.$$.dirty[0] & /*limY*/
|
|
1199
|
+
if ($$self.$$.dirty[0] & /*limY*/ 262144) {
|
|
1244
1200
|
if (!limY.some(v => v === undefined)) yLim.update(v => limY);
|
|
1245
1201
|
}
|
|
1246
1202
|
|
|
1247
|
-
if ($$self.$$.dirty[0] & /*axesMargins, $scale*/
|
|
1203
|
+
if ($$self.$$.dirty[0] & /*axesMargins, $scale*/ 1048592) {
|
|
1248
1204
|
// computes real margins in pixels based on current scale
|
|
1249
|
-
$$invalidate(
|
|
1205
|
+
$$invalidate(21, margins = axesMargins.map(v => v * AXES_MARGIN_FACTORS[$scale]));
|
|
1250
1206
|
}
|
|
1251
1207
|
|
|
1252
|
-
if ($$self.$$.dirty[0] & /*$yLim, $xLim, $width, margins, $height*/
|
|
1208
|
+
if ($$self.$$.dirty[0] & /*$yLim, $xLim, $width, margins, $height*/ 65011712) {
|
|
1253
1209
|
// computes status which tells that axes limits look fine and it is safe to draw
|
|
1254
1210
|
// the status is based on the axis limits validity
|
|
1255
1211
|
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]);
|
|
1256
1212
|
}
|
|
1257
1213
|
|
|
1258
|
-
if ($$self.$$.dirty[0] & /*$isOk, $xLim, $width*/
|
|
1214
|
+
if ($$self.$$.dirty[0] & /*$isOk, $xLim, $width*/ 50331656) {
|
|
1259
1215
|
// computes coordinates for clip path box
|
|
1260
|
-
$$invalidate(
|
|
1216
|
+
$$invalidate(8, cpx = $isOk ? scaleX($xLim, $xLim, $width) : [0, 1]);
|
|
1261
1217
|
}
|
|
1262
1218
|
|
|
1263
|
-
if ($$self.$$.dirty[0] & /*$isOk, $yLim, $height*/
|
|
1264
|
-
$$invalidate(
|
|
1219
|
+
if ($$self.$$.dirty[0] & /*$isOk, $yLim, $height*/ 12582920) {
|
|
1220
|
+
$$invalidate(7, cpy = $isOk ? scaleY($yLim, $yLim, $height) : [1, 0]);
|
|
1265
1221
|
}
|
|
1266
1222
|
};
|
|
1267
1223
|
|
|
@@ -1269,12 +1225,10 @@ function instance$b($$self, $$props, $$invalidate) {
|
|
|
1269
1225
|
title,
|
|
1270
1226
|
xLabel,
|
|
1271
1227
|
yLabel,
|
|
1272
|
-
plotWidth,
|
|
1273
|
-
plotHeight,
|
|
1274
|
-
$height,
|
|
1275
1228
|
$isOk,
|
|
1276
|
-
$width,
|
|
1277
1229
|
$scale,
|
|
1230
|
+
plotElement,
|
|
1231
|
+
axesElement,
|
|
1278
1232
|
cpy,
|
|
1279
1233
|
cpx,
|
|
1280
1234
|
clipPathID,
|
|
@@ -1290,12 +1244,14 @@ function instance$b($$self, $$props, $$invalidate) {
|
|
|
1290
1244
|
multiSeries,
|
|
1291
1245
|
axesMargins,
|
|
1292
1246
|
margins,
|
|
1247
|
+
$height,
|
|
1293
1248
|
$yLim,
|
|
1249
|
+
$width,
|
|
1294
1250
|
$xLim,
|
|
1295
1251
|
$$scope,
|
|
1296
1252
|
slots,
|
|
1297
|
-
|
|
1298
|
-
|
|
1253
|
+
div0_binding,
|
|
1254
|
+
div1_binding
|
|
1299
1255
|
];
|
|
1300
1256
|
}
|
|
1301
1257
|
|
|
@@ -1310,12 +1266,12 @@ class Axes extends SvelteComponent {
|
|
|
1310
1266
|
create_fragment$b,
|
|
1311
1267
|
safe_not_equal,
|
|
1312
1268
|
{
|
|
1313
|
-
limX:
|
|
1314
|
-
limY:
|
|
1269
|
+
limX: 17,
|
|
1270
|
+
limY: 18,
|
|
1315
1271
|
title: 0,
|
|
1316
1272
|
xLabel: 1,
|
|
1317
1273
|
yLabel: 2,
|
|
1318
|
-
multiSeries:
|
|
1274
|
+
multiSeries: 19
|
|
1319
1275
|
},
|
|
1320
1276
|
add_css$3,
|
|
1321
1277
|
[-1, -1]
|
package/package.json
CHANGED
package/src/Axes.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { setContext, createEventDispatcher } from 'svelte';
|
|
2
|
+
import { setContext, createEventDispatcher, onMount } from 'svelte';
|
|
3
3
|
import { writable } from 'svelte/store';
|
|
4
4
|
|
|
5
5
|
/* input parameters */
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
const clipPathID = "plottingArea" + Math.round(Math.random() * 10000);
|
|
47
47
|
|
|
48
48
|
/* parameters for internal use inside the component */
|
|
49
|
-
let
|
|
50
|
-
let
|
|
49
|
+
let plotElement;
|
|
50
|
+
let axesElement;
|
|
51
51
|
let axesMargins = [0.034, 0.034, 0.034, 0.034]; // initial margins (will be multiplied to FACTORS)
|
|
52
52
|
|
|
53
53
|
/* reactive parameters to be shared with children via context */
|
|
@@ -265,10 +265,6 @@
|
|
|
265
265
|
|
|
266
266
|
setContext('axes', context);
|
|
267
267
|
|
|
268
|
-
// update plot scale based on its size
|
|
269
|
-
$: scale.update(x => getScale(plotWidth, plotHeight));
|
|
270
|
-
|
|
271
|
-
|
|
272
268
|
// handle click on plot elements and dispatch manual events
|
|
273
269
|
function dispatchClickEvent(eventName, el) {
|
|
274
270
|
dispatch(eventName, {seriesTitle: el.parentNode.getAttribute('title'), elementID: el.dataset.id});
|
|
@@ -320,10 +316,27 @@
|
|
|
320
316
|
// computes coordinates for clip path box
|
|
321
317
|
$: cpx = $isOk ? scaleX($xLim, $xLim, $width) : [0, 1];
|
|
322
318
|
$: cpy = $isOk ? scaleY($yLim, $yLim, $height) : [1, 0];
|
|
319
|
+
|
|
320
|
+
/* observer for the plotting area size */
|
|
321
|
+
var ro = new ResizeObserver(entries => {
|
|
322
|
+
for (let entry of entries) {
|
|
323
|
+
|
|
324
|
+
const pcr = plotElement.getBoundingClientRect();
|
|
325
|
+
const acr = axesElement.getBoundingClientRect();
|
|
326
|
+
|
|
327
|
+
width.update(x => acr.width);
|
|
328
|
+
height.update(x => acr.height);
|
|
329
|
+
scale.update(x => getScale(pcr.width, pcr.height));
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
onMount(() => {
|
|
334
|
+
ro.observe(plotElement);
|
|
335
|
+
});
|
|
323
336
|
</script>
|
|
324
337
|
|
|
325
338
|
|
|
326
|
-
<div class="plot {'plot_' + $scale}" bind:
|
|
339
|
+
<div class="plot {'plot_' + $scale}" bind:this={plotElement} class:plot_error="{!$isOk}">
|
|
327
340
|
|
|
328
341
|
<!-- plot title and axis labels -->
|
|
329
342
|
{#if title !== ""}<div class="axes__title">{@html title}</div>{/if}
|
|
@@ -331,7 +344,7 @@
|
|
|
331
344
|
{#if xLabel !== ""}<div class="axes__xlabel"><span>{@html xLabel}</span></div>{/if}
|
|
332
345
|
|
|
333
346
|
<!-- axes (coordinate system) -->
|
|
334
|
-
<div class="axes-wrapper" bind:
|
|
347
|
+
<div class="axes-wrapper" bind:this={axesElement} >
|
|
335
348
|
<svg on:click={handleClick} preserveAspectRatio="none" class="axes">
|
|
336
349
|
|
|
337
350
|
<!-- define clipping path -->
|