Search in sources :

Example 1 with Cursor

use of io.jmix.charts.model.cursor.Cursor in project jmix by jmix-framework.

the class ChartsSerializationTest method testSerialChart.

@Test
public void testSerialChart() throws IOException, URISyntaxException, ParseException {
    DataProvider dataProvider = new ListDataProvider();
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "1", "date", "2012-07-27", "value", 13)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "2", "date", "2012-07-28", "value", 11)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "3", "date", "2012-07-29", "value", 15)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "4", "date", "2012-07-30", "value", 16)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "5", "date", "2012-07-31", "value", 18)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "6", "date", "2012-08-01", "value", 13)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "7", "date", "2012-08-02", "value", 22)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "8", "date", "2012-08-03", "value", 23)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "9", "date", "2012-08-04", "value", 20)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "10", "date", "2012-08-05", "value", 17)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "11", "date", "2012-08-06", "value", 16)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "12", "date", "2012-08-07", "value", 18)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "13", "date", "2012-08-08", "value", 21)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "14", "date", "2012-08-09", "value", 26)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "15", "date", "2012-08-10", "value", 24)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "16", "date", "2012-08-11", "value", 29)));
    AbstractChart chart = new SerialChartModelImpl().setCategoryField("date").setDataProvider(dataProvider).addValueAxes(new ValueAxis().setAxisAlpha(0.0).setPosition(Position.LEFT)).addGraphs(new Graph().setId("g1").setBullet(BulletType.ROUND).setBulletBorderAlpha(1.0).setBulletColor(Color.WHITE).setBulletSize(5).setHideBulletsCount(50).setLineThickness(2).setTitle("Red line").setValueField("value")).setCategoryAxis(new CategoryAxis().setDashLength(1).setMinorGridEnabled(true).setPosition(Position.TOP)).setChartScrollbar(new Scrollbar().setGraph("g1").setScrollbarHeight(30)).setChartCursor(new Cursor().setCursorPosition(CursorPosition.MOUSE).setPan(true)).setExport(new Export());
    ChartSerializer serializer = getTestSerializer();
    String json = serializer.serialize(chart);
    String expected = readFile("SerialChart.json");
    assertEquals(prettyJson(expected), prettyJson(json));
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) ChartSerializer(io.jmix.charts.widget.amcharts.serialization.ChartSerializer) Cursor(io.jmix.charts.model.cursor.Cursor) ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) DataProvider(io.jmix.ui.data.DataProvider) Graph(io.jmix.charts.model.graph.Graph) CategoryAxis(io.jmix.charts.model.axis.CategoryAxis) ValueAxis(io.jmix.charts.model.axis.ValueAxis) Export(io.jmix.charts.model.export.Export) MapDataItem(io.jmix.ui.data.impl.MapDataItem) Scrollbar(io.jmix.charts.model.Scrollbar) Test(org.junit.jupiter.api.Test)

Example 2 with Cursor

use of io.jmix.charts.model.cursor.Cursor in project jmix by jmix-framework.

the class ChartsSerializationTest method testGanttChart.

