Skip to content

Commit

Permalink
v4.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
smklimenko committed Oct 14, 2023
1 parent 7c17bc6 commit 912716e
Show file tree
Hide file tree
Showing 20 changed files with 454 additions and 147 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# KdbInsideBrains Changelog

## [4.4.0]

### Added

- Shortcuts added for Copy/Save active chart
- All overlays/instruments are copied/saved into clipboard as well

### Changed

- Chart SVG library changed to the latest one

### Fixed

- IDEA Save dialog is used to save a chart as PNG or SVG
- Charting takes into account local timezone for drawing correct scale
- Measure charting tool shows temporal values for domain

## [4.3.0]

### Added
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.changelog.Changelog
plugins {
id 'java'
id 'org.jetbrains.intellij' version '1.13.3'
id 'org.jetbrains.changelog' version '2.0.0'
id 'org.jetbrains.changelog' version '2.1.2'
id "org.jetbrains.grammarkit" version "2022.3"
}

Expand Down Expand Up @@ -63,15 +63,15 @@ generateParser {
}

dependencies {
implementation 'org.jfree:jfreesvg:3.4.3'
implementation 'org.jfree:jfreechart:1.5.4'
implementation 'org.jfree:org.jfree.svg:5.0.5'

implementation 'org.apache.poi:poi:5.2.3'
implementation 'org.apache.poi:poi-ooxml:5.2.3'

testImplementation 'org.mockito:mockito-core:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.9.3'
testImplementation 'org.mockito:mockito-core:5.5.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.10.0'
}

sourceSets {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ pluginUntilBuild=232.*
pluginJavaVersion=17
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html for available build versions
pluginVerifierVersions=2022.3, 2022.3.3, 2023.1.1, 2023.2.1
pluginVerifierVersions=2022.3, 2022.3.3, 2023.1.1, 2023.2.3
platformType=IC
#platformVersion=2022.3
#platformPlugins=java, PsiViewer:2022.3
#platformVersion=2022.3.3
#platformPlugins=java, PsiViewer:2022.3
#platformVersion=2023.1.3
#platformPlugins=java, PsiViewer:231-SNAPSHOT
platformVersion=2023.2.1
platformVersion=2023.2.3
platformPlugins=java, PsiViewer:232.2
platformDownloadSources=true
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.block.BlockBorder;
Expand All @@ -26,8 +25,6 @@
import java.lang.reflect.Field;
import java.util.function.Supplier;

import static kx.KxConnection.UTC_TIMEZONE;

public class BaseChartPanel extends ChartPanel {
private final ChartOptions myOptions;
private boolean defaultCursor = false;
Expand Down Expand Up @@ -75,10 +72,11 @@ protected static void initializeAxis(ValueAxis axis) {
axis.setAxisLinePaint(JBColor.foreground());
axis.setTickLabelPaint(JBColor.foreground());

if (axis instanceof NumberAxis) {
((NumberAxis) axis).setAutoRangeIncludesZero(false);
} else if (axis instanceof DateAxis) {
((DateAxis) axis).setTimeZone(UTC_TIMEZONE);
if (axis instanceof NumberAxis a) {
a.setAutoRangeIncludesZero(false);
// Leads to wrong values display
// } else if (axis instanceof DateAxis a) {
// a.setTimeZone(UTC_TIMEZONE);
}
}

Expand Down Expand Up @@ -122,11 +120,11 @@ public void setChart(JFreeChart chart) {

if (chart != null) {
setMouseZoomable(true);
initializeChar(chart);
initializeChart(chart);
}
}

private void initializeChar(JFreeChart chart) {
private void initializeChart(JFreeChart chart) {
chart.setBorderPaint(JBColor.foreground());
chart.setBackgroundPaint(JBColor.background());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kdb.inside.brains.view.chart;

import org.jdom.Element;
import org.kdb.inside.brains.KdbType;
import org.kdb.inside.brains.view.chart.types.ChartType;

import java.util.List;
Expand All @@ -20,6 +21,8 @@ public interface ChartConfig {

String toHumanString();

KdbType getDomainType();

List<ColumnConfig> getColumns();

default boolean isApplicable(ChartDataProvider dataProvider) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package org.kdb.inside.brains.view.chart;

import kx.KxConnection;
import kx.c;
import org.jfree.data.time.Month;
import org.jfree.data.time.*;
import org.kdb.inside.brains.KdbType;

import javax.swing.*;
import java.sql.Timestamp;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public interface ChartDataProvider {
LocalDate KDB_FIRST_DATE = LocalDate.of(2000, 1, 1);

static ChartDataProvider copy(JTable table) {
final int rowsCount = table.getRowCount();
final int columnCount = table.getColumnCount();
Expand Down Expand Up @@ -74,42 +83,62 @@ public Object[] getRows(ColumnConfig column) {

int getRowsCount();

static Object createKdbTemporal(long millis, KdbType type) {
if (type == null || type == KdbType.TIMESTAMP) {
return new Timestamp(millis);
}
return switch (type) {
case DATE -> new java.sql.Date(millis);
case TIME -> new java.sql.Time(millis);
case DATETIME -> new java.util.Date(millis);
case MONTH ->
new c.Month((int) ChronoUnit.MONTHS.between(KDB_FIRST_DATE, Instant.ofEpochMilli(millis).atZone(ZoneOffset.UTC)));

case SECOND -> new c.Second((int) (millis / 1_000L));
case MINUTE -> new c.Minute((int) (millis / 60_000L));
case TIMESPAN -> new c.Timespan(millis * 1_000_000L);
default -> new Timestamp(millis);
};
}

static Date createDate(Object value) {
// SQL Date, Time, Timestamp are here
if (value instanceof Date) {
return (Date) value;
} else if (value instanceof c.Second) {
final c.Second v = (c.Second) value;
return new Date(v.i * 1000L);
} else if (value instanceof c.Minute) {
final c.Minute v = (c.Minute) value;
return new Date(v.i * 60 * 1000L);
} else if (value instanceof c.Month) {
final c.Month v = (c.Month) value;
return new Date(v.i * 12 * 24 * 60 * 1000L);
} else if (value instanceof c.Timespan) {
final c.Timespan v = (c.Timespan) value;
return new Date(v.j / 1_000_000L);
Date res;
if (value instanceof Date date) {
res = date;
} else if (value instanceof c.Month month) {
final long epochMilli = KDB_FIRST_DATE.plusMonths(month.i).atTime(LocalTime.MIDNIGHT).atZone(ZoneOffset.UTC).toInstant().toEpochMilli();
res = new Date(epochMilli);
} else if (value instanceof c.Second v) {
res = new Date(v.i * 1_000L);
} else if (value instanceof c.Minute v) {
res = new Date(v.i * 60_000L);
} else if (value instanceof c.Timespan v) {
res = new Date(v.j / 1_000_000L);
} else {
throw new IllegalArgumentException("Invalid value type: " + value.getClass());
}
throw new IllegalArgumentException("Invalid value type: " + value.getClass());
final ZonedDateTime f = Instant.ofEpochMilli(res.getTime()).atZone(ZoneId.systemDefault()).withZoneSameLocal(ZoneId.systemDefault());
final ZonedDateTime t = f.withZoneSameInstant(ZoneOffset.UTC).withZoneSameLocal(ZoneId.systemDefault());
return Date.from(t.toInstant());
}

static RegularTimePeriod createPeriod(Object value) {
// SQL Date, Time, Timestamp are here
if (value instanceof Date) {
return new Millisecond((Date) value);
} else if (value instanceof c.Second) {
final c.Second v = (c.Second) value;
return new Second(new Date(v.i * 1000L));
} else if (value instanceof c.Minute) {
final c.Minute v = (c.Minute) value;
return new Minute(new Date(v.i * 60 * 1000L));
} else if (value instanceof c.Month) {
final c.Month v = (c.Month) value;
return new Month(new Date(v.i * 12 * 24 * 60 * 1000L));
} else if (value instanceof c.Timespan) {
final c.Timespan v = (c.Timespan) value;
return new Millisecond(new Date(v.j / 1_000_000L));
if (value instanceof java.sql.Date date) {
return new Day(date, KxConnection.UTC_TIMEZONE, Locale.getDefault());
} else if (value instanceof java.sql.Time time) {
return new Millisecond(time, KxConnection.UTC_TIMEZONE, Locale.getDefault());
} else if (value instanceof java.util.Date datetime) {
return new Millisecond(datetime, KxConnection.UTC_TIMEZONE, Locale.getDefault());
} else if (value instanceof c.Month v) {
final long epochMilli = KDB_FIRST_DATE.plusMonths(v.i).atTime(LocalTime.MIDNIGHT).toInstant(ZoneOffset.UTC).toEpochMilli();
return new Month(new Date(epochMilli), KxConnection.UTC_TIMEZONE, Locale.getDefault());
} else if (value instanceof c.Second v) {
return new Second(new Date(v.i * 1_000L), KxConnection.UTC_TIMEZONE, Locale.getDefault());
} else if (value instanceof c.Minute v) {
return new Minute(new Date(v.i * 60_000L), KxConnection.UTC_TIMEZONE, Locale.getDefault());
} else if (value instanceof c.Timespan v) {
return new Millisecond(new Date(v.j / 1_000_000L), KxConnection.UTC_TIMEZONE, Locale.getDefault());
}
throw new IllegalArgumentException("Invalid value type: " + value.getClass());
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/kdb/inside/brains/view/chart/ChartTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import com.intellij.openapi.actionSystem.ActionGroup;
import org.jfree.chart.JFreeChart;
import org.kdb.inside.brains.KdbType;

public interface ChartTool {
void setChart(JFreeChart chart);

boolean isEnabled();

void setEnabled(boolean state);


void initialize(JFreeChart chart, KdbType domainType);


default ActionGroup getPopupActions() {
return ActionGroup.EMPTY_GROUP;
}
Expand Down
Loading

0 comments on commit 912716e

Please sign in to comment.