@Test
public void testGanttChart() throws ParseException, IOException, URISyntaxException {
    ListDataProvider dataProvider = new ListDataProvider();
    dataProvider.addItem(taskSpan("1", "John", segment("s1", 7, 2, "#7B742C", "Task #1"), segment("s2", null, 2, "#7E585F", "Task #2"), segment("s3", null, 2, "#CF794A", "Task #3")));
    dataProvider.addItem(taskSpan("2", "Smith", segment("s4", 10, 2, "#7E585F", "Task #2"), segment("s5", null, 1, "#CF794A", "Task #3"), segment("s6", null, 4, "#7B742C", "Task #1")));
    dataProvider.addItem(taskSpan("3", "Ben", segment("s7", 12, 2, "#7E585F", "Task #2"), segment("s8", 16, 2, "#FFE4C4", "Task #4")));
    dataProvider.addItem(taskSpan("4", "Mike", segment("s9", 9, 6, "#7B742C", "Task #1"), segment("s10", null, 4, "#7E585F", "Task #2")));
    dataProvider.addItem(taskSpan("5", "Lenny", segment("s11", 8, 1, "#CF794A", "Task #3"), segment("s12", null, 4, "#7B742C", "Task #1")));
    dataProvider.addItem(taskSpan("6", "Scott", segment("s13", 15, 3, "#7E585F", "Task #2")));
    dataProvider.addItem(taskSpan("7", "Julia", segment("s14", 9, 2, "#7B742C", "Task #1"), segment("s15", null, 1, "#7E585F", "Task #2"), segment("s16", null, 8, "#CF794A", "Task #3")));
    dataProvider.addItem(taskSpan("8", "Bob", segment("s17", 9, 8, "#7E585F", "Task #2"), segment("s18", null, 7, "#CF794A", "Task #3")));
    dataProvider.addItem(taskSpan("9", "Kendra", segment("s19", 11, 8, "#7E585F", "Task #2"), segment("s20", 16, 2, "#FFE4C4", "Task #4")));
    dataProvider.addItem(taskSpan("9", "Tom", segment("s21", 9, 4, "#7B742C", "Task #1"), segment("s22", null, 3, "#7E585F", "Task #2"), segment("s23", null, 5, "#CF794A", "Task #3")));
    dataProvider.addItem(taskSpan("10", "Kyle", segment("s24", 6, 3, "#7E585F", "Task #2")));
    dataProvider.addItem(taskSpan("11", "Anita", segment("s25", 12, 2, "#7E585F", "Task #2"), segment("s26", 16, 2, "#FFE4C4", "Task #4")));
    dataProvider.addItem(taskSpan("12", "Jack", segment("s27", 8, 10, "#7B742C", "Task #1"), segment("s28", null, 2, "#7E585F", "Task #2")));
    dataProvider.addItem(taskSpan("13", "Kim", segment("s29", 12, 2, "#7E585F", "Task #2"), segment("s30", null, 3, "#CF794A", "Task #3")));
    dataProvider.addItem(taskSpan("14", "Aaron", segment("s31", 18, 2, "#7E585F", "Task #2"), segment("s32", null, 2, "#FFE4C4", "Task #4")));
    dataProvider.addItem(taskSpan("15", "Alan", segment("s33", 17, 2, "#7B742C", "Task #1"), segment("s34", null, 2, "#7E585F", "Task #2"), segment("s35", null, 2, "#CF794A", "Task #3")));
    dataProvider.addItem(taskSpan("16", "Ruth", segment("s36", 13, 2, "#7E585F", "Task #2"), segment("s37", null, 1, "#CF794A", "Task #3"), segment("s38", null, 4, "#7B742C", "Task #1")));
    dataProvider.addItem(taskSpan("17", "Simon", segment("s39", 10, 3, "#7E585F", "Task #2"), segment("s40", 17, 4, "#FFE4C4", "Task #4")));
    AbstractChart chart = new GanttChartModelImpl().setDataProvider(dataProvider).setTheme(ChartTheme.LIGHT).setMarginRight(70).setPeriod(DatePeriod.HOURS).setBalloonDateFormat("JJ:NN").setColumnWidth(0.5).setBrightnessStep(10).setRotate(true).setCategoryField("category").setSegmentsField("segments").setStartDate(df.parse("2015-01-01")).setColorField("color").setStartField("start").setEndField("end").setDurationField("duration").addAdditionalSegmentFields("task").setGraph(new Graph().setFillAlphas(1.0).setBalloonText("[[task]]: [[open]] [[value]]")).setValueAxis(new ValueAxis().setType(ValueAxisType.DATE).setMinimum(7.0).setMaximum(31.0)).setChartScrollbar(new Scrollbar()).setChartCursor(new Cursor().setValueBalloonsEnabled(false).setCursorAlpha(0.1).setValueLineBalloonEnabled(true).setValueLineEnabled(true).setFullWidth(true)).setExport(new Export());
    ChartSerializer serializer = getTestSerializer();
    String json = serializer.serialize(chart);
    String expected = readFile("GanttChart.json");
    assertEquals(prettyJson(expected), prettyJson(json));
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) Graph(io.jmix.charts.model.graph.Graph) ChartSerializer(io.jmix.charts.widget.amcharts.serialization.ChartSerializer) ValueAxis(io.jmix.charts.model.axis.ValueAxis) Export(io.jmix.charts.model.export.Export) Cursor(io.jmix.charts.model.cursor.Cursor) Scrollbar(io.jmix.charts.model.Scrollbar) Test(org.junit.jupiter.api.Test)

Example 3 with Cursor

use of io.jmix.charts.model.cursor.Cursor in project jmix by jmix-framework.

the class CustomChartImpl method setupRectangularChartDefaults.

protected void setupRectangularChartDefaults(RectangularChartModelImpl chart) {
    if (chart.getZoomOutText() == null) {
        chart.setZoomOutText(messages.getMessage("amcharts.zoomOutText"));
    }
    Cursor cursor = chart.getChartCursor();
    if (cursor != null) {
        if (StringUtils.isEmpty(cursor.getCategoryBalloonDateFormat())) {
            String format = messages.getMessage("amcharts.rectangularChart.categoryBalloonDateFormat");
            cursor.setCategoryBalloonDateFormat(format);
        }
    }
}
Also used : Cursor(io.jmix.charts.model.cursor.Cursor)

Example 4 with Cursor

use of io.jmix.charts.model.cursor.Cursor in project jmix by jmix-framework.

the class ChartModelLoader method loadCursor.

protected void loadCursor(RectangularChartModel chart, Element element) {
    Element cursorElement = element.element("chartCursor");
    if (cursorElement != null) {
        Cursor cursor = new Cursor();
        String adjustment = cursorElement.attributeValue("adjustment");
        if (StringUtils.isNotEmpty(adjustment)) {
            cursor.setAdjustment(Integer.valueOf(adjustment));
        }
        String categoryBalloonFunction = cursorElement.elementText("categoryBalloonFunction");
        if (StringUtils.isNotEmpty(categoryBalloonFunction)) {
            cursor.setCategoryBalloonFunction(new JsFunction(categoryBalloonFunction));
        }
        String animationDuration = cursorElement.attributeValue("animationDuration");
        if (StringUtils.isNotEmpty(animationDuration)) {
            cursor.setAnimationDuration(Double.valueOf(animationDuration));
        }
        String avoidBalloonOverlapping = cursorElement.attributeValue("avoidBalloonOverlapping");
        if (StringUtils.isNotEmpty(avoidBalloonOverlapping)) {
            cursor.setAvoidBalloonOverlapping(Boolean.valueOf(avoidBalloonOverlapping));
        }
        String balloonPointerOrientation = cursorElement.attributeValue("balloonPointerOrientation");
        if (StringUtils.isNotEmpty(balloonPointerOrientation)) {
            cursor.setBalloonPointerOrientation(balloonPointerOrientation);
        }
        String bulletsEnabled = cursorElement.attributeValue("bulletsEnabled");
        if (StringUtils.isNotEmpty(bulletsEnabled)) {
            cursor.setBulletsEnabled(Boolean.valueOf(bulletsEnabled));
        }
        String bulletSize = cursorElement.attributeValue("bulletSize");
        if (StringUtils.isNotEmpty(bulletSize)) {
            cursor.setBulletSize(Integer.valueOf(bulletSize));
        }
        String categoryBalloonAlpha = cursorElement.attributeValue("categoryBalloonAlpha");
        if (StringUtils.isNotEmpty(categoryBalloonAlpha)) {
            cursor.setCategoryBalloonAlpha(Double.valueOf(categoryBalloonAlpha));
        }
        String categoryBalloonColor = cursorElement.attributeValue("categoryBalloonColor");
        if (StringUtils.isNotEmpty(categoryBalloonColor)) {
            cursor.setCategoryBalloonColor(Color.valueOf(categoryBalloonColor));
        }
        String categoryBalloonDateFormat = cursorElement.attributeValue("categoryBalloonDateFormat");
        if (StringUtils.isNotEmpty(categoryBalloonDateFormat)) {
            cursor.setCategoryBalloonDateFormat(loadResourceString(categoryBalloonDateFormat));
        }
        String categoryBalloonEnabled = cursorElement.attributeValue("categoryBalloonEnabled");
        if (StringUtils.isNotEmpty(categoryBalloonEnabled)) {
            cursor.setCategoryBalloonEnabled(Boolean.valueOf(categoryBalloonEnabled));
        }
        String categoryBalloonText = cursorElement.attributeValue("categoryBalloonText");
        if (StringUtils.isNotEmpty(categoryBalloonText)) {
            cursor.setCategoryBalloonText(categoryBalloonText);
        }
        String color = cursorElement.attributeValue("color");
        if (StringUtils.isNotEmpty(color)) {
            cursor.setColor(Color.valueOf(color));
        }
        String cursorAlpha = cursorElement.attributeValue("cursorAlpha");
        if (StringUtils.isNotEmpty(cursorAlpha)) {
            cursor.setCursorAlpha(Double.valueOf(cursorAlpha));
        }
        String cursorColor = cursorElement.attributeValue("cursorColor");
        if (StringUtils.isNotEmpty(cursorColor)) {
            cursor.setCursorColor(Color.valueOf(cursorColor));
        }
        String cursorPosition = cursorElement.attributeValue("cursorPosition");
        if (StringUtils.isNotEmpty(cursorPosition)) {
            cursor.setCursorPosition(CursorPosition.valueOf(cursorPosition));
        }
        String enabled = cursorElement.attributeValue("enabled");
        if (StringUtils.isNotEmpty(enabled)) {
            cursor.setEnabled(Boolean.valueOf(enabled));
        }
        String fullWidth = cursorElement.attributeValue("fullWidth");
        if (StringUtils.isNotEmpty(fullWidth)) {
            cursor.setFullWidth(Boolean.valueOf(fullWidth));
        }
        String graphBulletAlpha = cursorElement.attributeValue("graphBulletAlpha");
        if (StringUtils.isNotEmpty(graphBulletAlpha)) {
            cursor.setGraphBulletAlpha(Double.valueOf(graphBulletAlpha));
        }
        String graphBulletSize = cursorElement.attributeValue("graphBulletSize");
        if (StringUtils.isNotEmpty(graphBulletSize)) {
            cursor.setGraphBulletSize(Double.valueOf(graphBulletSize));
        }
        String oneBalloonOnly = cursorElement.attributeValue("oneBalloonOnly");
        if (StringUtils.isNotEmpty(oneBalloonOnly)) {
            cursor.setOneBalloonOnly(Boolean.valueOf(oneBalloonOnly));
        }
        String leaveAfterTouch = cursorElement.attributeValue("leaveAfterTouch");
        if (StringUtils.isNotEmpty(leaveAfterTouch)) {
            cursor.setLeaveAfterTouch(Boolean.valueOf(leaveAfterTouch));
        }
        String leaveCursor = cursorElement.attributeValue("leaveCursor");
        if (StringUtils.isNotEmpty(leaveCursor)) {
            cursor.setLeaveCursor(Boolean.valueOf(leaveCursor));
        }
        String limitToGraph = cursorElement.attributeValue("limitToGraph");
        if (StringUtils.isNotEmpty(limitToGraph)) {
            cursor.setLimitToGraph(limitToGraph);
        }
        String pan = cursorElement.attributeValue("pan");
        if (StringUtils.isNotEmpty(pan)) {
            cursor.setPan(Boolean.valueOf(pan));
        }
        String selectionAlpha = cursorElement.attributeValue("selectionAlpha");
        if (StringUtils.isNotEmpty(selectionAlpha)) {
            cursor.setCursorAlpha(Double.valueOf(selectionAlpha));
        }
        String selectWithoutZooming = cursorElement.attributeValue("selectWithoutZooming");
        if (StringUtils.isNotEmpty(selectWithoutZooming)) {
            cursor.setSelectWithoutZooming(Boolean.valueOf(selectWithoutZooming));
        }
        String showNextAvailable = cursorElement.attributeValue("showNextAvailable");
        if (StringUtils.isNotEmpty(showNextAvailable)) {
            cursor.setShowNextAvailable(Boolean.valueOf(showNextAvailable));
        }
        String valueBalloonsEnabled = cursorElement.attributeValue("valueBalloonsEnabled");
        if (StringUtils.isNotEmpty(valueBalloonsEnabled)) {
            cursor.setValueBalloonsEnabled(Boolean.valueOf(valueBalloonsEnabled));
        }
        String valueLineAlpha = cursorElement.attributeValue("valueLineAlpha");
        if (StringUtils.isNotEmpty(valueLineAlpha)) {
            cursor.setValueLineAlpha(Double.valueOf(valueLineAlpha));
        }
        String valueLineAxis = cursorElement.attributeValue("valueLineAxis");
        if (StringUtils.isNotEmpty(valueLineAxis)) {
            cursor.setValueLineAxis(valueLineAxis);
        }
        String valueLineBalloonEnabled = cursorElement.attributeValue("valueLineBalloonEnabled");
        if (StringUtils.isNotEmpty(valueLineBalloonEnabled)) {
            cursor.setValueLineBalloonEnabled(Boolean.valueOf(valueLineBalloonEnabled));
        }
        String valueLineEnabled = cursorElement.attributeValue("valueLineEnabled");
        if (StringUtils.isNotEmpty(valueLineEnabled)) {
            cursor.setValueLineEnabled(Boolean.valueOf(valueLineEnabled));
        }
        String valueZoomable = cursorElement.attributeValue("valueZoomable");
        if (StringUtils.isNotEmpty(valueZoomable)) {
            cursor.setValueZoomable(Boolean.valueOf(valueZoomable));
        }
        String zoomable = cursorElement.attributeValue("zoomable");
        if (StringUtils.isNotEmpty(zoomable)) {
            cursor.setZoomable(Boolean.valueOf(zoomable));
        }
        String tabIndex = cursorElement.attributeValue("tabIndex");
        if (StringUtils.isNotEmpty(tabIndex)) {
            cursor.setTabIndex(Integer.parseInt(tabIndex));
        }
        chart.setChartCursor(cursor);
    }
}
Also used : JsFunction(io.jmix.charts.model.JsFunction) Element(org.dom4j.Element) Cursor(io.jmix.charts.model.cursor.Cursor)

Example 5 with Cursor

use of io.jmix.charts.model.cursor.Cursor in project jmix by jmix-framework.

the class ChartsSerializationTest method testXYChart.

@Test
public void testXYChart() throws IOException, URISyntaxException {
    ListDataProvider dataProvider = new ListDataProvider();
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "1", "ax", 1.0, "ay", 0.5, "bx", 1.0, "by", 2.2)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "2", "ax", 2.0, "ay", 1.3, "bx", 2.0, "by", 4.9)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "3", "ax", 3.0, "ay", 2.3, "bx", 3.0, "by", 5.1)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "4", "ax", 4.0, "ay", 2.8, "bx", 4.0, "by", 5.3)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "5", "ax", 5.0, "ay", 3.5, "bx", 5.0, "by", 6.1)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "6", "ax", 6.0, "ay", 5.1, "bx", 6.0, "by", 8.3)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "7", "ax", 7.0, "ay", 6.7, "bx", 7.0, "by", 10.5)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "8", "ax", 8.0, "ay", 8.0, "bx", 8.0, "by", 12.3)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "9", "ax", 9.0, "ay", 8.9, "bx", 9.0, "by", 14.5)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "10", "ax", 10.0, "ay", 9.7, "bx", 10.0, "by", 15.0)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "11", "ax", 11.0, "ay", 10.4, "bx", 11.0, "by", 18.8)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "12", "ax", 12.0, "ay", 11.7, "bx", 12.0, "by", 19.0)));
    AbstractChart chart = new XYChartModelImpl().setDataProvider(dataProvider).setStartDuration(1.0).setMarginLeft(64).setMarginBottom(60).setChartCursor(new Cursor()).setChartScrollbar(new Scrollbar()).addGraphs(new Graph().setBullet(BulletType.TRIANGLE_UP).setLineAlpha(0.0).setXField("ax").setYField("ay").setLineColor(Color.valueOf("#FF6600")).setFillAlphas(0.0), new Graph().setBullet(BulletType.TRIANGLE_DOWN).setLineAlpha(0.0).setXField("bx").setYField("by").setLineColor(Color.valueOf("#FCD202")).setFillAlphas(0.0)).addTrendLines(new TrendLine().setFinalValue(12.0).setFinalXValue(12.0).setInitialValue(2.0).setInitialXValue(1.0).setLineColor(Color.valueOf("#FF6600")), new TrendLine().setFinalValue(19.0).setFinalXValue(12.0).setInitialValue(1.0).setInitialXValue(1.0).setLineColor(Color.valueOf("#FCD202"))).addValueAxes(new ValueAxis().setAxisAlpha(0.0).setDashLength(1).setTitle("X Axis").setPosition(Position.BOTTOM), new ValueAxis().setAxisAlpha(0.0).setDashLength(1).setTitle("Y Axis").setPosition(Position.LEFT));
    ChartSerializer serializer = getTestSerializer();
    String json = serializer.serialize(chart);
    String expected = readFile("XYChart.json");
    assertEquals(prettyJson(expected), prettyJson(json));
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) Graph(io.jmix.charts.model.graph.Graph) ChartSerializer(io.jmix.charts.widget.amcharts.serialization.ChartSerializer) ValueAxis(io.jmix.charts.model.axis.ValueAxis) TrendLine(io.jmix.charts.model.trendline.TrendLine) Cursor(io.jmix.charts.model.cursor.Cursor) MapDataItem(io.jmix.ui.data.impl.MapDataItem) Scrollbar(io.jmix.charts.model.Scrollbar) Test(org.junit.jupiter.api.Test)

Aggregations

Cursor (io.jmix.charts.model.cursor.Cursor)5 Scrollbar (io.jmix.charts.model.Scrollbar)3 ValueAxis (io.jmix.charts.model.axis.ValueAxis)3 Graph (io.jmix.charts.model.graph.Graph)3 ChartSerializer (io.jmix.charts.widget.amcharts.serialization.ChartSerializer)3 ListDataProvider (io.jmix.ui.data.impl.ListDataProvider)3 Test (org.junit.jupiter.api.Test)3 Export (io.jmix.charts.model.export.Export)2 MapDataItem (io.jmix.ui.data.impl.MapDataItem)2 JsFunction (io.jmix.charts.model.JsFunction)1 CategoryAxis (io.jmix.charts.model.axis.CategoryAxis)1 TrendLine (io.jmix.charts.model.trendline.TrendLine)1 DataProvider (io.jmix.ui.data.DataProvider)1 Element (org.dom4j.Element)1